bethskurrie
2018-03-24 03:39
has joined #pact-js

mboudreau
2018-03-26 10:38
has joined #pact-js

bethskurrie
2018-04-05 04:06
/github subscribe pact-foundation/pact-js

bethskurrie
2018-05-02 04:56
/github unsubscribe pact-foundation/pact-js commits

bethskurrie
2018-05-02 04:57
/github unsubscribe pact-foundation/pact-js commits

bethskurrie
2018-05-02 04:57
/github unsubscribe pact-foundation/pact-js deployments public

sgleadow
2018-05-09 07:06
has joined #pact-js

vinod.baradwaj
2018-05-09 07:08
has joined #pact-js

abubics
2018-05-09 07:11
has joined #pact-js

rgshah781988
2018-05-09 07:16
has joined #pact-js


matt.fellows
2018-05-09 07:20
has joined #pact-js

mboudreau
2018-05-09 07:22
@rgshah781988 that error message has nothing to do with pact

mboudreau
2018-05-09 07:22
that's an assertion error

matt.fellows
2018-05-09 07:22
exactly

mboudreau
2018-05-09 07:23
must be coming from your tests

matt.fellows
2018-05-09 07:23
you?re not properly handling the promise, it seems

matt.fellows
2018-05-09 07:23
if you can share your test code, we can probably help


mboudreau
2018-05-09 07:24
but remember that we're not here to fix your tests for you, there's plenty of documentation out there, so please try your best before bringing it to us as we're busy as well :slightly_smiling_face:

rgshah781988
2018-05-09 07:24
Yes sure

rgshah781988
2018-05-09 07:25
I got stuck since 5 days


mboudreau
2018-05-09 07:26
did you follow an example on how to use pact?

rgshah781988
2018-05-09 07:26
Yes

rgshah781988
2018-05-09 07:26
When I use matchers

mboudreau
2018-05-09 07:26
`const { Pact, Matchers } = require('../../../dist/pact')` ...this doesn't seem right..

rgshah781988
2018-05-09 07:26
THen i am facing issue

mboudreau
2018-05-09 07:27
can you post the link of the example you're following?

rgshah781988
2018-05-09 07:27
Actually, Example is working.

rgshah781988
2018-05-09 07:28
pact-foundation e2e folder

rgshah781988
2018-05-09 07:28
I am trying my application with it.

rgshah781988
2018-05-09 07:28
I am getting pact file creating successfully without using matchers

mboudreau
2018-05-09 07:29
...I asked for the link to the example

rgshah781988
2018-05-09 07:29
When I use matchers then I am getting error.


mboudreau
2018-05-09 07:32
right. An where in this example are we doing `expect(response.data).to.eql(EXPECTED_BODY)`?


mboudreau
2018-05-09 07:34
so, you took 2 different examples and mashed it together

rgshah781988
2018-05-09 07:34
I have updated code as per this details

mboudreau
2018-05-09 07:35
the line before `expect(response.data).to.eql(EXPECTED_BODY)`, add this: `console.log(JSON.stringify(response.data, null, 2));console.log(JSON.stringify(EXPECTED_BODY, null, 2));`

mboudreau
2018-05-09 07:35
run the example again

rgshah781988
2018-05-09 07:35
This example , I need to use matchers

mboudreau
2018-05-09 07:35
and see if they're equal

rgshah781988
2018-05-09 07:38
Expect condition is failing. I am getting console response

mboudreau
2018-05-09 07:38
anywho, I need to get home. I suggest that you try to understand how pact works before you start combining tests together. There's plenty of resources out there

mboudreau
2018-05-09 07:38
the expect is failing because the objects are not the same

mboudreau
2018-05-09 07:38
one is the pact definition, the other is the action object coming from the mock

mboudreau
2018-05-09 07:38
they're 2 different things

mboudreau
2018-05-09 07:38
one explains the format, the other returns the end results

rgshah781988
2018-05-09 07:39
Thanks you so much @mboudreau

mboudreau
2018-05-09 07:39
point is, you're not suppose to do an expect on the whole object

mboudreau
2018-05-09 07:40
do an expect on individual properties

mboudreau
2018-05-09 07:40
or keys if needed

mboudreau
2018-05-09 07:41
but really, by adding those tests, you're not testing your code, you're testing the mock service. We have plenty of tests for those, and I assure you they work. You should be testing your own code

matt.fellows
2018-05-09 07:41
I think we should update the examples. The original `dog api` examples are so contrived they are useless - i.e. they encourage testing the whole object. I?ll put an issue in pact-js for us to fix them

matt.fellows
2018-05-09 07:50
:point_up:

rgshah781988
2018-05-09 08:23
ok

rgshah781988
2018-05-09 13:37
How can I get dynamic response from pact files ? I tried using matchers such as like,eachlike

rgshah781988
2018-05-09 13:38
I am working on API which has POST call with different payload values.

rgshah781988
2018-05-09 13:38
According response changes.

slack1
2018-05-09 20:00
has joined #pact-js

brentbarker9
2018-05-09 20:56
has joined #pact-js

mboudreau
2018-05-09 22:25
you don't. The point of pact is to generate a new response for each different request, hence you're now mapping all of the "interactions" as part of the "contract"

mboudreau
2018-05-09 22:26
you can reuse responses if you'd like for a different interaction though

abubics
2018-05-10 01:37
I think ?dynamic response? isn?t quite what you mean :slightly_smiling_face: You have - variable request (on parameters), and - deterministic response fields (constant, or from parameters), or - flexible response fields (?dynamic? such as a fresh ID).

abubics
2018-05-10 01:37
for all response fields, you may want to use a flexible matcher

bethskurrie
2018-05-10 04:01
That's fine @rgshah781988. Just make a different interaction (request/response) for each different POST example. If the post is to the same URL, you'll need to make sure that only one interaction is mocked at a time, so the mock knows which response to return. That is, you'll have to do a set up/tear down for each interaction (which is actually the recommended way to use pact anyway).

rgshah781988
2018-05-10 05:47
Yes, This what I expect

rgshah781988
2018-05-10 05:47
So, how to do flexible matcher

abubics
2018-05-10 06:09
Have a look in the docs: https://github.com/pact-foundation/pact-js#matching There?s an example under the heading *Match based on type* :slightly_smiling_face:

rgshah781988
2018-05-10 06:09
ok tysm

matt.fellows
2018-05-10 07:33
Just released a neat little video showing some of the features of Pact JS and integration with the broker: https://github.com/pact-foundation/pact-js/#examples

matt.fellows
2018-05-10 07:33
Useful?

rgshah781988
2018-05-10 09:15
Pact JS and integration with the broker . All inforamtion is clear with pact-broker

matt.fellows
2018-05-10 11:05
:+1:

abubics
2018-05-11 05:28
Having the console recording is nice, but with no scrub bar, it all disappears before I can read it :slightly_smiling_face:

abubics
2018-05-11 05:28
Maybe https://asciinema.org/ would be easier to use?

matt.fellows
2018-05-11 06:17
that?s what I used to create it. The annoying thing about asciinema is that it doesn?t play - I should probably like to it though, good point

abubics
2018-05-11 07:11
you mean there?s no embeddable player? http://asciicinema.org is covered in them :s I thought it was part of the package

matt.fellows
2018-05-11 07:12
As in, you can?t embed the player into a GitHub README (or maybe you can now). You can only put the image and a link

matt.fellows
2018-05-11 07:12
That?s why the SVG plugin exists - because it plays, so you can see it

matt.fellows
2018-05-11 07:13
so the best of both words is the SVG in the readme (because it looks sexy and can play) and a link to the player, where you can control the speed?

abubics
2018-05-11 07:21
right, because you need to source the player script

abubics
2018-05-11 07:22
I guess you could iframe it . . . nothing but hacks to workaround that :stuck_out_tongue:

abubics
2018-05-11 07:22
but if the svg linked to a player, I think that?d be good enough

rgshah781988
2018-05-18 10:18
No update or message in pacts js since last 7 days :sunglasses: Is anyone working with pactjs or not ?

matt.fellows
2018-05-18 11:20
@rgshah781988 hehehe

matt.fellows
2018-05-18 11:20
People still migrating (and using) the gazillion other channels they were communicating to us on.

matt.fellows
2018-05-18 11:21
But I like to think, it?s so amazing and easy to use, that noone needs to ask questions about pact-js :slightly_smiling_face:

rgshah781988
2018-05-18 11:24
@matt.fellows gazillion ? can you share link of it ? I can find some solution or help.

matt.fellows
2018-05-18 12:47
what do you mean, sorry?

matt.fellows
2018-05-18 12:48
I was just remarking that the move from gitter/google groups/etc. to Slack is new, so it?s still new place to grow this community, hence not many conversations yet

thomas.heilbronner
2018-05-21 09:24
has joined #pact-js

avinash.eediga
2018-05-23 05:56
has joined #pact-js

avinash.eediga
2018-05-30 00:41
hi guys

avinash.eediga
2018-05-30 00:41
how do i add authorization headers to access my endpoint to verify

matt.fellows
2018-05-30 02:39
@avinash.eediga could you please provide more info? Also, have you seen `customProviderHeaders` in https://github.com/pact-foundation/pact-js#verification-options?


brentbarker9
2018-05-30 20:17
Can I match based on the key? For example, I have a payload that returns with `{"monthJan":5}`, and every month that key will change (monthFeb, monthMarch, etc..)

mboudreau
2018-05-30 22:19
you can match using a regex

mboudreau
2018-05-30 22:19
wait, I think that might be on the value, not the key

matt.fellows
2018-05-30 22:39
Yep, you can?t do it on the keys yet I?m afraid. That?s something slated for v4 of the spec: https://github.com/pact-foundation/pact-specification/tree/version-4

mboudreau
2018-05-30 22:57
@brentbarker9 is there a way to change the data structure? I can't imagine monthJan/monthFeb/etc to be a great way of doing it since the key changes. It's adding more complexity than needed. What are you trying to accomplish with this data structure?

brentbarker9
2018-05-30 23:05
Yeah, talked to the dev. They are going to change the data structure to make a little more sense and not have the keys dynamic

brentbarker9
2018-05-30 23:06
Very cool it is going to be in v4 though

brentbarker9
2018-05-30 23:06
thanks!

g.r.mccann
2018-05-31 10:39
has joined #pact-js

dervis4
2018-06-07 08:26
has joined #pact-js

vinny
2018-06-15 06:01
has joined #pact-js

vinod.baradwaj
2018-06-21 10:51
is it possible to pass query parameter values in array ? something like this `page=[1]&limit=[25]&fql=[]`

bethskurrie
2018-06-21 10:51
It should just be a string

bethskurrie
2018-06-21 10:52
I don't think it would be treated any differently to any other string.

bethskurrie
2018-06-21 10:52
`{page: "[1]"}`.

bethskurrie
2018-06-21 10:52
Are you trying to work around some limitation in pact, or is that what your API requires?

vinod.baradwaj
2018-06-21 10:57
this is what my API requires

bethskurrie
2018-06-21 10:57
Should be fine. Why do you ask? Have you had problems?

vinod.baradwaj
2018-06-21 11:01
no problem.. i just wanted to try that

ragarwal
2018-06-22 03:49
has joined #pact-js

abubics
2018-06-22 10:17
Doesn't sound very consumer-driven :P

wchuang
2018-06-22 16:56
has joined #pact-js

wchuang
2018-06-22 16:57
Hi, I am new on pact. I am having some issue with regex matching on a request, is not matching any other value after the one specified in generate. I noticed if I remove manually from the json the [0] it then start to work. how should I setup in order to allow any value to be match? any idea?

bethskurrie
2018-06-23 23:46
Something is wrong with the serialisation of the query. It should be an object, not a string. @matt.fellows does pact js turn the query in to a string, or does it pass the object through?

matt.fellows
2018-06-24 00:48
I'll double check Beth. It should turn it into an object

bethskurrie
2018-06-24 00:51
@wchuang can you post the mock service logs?

matt.fellows
2018-06-24 01:12
@bethskurrie this is what the framework serialises before sending over the wire to the mock service: ``` "request": { "method": "GET", "path": "/animals/available", "query": { "page": { "json_class": "Pact::Term", "data": { "generate": "1", "matcher": { "json_class": "Regexp", "o": 0, "s": ".*" } } } } } ```

matt.fellows
2018-06-24 01:13
I?m not treating query strings any different to regular parameters, and to my eyes that looks to be consistent

bethskurrie
2018-06-24 01:45
Yep, it looks fine to me.

bethskurrie
2018-06-24 01:47
@wchuang what you see in the pact is not what the mock service uses for matching. The pact is written after the request matching is done.

matt.fellows
2018-06-24 01:56
also that matcher is pretty useless (it?s a regex that matches everything) - you might as well just match on type with `like('1')` which basically matches any string

matt.fellows
2018-06-24 01:58
@wchuang do you mean that when you modify the pact, it fixes your _consumer_ test or the _provider_ verification test?

matt.fellows
2018-06-24 01:59
I?ve just tested that locally anyway using the e2e examples in the repository, and the consumer test passes just fine

wchuang
2018-06-25 15:36
sorry for the delay

wchuang
2018-06-25 15:37
15:36:36 [INFO] ===> Received request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["2"]}), headers: Some({"Authorization": "Basic Og==", "Content-Type": "application/json", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36", "Accept-Encoding": "gzip, deflate, br", "Cache-Control": "no-cache", "Accept-Language": "en-US,en;q=0.9,it;q=0.8", "Postman-Token": "c9ebfe6b-d8c6-000c-5d03-b31d268636c3", "Accept": "*/*", "Connection": "keep-alive", "Host": "localhost:18119"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } 15:36:36 [INFO] body: '' 15:36:36 [INFO] comparing to expected request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["1"]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {"query": Category { name: "query", rules: {"page[0]": RuleList { rules: [Regex(".*")], rule_logic: And }} }} }, generators: Generators { categories: {} } } 15:36:36 [WARN] No matching request found, sending 404 Not Found

wchuang
2018-06-25 15:37
thanks :slightly_smiling_face:

wchuang
2018-06-25 16:25
I used the regex, because now I am matching anything, but in long term i want to also do assertation on the string itself. i am trying now with like

wchuang
2018-06-25 16:30
service | ===> Received request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["2"]}), headers: Some({"Postman-Token": "866f0fef-1ecd-122c-801b-4480d74c63d2", "Authorization": "Basic Og==", "Accept": "*/*", "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36", "Host": "localhost:18119", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "en-US,en;q=0.9,it;q=0.8", "Connection": "keep-alive", "Content-Type": "application/json", "Cache-Control": "no-cache"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } service | 16:27:40 [INFO] body: '' service | service | 16:27:40 [INFO] comparing to expected request: Request { method: "GET", path: "/api/objects", query: Some({"page": ["1"]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {"query": Category { name: "query", rules: {"page[0]": RuleList { rules: [Type], rule_logic: And }} }} }, generators: Generators { categories: {} } } service | 16:27:40 [WARN] No matching request found, sending 404 Not Found

wchuang
2018-06-25 16:30
no matching with Like, use somethinglike could not a like

wchuang
2018-06-25 16:30
withRequest: { method: 'GET', path: '/api/objects', query: { page: somethingLike('1') } },

wchuang
2018-06-25 16:31
that the test

wchuang
2018-06-25 16:31
and this is the json generated "description": "Get object", "request": { "method": "GET", "path": "/api/objects", "query": "page=1", "matchingRules": { "$.query.page[0]": { "match": "type" } } },

wchuang
2018-06-25 16:31
I just call with /api/objects?page=2

wchuang
2018-06-25 16:32
on the consumer test works, I need then to start the mock service and use is like the real one, here is failing

bethskurrie
2018-06-26 05:55
@wchuang which implementation are you using?

bethskurrie
2018-06-26 05:56
Those aren't the mock service logs from the ruby implementation (used by pact-js)

wchuang
2018-06-26 11:36
Hi beth, sorry for the misunderstanding, as said at the beginning I am new to pact :stuck_out_tongue: I have talked with my qa team, and basically we are using the pact-stub-server to then run the json file. that log come from there


wchuang
2018-06-26 11:36
I guess here is the prob, do you know if these are compatible to be use in that way?

bethskurrie
2018-06-26 11:57
Oh! You'll need @uglyog to help you with that.

wchuang
2018-06-26 12:39
k thanks beth for our help :slightly_smiling_face:

vinod.baradwaj
2018-06-27 06:22
this happens when we use the pact files with stub-server

spai
2018-06-27 10:37
has joined #pact-js

liran.tal
2018-07-05 05:23
has joined #pact-js

bsayers
2018-07-11 08:01
has joined #pact-js

mikey
2018-07-12 21:06
has joined #pact-js


matt.fellows
2018-07-12 21:07
So yep, basically that?s the right one

mikey
2018-07-12 21:13
Cool. You mentioned avoiding karma-pact when possible. Why is that?

matt.fellows
2018-07-12 21:21
Well it?s just a bit more complicated to setup and has some restrictions. The reason is that inside Karma you don?t have access to the filesystem, so you need to configure Pact in your client test and in the Karma config (which starts the mock server, logs etc.). But the big one for me is that it encourages testing via UIs (end-to-end / acceptance style) rather than testing _just_ the collaborating components using pure JS


mikey
2018-07-12 21:23
:ewww:

mikey
2018-07-12 21:24
yeah I?d like to avoid a UI

matt.fellows
2018-07-12 21:24
hehe

matt.fellows
2018-07-12 21:24
that?s not to say that `karma-pact` means you have to test via the UI, but Karma most often is associated with it. If you know what you?re doing (i.e. can structure your tests appropriately) then you?re good :slightly_smiling_face:

mikey
2018-07-12 21:25
right on

mikey
2018-07-12 21:25
thank you for your time! this is helpful info

matt.fellows
2018-07-12 21:25
no worries!

matt.fellows
2018-07-12 21:25
Now, I think I?ve seen your name from somewhere before - you?ve been using Pact for a while yeah?

mikey
2018-07-12 21:26
yessir I have, and with pleasure :simple_smile:

matt.fellows
2018-07-12 21:26
:smile:

matt.fellows
2018-07-12 21:26
Have I seen you on the Pact Broker forums maybe? (i.e. the forum for the hosted product http://pact.dius.com.au ? which is now #pact-broker)

mikey
2018-07-12 21:28
I think you and Beth did a video ?intro to Pact? meeting with us a while ago (for Instructure). Also I?ve asked a few questions in the Google Group and Stackoverflow.

matt.fellows
2018-07-12 21:28
aha! Yes that?s it

mikey
2018-07-12 21:29
thanks to Pact we?ve scaled back our E2E test suite and moved almost all of them to run on deployed ?staging? and ?prod? environments only. So much faster CI!!

matt.fellows
2018-07-12 21:29
Where in discussions with Robert Lamb at the moment

matt.fellows
2018-07-12 21:29
oh cool, that?s really great to hear

mikey
2018-07-12 21:30
excellent, yeah Robert?s leading the Pact adoption for our flagship product

mikey
2018-07-12 21:30
speaking of whom, I have a meeting with him right now :smile:

matt.fellows
2018-07-12 21:30
haha ok

mikey
2018-07-12 21:30
Thanks again, matt! Really appreciate all your help.

matt.fellows
2018-07-12 21:30
say hi (and let him know that when it?s daylight here i?ll be talking with out people about how we can help :smile: )

michael.follmann
2018-07-16 21:38
has joined #pact-js

michael.follmann
2018-07-16 21:54
Hi, I?m trying to integrate Pact JS into a React project. It worked well until I tried to build the application with Jenkins. When I execute `yarn install` I get the following error: ``` `Postinstalled Failed Unexpectedly: Extraction failed for /var/lib/jenkins/workspace/.../node_modules/@pact-foundation/pact-node/standalone/pact-1.52.1-linux-x86_64.tar.gz: Checksum rejected for file 'pact-1.52.1-linux-x86_64.tar.gz' with checksum pact-1.52.1-linux-x86_64.tar.gz.checksum` ``` I doubt that this a Pact JS issue, I?d rather blame Jenkins or Nexus. But I was hoping that maybe you have seen this before and could give me a useful hint how to resolve this. Thank you in advance!

matt.fellows
2018-07-16 22:20
It would be worth trynig to get your hands on `/var/lib/jenkins/workspace/.../node_modules/@pact-foundation/pact-node/standalone/pact-1.52.1-linux-x86_64.tar.gz`

matt.fellows
2018-07-16 22:21
Perhaps there is an intermediate proxy or something and it?s not properly downloading it, so when it does the validation it?s incorrect?

michael.follmann
2018-07-17 07:12
Thank you @matt.fellows! Unfortunately, the workspace is already gone and I can?t reproduce the issue. I can see that this file has been downloaded from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.52.1/pact-1.52.1-linux-x86_64.tar.gz. Maybe it was a temporary issue with GitHub or any network/firewall component that corrupted the artifact.

matt.fellows
2018-07-17 07:14
the old ?turn it on and off again? trick - no worries, glad it?s up and working :slightly_smiling_face:

michael.follmann
2018-07-17 07:39
It?s safe to assume that it was a temporary GitHub issue: https://status.github.com/messages ``` Jul 16, 2018 7:44 PM 20:04 CEST We've discovered the issue causing connectivity failures and are remediating. ``` Thank you for your support! :+1:

matt.fellows
2018-07-17 07:44
no worries

dominic.jones
2018-07-17 07:54
has joined #pact-js

matt
2018-07-18 16:19
has joined #pact-js

liran.tal
2018-07-23 05:43
what?s the status of the pact js framework in terms of supporting parallel tests ? the most prevalent example is jest

matt.fellows
2018-07-23 07:02
It?s possible, albeit you?ll need to follow the caveats outlined in the readme

matt.fellows
2018-07-23 07:02
it?s easiest if the parallelised tests are hitting a different mock endpoint

bethskurrie
2018-07-23 07:10
Easiest == only possible.

matt.fellows
2018-07-23 07:11
or `s/a different mock endpoint/a different mock provider`

matt.fellows
2018-07-23 07:11
you definitely need a different _mock endpoint_ to make tests against a single provider work.


liran.tal
2018-07-23 07:56
alright. going to test that soon and will report back with feedback

matt.fellows
2018-07-23 08:43
Let us know how things go. I should be semi available later on tonight :laughing:

liran.tal
2018-07-23 09:02
no rush, but appreciate it :wink:

antonello
2018-07-26 11:02
has joined #pact-js

codypumper
2018-08-08 14:03
has joined #pact-js

kurst03
2018-08-09 00:29
has joined #pact-js

mbudde
2018-08-09 08:47
has joined #pact-js

liran.tal
2018-08-09 16:50
how much ?beta? is pact-js 6 exactly? :slightly_smiling_face:

matt.fellows
2018-08-09 20:42
More production ready than beta.

matt.fellows
2018-08-09 20:43
It's just the message pact interface that might change. We were wanting more feedback

liran.tal
2018-08-10 08:21
is there a PR or an issue opened on it which I should follow? and is there a list of items that need to land to make 6 ready?

simon.nizov
2018-08-12 09:06
has joined #pact-js

wilkin4
2018-08-12 21:33
has joined #pact-js

nathanrobert.smith
2018-08-13 12:35
has joined #pact-js

dagarwal
2018-08-15 06:44
has joined #pact-js

dagarwal
2018-08-15 06:46
Hi ,is it possible to create interactions in JS like this ?matchingRules?: { ?$.query.var1[0]?: { ?match?: ?regex?, ?regex?: ?.*? }, ?$.query.var2[0]?: { ?match?: ?regex?, ?regex?: ?.*? }, what should i pass in var 2 that my two api calls are successful http://localhost:${PORT}/api/objects?var1=0&var2=25 and http://localhost:${PORT}/api/objects?var1 Is it possible to do by provider states?

matt.fellows
2018-08-15 09:00
Rather than showing the expected pact file, let's start at the start. What's the goal of your test? You can definitely apply matchers to query strings if that's what you're asking

matt.fellows
2018-08-15 09:36
You'll probably want to use a type matcher also, rather than a regex if you don't care about the value

dagarwal
2018-08-15 09:45
I want two tests to work .For example One uses only one parameter and other query uses two parameter .How do i do that


dagarwal
2018-08-15 09:45
like this

dagarwal
2018-08-15 09:46
one is to list the data and in other test we pass one more parameter of sorting

liran.tal
2018-08-15 13:46
@dagarwal there isn?t any problem to do that. what?s your issue?

liran.tal
2018-08-15 13:46
you define different interactions in different tests so there?s no reason why you can?t do what you just described

dagarwal
2018-08-15 13:49
I tried the same way .It just creates only one response for two interactions

dagarwal
2018-08-15 13:49
let me share the code with u

liran.tal
2018-08-15 13:50
you should do: 1. set up interaction 2. run your test on the cdc 3. verify the interaction for each one single test case that you have

liran.tal
2018-08-15 13:50
it?s a best practice regardless to cdc

dagarwal
2018-08-15 13:57
I have shared the code with u

matt.fellows
2018-08-15 22:31
Did you want to share it with the channel so you can get the collective help of the community?

dagarwal
2018-08-17 14:23
@matt.fellows it allows me to create only one json , m adding two interaction with diff query and same path

matt.fellows
2018-08-17 22:27
You don't need to run setup for each test. You should be able to run it once for the whole test suite. Secondly, each test is unique based on the `given` and `uponReceiving` values. You can differentiate then with different values and pact will then record them as unique interactions

uglyog
2018-08-19 02:44
has joined #pact-js


deshdeepdivakar
2018-08-19 03:17
has joined #pact-js

richarddalziel
2018-08-19 09:34
has joined #pact-js

richarddalziel
2018-08-19 09:34
Cheers!

richarddalziel
2018-08-19 09:39
If there's any examples of larger code bases with Angular Karma and PactJS out there - i'd been keen to have a look!

richarddalziel
2018-08-19 17:38
Is this usually a fairly quiet channel over the weekend yeah?

matt.fellows
2018-08-19 21:33
Hehe yeah

richarddalziel
2018-08-19 21:48
No worries :stuck_out_tongue:

matt.fellows
2018-08-19 21:51
Ah, I thought I had responded to this. I have some ideas/tips but have not used it with karma in anger.


matt.fellows
2018-08-19 21:54
The mock server that spins up is specific to each consumer/provider pair. So you can't reuse it for others. This is often the cause of strange behavior

richarddalziel
2018-08-19 21:57
The provider/consumer pair is unique. But it's specified at the top of each spec file like so : let provider; beforeAll(function (done) { provider = new PactWeb({ consumer: 'FRESUI', provider: 'FRESAPI', logLevel: 'info', port: 1234, host: 'localhost', }); // required for slower CI environments setTimeout(done, 2000); // Required if run with `singleRun: false` provider.removeInteractions(); }); afterAll(function (done) { provider.finalize().then(done, e => done.fail(e)); });

richarddalziel
2018-08-19 21:58
I had looked at the README but wasn't sure how to achieve the setup and teardown across all Karma Tests. As a sort of beforeAllTests

richarddalziel
2018-08-19 21:59
I'm not sure how much of a clue it is - but i get all sorts of failure spam on my console (Even on successful test pass).

matt.fellows
2018-08-19 22:00
I don't think you can at this point. I'd suggest setting up multiple pact servers (on different ports) in your karma config, and then link to the different servers in your tests. 1 for each mock server

richarddalziel
2018-08-19 22:05
Even with the same consumers? Is this just from a reliability standpoint?

richarddalziel
2018-08-19 22:06
It does seem to pass on occassion on the build servers, just not reliably

mboudreau
2018-08-20 04:58
most people have the weekend off from work :wink:

matt.fellows
2018-08-20 06:40
for the same consumer/provider _pair_, yes. If you have different providers but the same _consumer_ then it?s likely to cause issues

matt.fellows
2018-08-20 06:42
In your Karma config, you?ll need a separate mock server for each unique consumer/provider combination. e.g. if you have two providers, something like this: ``` // Pact Providers pact: [{ port: 1234, consumer: 'Consumer', provider: 'Provider1', log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts') }, { port: 5678, consumer: 'Consumer', provider: 'Provider2', log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts') } ], ```

matt.fellows
2018-08-20 06:44
Karma is responsible for starting the mock servers. After that, the jasmine tests are responsible for wiring to the correct mock server

richarddalziel
2018-08-20 07:22
Shock horror :joy: I only ask to set my expectations right :wink:

richarddalziel
2018-08-20 07:23
Cheers Matt - i had a quick go last night but had some issues. On for another go now :slightly_smiling_face:

richarddalziel
2018-08-20 07:36
Actually - just re-read back there. In the tests my Consumer/Provider Pair IS the same. Is it still recommended for them to be on 2 seperate providers?

matt.fellows
2018-08-20 11:32
and yet, I?m sure if we reviewed commit history this is where the majority of commits are made :smile:

mboudreau
2018-08-20 21:00
only for the good projects :wink:

matt.fellows
2018-08-20 21:01
:laughing:

richarddalziel
2018-08-21 06:25
I think i've figure out what's wrong. I had afterEach((done) => { provider.verify().then(done, e => done.fail(e)); }); In each of my tests when i was never looking to do this on my Angular tests. My intention was to create unit tests with the mock responses - generate a pact file, publish to broker and then verify the pact on the actual consumers CI Build.

richarddalziel
2018-08-21 06:26
So verifying the provider in the angular tests is pointless (Or is it, question for another day), and removing this resolves my issue

matt.fellows
2018-08-22 23:21
Hmm something doesn?t seem right here. `provider.verify().then(done, e => done.fail(e));`is not actually doing a provider verification, it?s checking that what you told the mock you were about to send to it in fact came through. If things are failing, that?s a cause for concern

matt.fellows
2018-08-22 23:22
if you could share a working example, or close enough to what you have it might be useful


richarddalziel
2018-08-23 06:31
Ah i did read afterwards that i may have misunderstood there. Perhaps there's a bug with this as it did seem to be fairly inconsistent with the results it provided. I'll hopefully get some time to dive into this again, i hit a bit of another snag with state management in the other thread too.

matt.fellows
2018-08-23 06:41
oh dear

matt.fellows
2018-08-23 06:42
if you have code that reproduces it, I can either help fix the bug, the docs or your code

richarddalziel
2018-08-23 09:00
I'll see if i can isolate it in a smaller repository - it may take me to the weekend to get round to it though

bernardo.guerreiro
2018-08-23 12:35
has joined #pact-js

bernardo.guerreiro
2018-08-23 12:48
Hello everyone. I have a question regarding using the `customProviderHeaders` . I am using it with AWS authentication, but I need each different request to be authenticated differently. How do I add a different provider header to each single interaction? Because basically, I need to dynamically add the headers according to information about the interaction I'm currently on. Is there a direct way to do this?

matt.fellows
2018-08-23 12:53
Yeah it?s a limitation at the moment. Currently you can?t do it per interaction, unless your verification step is split for each interaction (not easy to do)

matt.fellows
2018-08-23 12:53
could you please raise a request, I think I have a solution for working around how this works that could achieve this

bernardo.guerreiro
2018-08-23 13:10
i was thinking as a workaround of getting the json file from the pact broker in a separate function, running through it and dynamically adding the auth header, make a new (local json), and then use that path for the pactUrls instead. This should work right?

bernardo.guerreiro
2018-08-23 13:10
sure, where should I raise the request? pact-js repo ?

nabrosimova
2018-08-23 19:41
has joined #pact-js

bherrera
2018-08-23 19:42
has joined #pact-js

matt.fellows
2018-08-23 20:52
Yes please

bernardo.guerreiro
2018-08-24 17:01
Hello guys. I could use some help. I seem to have come across a weird bug, or maybe I am doing something wrong. We spent a while trying to debug it thinking it might be something we are doing on our side, but after debugging some of the code, I think it might be on pact-provider-verifier.rb , since I assume it is somewhere in there that it makes the HTTP request to my local server, but that's as far as we got. - I have a pact broker hosted on heroku (temporarily) deployed like this https://github.com/pact-foundation/pact_broker/tree/master/example , which i believe is using the latest version. - Since this is a Serverless project, we had to make a local server for the providerStatesSetupUrl. I am using the customProviderHeaders option to do AWS authentication. I need to pass in 3 headers. This is where it gets weird. I have to pass in 'Authorization' , 'X-Amz-Date' and 'Content-Type' headers. - If I just pass in the first 2, I can see that pact talks to my local setup server, and it passes it the state in the body of the request. This, however, won't work, since it needs the third header. - However, when I pass in the additional header 'Content-Type: application/x-www-form-urlencoded ' , for some reason, the state is no longer passed in the body of the request. It is being sent as an empty object {}, without the state. It appears if I send any Content-Type that isn't Content-Type/application-json, including some gibberish , the state gets passed as empty. Any clues?

adamgreen
2018-08-28 10:15
has joined #pact-js

adamgreen
2018-08-30 08:18
Morning all, having some issues getting Pact working with Angular 6 and Karma. See below for the log against the terminal, and the package.json file in the thread. I'm following the tutorial on the git hub page, using the Karma + Jasmine page to modify the other relavent files. Any help would be appreciated. Thank you

adamgreen
2018-08-30 08:19
apologies in advance for any rookie mistakes, first time using JS/TS frameworks here

richard.peckett
2018-08-30 08:21
has joined #pact-js

rhys
2018-09-04 10:31
has joined #pact-js

dagarwal
2018-09-04 16:08
Hello all , I am getting ?Failed to load pact from ?pacts? - Failed to parse Pact JSON - expected value at line 1 column 1 ?error after docker pull , I have not made any changes in pact file .Any suggestions ?

christophe
2018-09-19 17:25
has joined #pact-js

leon.gaban
2018-09-19 18:10
has joined #pact-js

leon.gaban
2018-09-19 18:10
Hi guys

leon.gaban
2018-09-19 18:11
I?m running into an issue and someone in general chat told me to ping you guys? https://stackoverflow.com/questions/52410277/error-with-typescript-pact-io-test-popsicleerror-unable-to-connect-to

leon.gaban
2018-09-19 18:11
Oh hah I see my issue posted above

abubics
2018-09-20 02:06
"solved" :upside_down_face:

matt.fellows
2018-09-20 12:30
Did you ever work out what this is?

matt.fellows
2018-09-20 12:31
Did you ever solve this? Sorry for my delay, must of missed it

matt.fellows
2018-09-20 12:32
I think there is an issue on the repo that logs this issue. Why do you need to _actually_ auth to AWS for the provider verification? Can you stub it out?

adamgreen
2018-09-20 13:25
hi @matt.fellows, no worries at all. Afraid I haven't been able to solve it no

dagarwal
2018-09-20 13:25
yes it worked for me later

wilson.mahann
2018-09-20 14:22
has joined #pact-js

zackary.mccolgan
2018-09-20 17:11
has joined #pact-js

matt.fellows
2018-09-20 22:42
:+1:

leon.gaban
2018-09-25 21:41
I asked this in General, but realized this is the correct place to post this issue

leon.gaban
2018-09-25 21:41
But I?m getting the following Pact test errors: ``` console.error node_modules/@pact-foundation/pact/pact.js:110 Pact verification failed! console.error node_modules/@pact-foundation/pact/pact.js:111 Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /frontoffice/api/liquidity-pool/get-total-payout ```

matt.fellows
2018-09-26 03:19
Hi @leon.gaban, the answer is in the error you are getting - your code (presumably `getTotalPayout`) is not hitting the Pact Mock Service endpoint `/frontoffice/api/liquidity-pool/get-total-payout`. It might be making an HTTP call, but it must not be calling the right thing (the Pact mock server).

leon.gaban
2018-09-26 13:12
ok I?ll work on mocking that endpoint today, thanks!

leon.gaban
2018-09-26 14:47
@matt.fellows are there any good examples you could pass on?

leon.gaban
2018-09-26 14:52
Hmm, `getTotalPayout` looks correct to me tho

leon.gaban
2018-09-26 14:53
and I have a `src/__mocks__/axios.ts` file ``` // tslint:disable-next-line:no-empty const mockNoop = () => new Promise(() => {}); export default { get: jest.fn(() => Promise.resolve({ data: { total_payout: 100.21 }})), default: mockNoop, post: mockNoop, put: mockNoop, delete: mockNoop, patch: mockNoop }; ```

leon.gaban
2018-09-26 14:56
I?ll post a new stackoverflow question (will change paths to hide real api), I need code example help at this point.


leon.gaban
2018-09-26 15:03
I will try create a small repo to reproduce this


leon.gaban
2018-09-26 15:31
running into a no tests found error atm :confused: `No tests found`

matt.fellows
2018-09-26 20:28
This suggests you're mocking out axois completely, so no http call us going to be made. Hence why it's not making any http calls to the next mock server

matt.fellows
2018-09-26 20:30
Pact is expecting a call via http. It's pretending to be your provider and will respond when interacted with

matt.fellows
2018-09-26 20:47
Thanks Leon

matt.fellows
2018-09-26 20:51
I?ve responded on Stack Overflow

matt.fellows
2018-09-26 22:44
There are multiple problems with your code 1. Axios seems to be used, but is not in your package.json. I?m guessing because you?re mocking it out (2) 2. Axios is mocked out to provide canned responses, DO NOT mock out axios during Pact testing (it?s ok for local dev if y,ou want) as this will prevent real calls being made to Pact 3. Configure axios in tests to hit the Pact mock service. Something like pactSetup.ts: ``` // Configure axios to use the Pact mock server for Pact tests import axios from "axios"; axios.defaults.baseURL = "http://localhost:1234"; ``` 4. Read the log files that Pact spits out. It tells you what?s going on. To re-iterate: You?ve told Pact that there should be an interaction on 5. You might want to use Pact for a local stub server for local development, once you?ve started generating Pacts (after 1-4 are fixed). The binary is actually installed in your node_modules and the docs for how it operates are at https://github.com/pact-foundation/pact-ruby-standalone/releases I typically have a script in package.json that looks something like: ``` "stubs": "$(find . -name pact-stub-service | head -n 1) pacts/* --port 4000" ``` So that I can run `npm run stubs` and have a local stub of the provider running on port 4000


matt.fellows
2018-09-26 22:48
The rest is up to you mate!

matt.fellows
2018-09-28 01:09
How did you go @leon.gaban?

leon.gaban
2018-09-28 13:59
I?ll try to get it working this weekend, so I?ll remove the axios mock

liran.tal
2018-09-30 08:55
while the README at `https://github.com/pact-foundation/pact-js` is for version 6, the installation instructions there are `npm i -S @pact-foundation/pact@latest` which will install version 5 since the `latest` tag is associated with that where-as 6 is tagged as pre-release

liran.tal
2018-09-30 08:55
not sure if that?s intentional or not but I find it confusing

matt.fellows
2018-09-30 11:43
That is misleading, I'll get that fixed. Thanks Liran!

liran.tal
2018-09-30 12:14
Thanks! anytime

matt.fellows
2018-09-30 21:50
:+1:

matt.fellows
2018-10-01 00:57
Fix on the way out for this process - thanks for the tip!

abubics
2018-10-01 01:48
lol, thanks integration . . . > *Release - null*

matt.fellows
2018-10-01 01:49
right?!

liran.tal
2018-10-01 11:30
Nice :)

tjones
2018-10-02 04:30
has joined #pact-js

holden.mcginnis
2018-10-03 15:45
has joined #pact-js

matt.fellows
2018-10-09 00:04
so I?m thinking of deprecating node versions below `6` in the next release. It?s hard to keep dependencies up to date and secure, because a lot of them only support 6 or later. Thoughts?

matt.fellows
2018-10-09 00:05
Release train `6.x.x` can continue to support until it?s deprecated, and `5.x.x`will be deprecated (> 1 year old now)

liran.tal
2018-10-09 00:06
@matt.fellows sounds like a good idea as 6 is anyway in maintenance mode.

liran.tal
2018-10-09 00:06
so I guess new threshold will be 8?

liran.tal
2018-10-09 00:06
5 is not relevant at all

matt.fellows
2018-10-09 00:07
I think 6 is still pretty common, so I?d prefer to start there unless good reason not to. Pact is used a lot in Enterprise environments, which can sometimes be a bit slower to upgrade/adopt

matt.fellows
2018-10-09 00:07
Part of the trigger, is I?m constantly finding myself (and others) to fix things to make it compatible - we?re fighting the system now, rather than flowing with it.

liran.tal
2018-10-09 00:09
yep that?s true

matt.fellows
2018-10-09 00:09
I can see why 8 might be good - `async` etc.

liran.tal
2018-10-09 00:09
nods

liran.tal
2018-10-09 00:10
also, 6 will be unsupported by 2019 which is just a few months ahead

matt.fellows
2018-10-09 00:10
hmmm

matt.fellows
2018-10-09 02:04
Hmmm? this integration might be a bit noisy!

mboudreau
2018-10-09 02:31
:stuck_out_tongue:

matt.fellows
2018-10-09 02:32
Was looking at some bots to automate versioning, staleness and triage issue/PRs - same :clock2:

mboudreau
2018-10-09 02:32
yeah, I just got spammed with emails

matt.fellows
2018-10-09 02:32
Heaps of good ones at https://probot.github.io/apps

mboudreau
2018-10-09 02:32
good job :wink:

matt.fellows
2018-10-09 02:32
sorry about that

dagarwal
2018-10-09 11:10
i have pact tests which have get , Put request and for video functionality .It stops working if i go higher than v0.0.9 . anyone has any idea or faced this issue


tjones
2018-10-11 00:55
Hi all - I wrote a proposal for improving the `pact-js` DSL - I'd be very interested in any thoughts: https://gist.github.com/TimothyJones/d138bf765509d41e0ce8a4bfb777a31d


adamgreen
2018-10-15 09:50
@matt.fellows hi matt, just to update you, i've managed to solve the above problem. The issue was in my *pact.spec.ts file i was trying to import Pact class from /pact instead of pact-web Using the equivalent PactWeb class is now allowing Karma to run without throwing up the errors in the previous attachement. However, when i come to try and create a broker for my tests, i'm required to use the Publisher class from pact-node module folder, doing this is bringing me back to the original problem of all those module not found errors in the terminal,. pact-web doesn't seem to have an equivalent for publishing to a broker, any ideas?

matt.fellows
2018-10-15 10:14
Hi Adam.

matt.fellows
2018-10-15 10:14
That?s great to hear! On the publishing topic, you would never want to be publishing pacts from `pact-web`, at least, it?s not an intended behaviour

matt.fellows
2018-10-15 10:15
> However, when i come to try and create a broker for my tests, Hmm, that doesn?t make sense. The broker is a hosted component (e.g. http://pact.dius.com.au or https://github.com/pact-foundation/pact_broker/), do you mean ?publish a pact?? > i?m required to use the Publisher class from pact-node module folder, doing this is bringing me back to the original problem of all those module not found errors in the terminal,. Yes, this won?t work in a non-node env (https://github.com/pact-foundation/pact-js/#using-pact-in-non-node-environments) > pact-web doesn?t seem to have an equivalent for publishing to a broker, any ideas? Yes, pact-web is just a DSL for the tests themselves, which when successfully run then produce a pact file. This is what gets published. It is recommended that only CI would publish pacts, so I would decouple the publishing (e.g. create a task `npm run pact:publish` from your test runs (`npm t`) - see https://github.com/pact-foundation/pact_broker/wiki/Set-up-checklist#consumer-team

adamgreen
2018-10-15 10:42
thanks for the reply Matt, appreciate your help. Ideally would like to debug the publishing code locally, but it could be we need to look at not using Karma if we're wanting to do that. Thanks again :+1:

matt.fellows
2018-10-15 12:08
What do you mean by "debug publishing locally"?

matt.fellows
2018-10-15 12:13
Oh right, I mean you can still test it from your local, but you wouldn't normally attach the publish step to your testing code anyway. There's an e2e example in the project repo if you want to see an example though

adamgreen
2018-10-15 12:24
we've got a http://pact.net implementation for our back end microservices, and our senior developer is setting up the entire pact test process from creation>verification>publishing as part of the test. This is allowing us to test that the broker is running the contract comparison against the consumer/provider correctly. I was attempting to do the same with our front end application (written in Angular). You think this approach is unwise in general or for simply a front-end application? Thanks

matt.fellows
2018-10-15 22:28
Just in general, you don?t want to be publishing pacts to the broker during development (i.e. TDD). Unless each time you run your test process locally you want to both publish the artifacts to the broker, and then run the provider verification (which seems very much overkill to me).

matt.fellows
2018-10-15 22:29
You might want to be able to set an environment flag (e.g. `CI=true`) to be able to test that the process works, or for setting it up in the first place

vinod.baradwaj
2018-10-16 08:25
Hi, When i try provider verification like this, ```describe('Pact Verification', () => { it('should validate the expectations of Matching Service', function () { let opts = { provider: 'Animal Profile Service', providerBaseUrl: 'http://localhost:8081', pactBrokerUrl: 'https://test.pact.dius.com.au/', pactBrokerUsername: 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M', pactBrokerPassword: 'O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1', publishVerificationResult: true, providerVersion: "1.0.0" } return new Verifier().verifyProvider(opts) .then(output => { console.log('Pact Verification Complete!') console.log(output) }); }); });``` i get an error ``` 1) Pact Verification should validate the expectations of Matching Service: TypeError: Must provide the providerBaseUrl argument at assertImpl (node_modules/check-types/src/check-types.js:730:11) at assertPredicate (node_modules/check-types/src/check-types.js:718:5) at Function.nonEmptyString (node_modules/check-types/src/check-types.js:710:14) at new Verifier (node_modules/@pact-foundation/pact-node/src/verifier.js:51:27) at Context.<anonymous> (test/pact/proververification.spec.js:26:14)```

vinod.baradwaj
2018-10-16 08:26
what am i missing in this ? i have given providerBaseUrl in opts

matt.fellows
2018-10-16 10:28
hmm it looks ok to my eye

matt.fellows
2018-10-16 10:28
Can you please share an example project on GitHub I can use to reproduce the issue? (i.e. with package.json etc.)


matt.fellows
2018-10-16 11:49
OK I think the first problem is you?re not using the `@pact-foundation/pact` dependency, albeit it should still probably work

matt.fellows
2018-10-16 11:49
see https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/provider.spec.js (it?s using a relative import, but that is the dependency from above)

matt.fellows
2018-10-16 11:52
Ah, you?re problem is you?re using the API that exists on the `@pact-foundation/pact` dependency, but calling it on the `@pact-foundation/pact-node` dependency

matt.fellows
2018-10-16 11:53
Whilst you?re passing the right options through, you?re passing them to `verifyProvider()` and not the `new Verifier(opts)` constructor. As soon as you fix the constructor problem, it will complain that the method doesn?t exist

matt.fellows
2018-10-16 11:53
TL;DR - change `const { Verifier } = require("@pact-foundation/pact-node");` to `const { Verifier } = require("@pact-foundation/pact");`

matt.fellows
2018-10-16 11:53
:ok_hand:

vinod.baradwaj
2018-10-16 12:37
thanks @matt.fellows it worked :slightly_smiling_face:

liran.tal
2018-10-16 21:45
@matt.fellows probably worth to document on the pact-foundation/pact-js github repo the different npms and what are they used for. The README on that repo also references @pact-foundation/pact-node in the broker publishing section

matt.fellows
2018-10-16 22:23
Thanks, I'll check today

daniel.straus
2018-10-16 22:38
has joined #pact-js

marco.dellolio
2018-10-16 23:06
has joined #pact-js

marco.dellolio
2018-10-16 23:07
Good evening, I?m trying to trouble shoot this request ``` describe('List of personal snippets', () => { beforeEach(() => { const interaction = { state: 'I have a list of snippets', uponReceiving: 'a request for all the snippets', withRequest: { method: 'POST', path: '/v2/searches/snippets', body: { type: 'personal' }, headers: { 'Content-Type': 'application/json', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: EXPECTED_BODY, }, } return pactProviders.scintillas.addInteraction(interaction) }) it('returns a list of snippets', async done => { const fetched_data = await fetch(`${url}/v2/searches/snippets`, { method: 'POST', body: JSON.stringify({ type: 'personal' }), headers: { 'Content-Type': 'application/json' }, }) const response = await fetched_data.json() expect(response).toEqual(EXPECTED_BODY) pactProviders.scintillas.verify() done() }) }) ``` In this setup when I added to `withRequest` ``` body: { type: 'personal' }, headers: { 'Content-Type': 'application/json', }, ``` and ``` body: JSON.stringify({ type: 'personal' }), headers: { 'Content-Type': 'application/json' }, ``` to my `fetch` request. The provider doesn?t like it and it dies right after being created ``` [2018-10-16T23:00:38.974Z] INFO: pact-node@6.19.11/72860 on Marcos-MacBook-Pro.local: Created './standalone/darwin-1.54.4/bin/pact-mock-service service --consumer 'Rhapsody' --cors 'true' --pact_dir '/Users/marcodellolio/src/rhapsody/pacts' --host '127.0.0.1' --log '/Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log' --pact-file-write-mode 'merge' --port '8001' --provider 'Scintillas' --pact_specification_version '2'' process with PID: 72882 [2018-10-16T23:00:40.051Z] INFO: pact-node@6.19.11/72860 on Marcos-MacBook-Pro.local: Removing Pact with PID: 72882 [2018-10-16T23:00:40.054Z] INFO: pact-node@6.19.11/72860 on Marcos-MacBook-Pro.local: Deleting Pact Server with options: ``` Should I parse my request in a particular way?

abubics
2018-10-17 00:14
Most of the core maintainers are at an event today, so I'm not sure when you might get a solid reply :sweat_smile:

marco.dellolio
2018-10-17 00:17
oh! thank you for letting me know, do you have a post request example I can confront mine with?

abubics
2018-10-17 00:27
I'll have a look :slightly_smiling_face:

abubics
2018-10-17 00:32
The most recent one I've got handy is from about a year ago . . .

abubics
2018-10-17 00:33
``` describe('can add an thing', () => { // given: beforeEach(() => provider.addInteraction({ state: 'a view with two samplers', uponReceiving: 'request to add a thing', withRequest: { method: 'POST', path: '/view/0/sampler/1/thing', headers: headers.request, body: { type: 'interleaved', metrics: [{ type: 'event', name: 'view' }], variants: [{ name: 'jim', data: '' }, { name: 'bob', data: '' }], name: 'Some new thing' } }, willRespondWith: { status: 201, body: { id: like('0'), state: 'unscheduled' } } }) ); // when: it('', () => client.thing .add(0, 1, { type: 'interleaved', metrics: [{ type: 'event', name: 'view' }], variants: [{ name: 'jim', data: '' }, { name: 'bob', data: '' }], name: 'Some new thing' }) .then(body => { expect(body).to.eql({ id: '0', state: 'unscheduled' }); }) .catch(fail)); }); ```

abubics
2018-10-17 00:35
and in the API client . . .

abubics
2018-10-17 00:35
well, it's quite abstracted, and using `axios`

abubics
2018-10-17 00:36
would that be useful too? or is this enough to work from?

marco.dellolio
2018-10-17 00:40
I think so thank you! I just have to figure out how correctly parse the payloads

abubics
2018-10-17 00:42
if you're not using `axios`, this may not be helpful, but here you go: ``` const mimeJson = 'application/json'; const headers = { 'Content-Type': mimeJson, Accept: mimeJson }; const GET = 'GET'; const POST = 'POST'; const PATCH = 'PATCH'; const DELETE = 'DELETE'; const transformBody = body => { if (body) { return JSON.stringify(body); } return null; }; const wrapRequest = (url, method = GET, body = null) => axios({ url, method, headers, data: transformBody(body) }) .then(resp => resp.data) .catch(error => { if (error.response) { // Made a request, but got a failure code if (error.response.data.message) { const errorMessage = { status: error.response.status, message: error.response.data.message }; throw errorMessage; } ... etc ```

marco.dellolio
2018-10-17 00:44
what `transformBody(body)` does?

abubics
2018-10-17 00:49
it's just above the `wrapRequest` function

marco.dellolio
2018-10-17 00:49
oh sorry I missed it. Thank you

abubics
2018-10-17 00:49
it just calls `JSON.stringify` if the body is truthy (mostly if it's not `null`)

matt.fellows
2018-10-17 02:56
As a quick note, to understand why it?s failing it might be worth setting logging to DEBUG and looking at the log files to see if there is any indication is to why it?s dying

matt.fellows
2018-10-17 02:56
Dying is not good :slightly_smiling_face:

marco.dellolio
2018-10-17 03:07
``` [2018-10-17T01:53:47.261Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Creating Pact Server with options: consumer = Rhapsody, cors = true, dir = /Users/marcodellolio/src/rhapsody/pacts, host = 127.0.0.1, log = /Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log, pactFileWriteMode = merge, port = 8001, provider = Scintillas, spec = 2, ssl = false, sslcert = , sslkey = [2018-10-17T01:53:47.262Z] INFO: pact@7.0.1/86087 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8001" [2018-10-17T01:53:47.815Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Starting pact binary with '/bin/sh,[object Object],... ..."NODE_ENV":"test","JEST_WORKER_ID":"1"}}' ```

marco.dellolio
2018-10-17 03:07
``` [2018-10-17T01:53:47.819Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Created './standalone/darwin-1.54.4/bin/pact-mock-service service --consumer 'Rhapsody' --cors 'true' --pact_dir '/Users/marcodellolio/src/rhapsody/pacts' --host '127.0.0.1' --log '/Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log' --pact-file-write-mode 'merge' --port '8001' --provider 'Scintillas' --pact_specification_version '2'' process with PID: 86109 [2018-10-17T01:53:48.664Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2018-10-17T01:53:48.664Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: INFO WEBrick::HTTPServer#start: pid=86109 port=8001 [2018-10-17T01:53:48.909Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Removing Pact with PID: 86109 [2018-10-17T01:53:48.911Z] INFO: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: Deleting Pact Server with options: consumer = Rhapsody, cors = true, dir = /Users/marcodellolio/src/rhapsody/pacts, host = 127.0.0.1, log = /Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log, pactFileWriteMode = merge, port = 8001, provider = Scintillas, spec = 2, ssl = false, sslcert = , sslkey = [2018-10-17T01:53:48.913Z] DEBUG: pact-node@6.19.11/86087 on Marcos-MacBook-Pro.local: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. FAIL test/pact/consumer/scintillas.test.js ? Test suite failed to run Error: Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout. at mapper (../../node_modules/jest-jasmine2/build/queue_runner.js:41:52) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 13.27s Ran all test suites matching /test\/pact\/consumer\/scintillas/i. ```

marco.dellolio
2018-10-17 03:09
it shuts down a second after, and obviously my fetch sends a request to not existing server

matt.fellows
2018-10-17 03:17
mmm

matt.fellows
2018-10-17 03:17
could you please try running the command it shows in the debug output? e.g. something along the lines of `./standalone/darwin-1.54.4/bin/pact-mock-service service --consumer 'Rhapsody' --cors 'true' --pact_dir '/Users/marcodellolio/src/rhapsody/pacts' --host '127.0.0.1' --log '/Users/marcodellolio/src/rhapsody/logs/mockserver-integration.log' --pact-file-write-mode 'merge' --port '8001' --provider 'Scintillas' --pact_specification_version '2'`

matt.fellows
2018-10-17 03:18
(you probably need to ensure the args are all correct but it _should_ start a server and wait. If it crashes, that might tell us what?s happening)

matt.fellows
2018-10-17 03:18
it?s possible there is perhaps a port conflict

marco.dellolio
2018-10-17 03:29
I?m not sure what command I?m supposed to run. But as soon I remove ``` body: { type: 'personal' }, headers: { 'Content-Type': 'application/json', }, ``` from the request expectation and from the actual fetch post request, the test works correctly

matt.fellows
2018-10-17 03:33
It should start a server on port 8001

matt.fellows
2018-10-17 03:34
you should then be able to hit it e.g. `curl localhost:8001` and it should return something (an error saying it can?t find an interaction)

matt.fellows
2018-10-17 03:34
if that happens, that tells me something else is the problem

matt.fellows
2018-10-17 03:34
I?d say it?s something to do with the way your fetch thing is working

marco.dellolio
2018-10-17 03:36
I suspect that too, because I applied the headers to fix this ``` {"interaction_diffs": [{"body": {"ACTUAL": "[{\"type\":\"personal\"}]", "EXPECTED": [{"type": "personal"}]}, "description": "a request for all the snippets", "provider_state": "I have a list of snippets"}], "message": "No interaction found for POST /v2/searches/snippets"} ```

marco.dellolio
2018-10-17 03:37
because JSON.stringify(body) would not match my expected body

marco.dellolio
2018-10-17 03:37
``` withRequest: { method: 'POST', path: '/v2/searches/snippets', body: [{ type: 'personal' }], headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }, ```

marco.dellolio
2018-10-17 13:39
I was able to solve the problem using `superagent` as client for my request. Still no success with `axios` or `fetch`

brian.smith.keith
2018-10-17 14:33
has joined #pact-js

vinod.baradwaj
2018-10-17 15:10
is there an npm module for `can-i-deploy` ? (https://github.com/pact-foundation/pact_broker-client#can-i-deploy)

liran.tal
2018-10-17 23:27
I can?t spot anything odd with your fetch. are you still using superagent as a workaround?

matt.fellows
2018-10-17 23:30
Yeah, it looks ok to me.

matt.fellows
2018-10-17 23:31
Marco if you could please create a small project we can use to repro and raise an issue on pact-js, we?ll get to the bottom of it.

marco.dellolio
2018-10-18 00:31
Update, looks like I was doing something odd with the beforeAll, afterAll hooks in Jest. I?m trying to spin up a mock provider for each service ``` global.pactProviders = { scintillas: new Pact({ port: 8000 + Number(process.env.JEST_WORKER_ID), log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), } ```

marco.dellolio
2018-10-18 00:33
Looks like is working now, I?ll try to replace `superagent` with `fetch`

matt.fellows
2018-10-18 04:48
:thumbsup:

marco.dellolio
2018-10-19 01:08
Good evening again. Do you mind clarifying this(?): >Each test is fully self-contained, with its own mock server on its own port for ?test? it means test suit I guess. I?m trying to start those 2 providers in parallel ``` global.pactProviders = { scintillas: new Pact({ port: 8000 + Number(process.env.JEST_WORKER_ID), log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), emailGateway: new Pact({ port: 8000 + Number(process.env.JEST_WORKER_ID), log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), } ``` with a ``` beforeAll(async done => { await pactProviders.scintillas/emailGateway.setup() done() }) ``` in each suit but it errors with `Port '8001'/'8002' is already in use by another process.` Working correctly if remove one provider from the global object. Thank you in advance

mboudreau
2018-10-19 01:11
It can be for each test, but it normally adds extra overhead to restart the server every time

mboudreau
2018-10-19 01:12
but fomr what I can see, the JEST_WORKER_ID would be the same for both mocks

mboudreau
2018-10-19 01:12
hence it would have a port conflict

marco.dellolio
2018-10-19 01:13
Shouldn?t the `JEST_WORKER_ID` increase with the test suit ran?

marco.dellolio
2018-10-19 01:15
in fact is failing on two different ports ``` ime: 1s, estimated 4s FAIL test/pact/consumer/email_gateway.test.js0-19T01:07:30.248Z] INFO: pact@7.0.1/96160 on Marcos-MacBook-Pro.local: ? Test suite failed to run Port '8001' is already in use by another process. 16 | logLevel: 'error', 17 | }), > 18 | emailGateway: new Pact({ | ^ 19 | port: 8000 + Number(process.env.JEST_WORKER_ID), 20 | log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), 21 | dir: path.resolve(process.cwd(), 'pacts'), at Pact.Object.<anonymous>.Pact.createServer (../../node_modules/@pact-foundation/pact-node/src/pact.ts:48:10) at new Pact (../../node_modules/@pact-foundation/src/pact.ts:64:34) at Object.<anonymous> (testSetup.js:18:17) FAIL test/pact/consumer/scintillas.test.js ? Test suite failed to run Port '8002' is already in use by another process. 16 | logLevel: 'error', 17 | }), > 18 | emailGateway: new Pact({ | ^ 19 | port: 8000 + Number(process.env.JEST_WORKER_ID), 20 | log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), 21 | dir: path.resolve(process.cwd(), 'pacts'), at Pact.Object.<anonymous>.Pact.createServer (../../node_modules/@pact-foundation/pact-node/src/pact.ts:48:10) at new Pact (../../node_modules/@pact-foundation/src/pact.ts:64:34) at Object.<anonymous> (testSetup.js:18:17) Test Suites: 2 failed, 2 total Tests: 0 total Snapshots: 0 total Time: 2.156s, estimated 4s Ran all test suites matching /test\/pact\/consumer/i ```

marco.dellolio
2018-10-19 01:28
I believe the problem could be in the `beforeAll`: before running the 1st test it starts 8001. Because the suit haven?t started yet and the ?reserved the worker 1? it tries to start a new provider again on 8001.

matt.fellows
2018-10-19 01:59
Have you seen the Jest example in the pact-js repo?

marco.dellolio
2018-10-19 02:00
yes, but in that example there is a single provider

matt.fellows
2018-10-19 02:00
yes, but it is used across two separate test suites

matt.fellows
2018-10-19 02:00
in your case above, technically it _is_ just a single provider ?Scintillas?

matt.fellows
2018-10-19 02:00
You?re just creating two instances of it

matt.fellows
2018-10-19 02:02
In any case, I think you?re right about the logic.

marco.dellolio
2018-10-19 02:02
Hi Matt, this what I?m trying to avoid. If I?m not wrong the example should be run with `--runInBand`

matt.fellows
2018-10-19 02:02
true, yes

marco.dellolio
2018-10-19 02:02
I?m trying to start in parallel two different providers

matt.fellows
2018-10-19 02:02
np

matt.fellows
2018-10-19 02:03
(just wanted to make sure you had good reasons and had thought about it first :slightly_smiling_face: )

matt.fellows
2018-10-19 02:04
I think you?re right though, it?s probably a logic thing where the provider is being created too many times

marco.dellolio
2018-10-19 02:05
I need, in someway, to bind the the second provider to the starting on the first test suit

marco.dellolio
2018-10-19 02:06
or I could scope the `beforeAll` inside each test suit, making sure to start only when the previous is started

matt.fellows
2018-10-19 02:08
why not just a) hard code the port for each test suite or b) randomly generate the port for each test suite?

matt.fellows
2018-10-19 02:08
`s/test/test suite`

marco.dellolio
2018-10-19 02:18
well, hard coding the ports, brought up something new. ``` Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8001" [2018-10-19T02:16:38.270Z] INFO: pact@7.0.1/1710 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8002" ```

marco.dellolio
2018-10-19 02:19
do you see anything wrong with this global object pattern? ``` global.pactProviders = { scintillas: new Pact({ port: 8001, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), emailGateway: new Pact({ port: 8002, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, pactfileWriteMode: 'merge', consumer: 'Rhapsody', provider: 'Scintillas', logLevel: 'error', }), } ```

mboudreau
2018-10-19 02:24
seems to work fine when hard coding?

mboudreau
2018-10-19 02:25
could it be at jest uses parallel test runners?

mboudreau
2018-10-19 02:25
I'm not entirely versed in how jest works

matt.fellows
2018-10-19 02:25
looks OK to me

marco.dellolio
2018-10-19 02:34
sometimes javascript is frustrating ``` Test Suites: 0 of 2 total Tests: 0 total Snapshots: 0 total Time: 1s[2018-10-19T02:36:27.226Z] INFO: pact@7.0.1/5567 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8001" [2018-10-19T02:36:27.228Z] INFO: pact@7.0.1/5567 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" using mock service on Port: "8002" [2018-10-19T02:36:27.273Z] INFO: pact@7.0.1/5568 on Marcos-MacBook-Pro.local: Setting up Pact with Consumer "Rhapsody" and Provider "Scintillas" RUNS test/pact/consumer/scintillas.test.js RUNS test/pact/consumer/email_gateway.test.js Test Suites: 0 of 2 total Tests: 0 total Snapshots: 0 total Time: 2s[2018-10-19T02:36:27.933Z] ERROR: pact-node@6.19.11/5568 on Marcos-MacBook-Pro.local: Pact Binary Error: /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) for "127.0.0.1" port 8001 (Errno::EADDRINUSE) from /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in `new' from /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:85:in `block in create_listeners' from /Users/marcodellolio/src/rhapsody/node_modules/@pact-foundation/pact-node/standalone/darwin-1.54.4/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/utils.rb:82:in `each' ```

marco.dellolio
2018-10-19 02:34
now fails on the same port

mboudreau
2018-10-19 02:35
I don't see a failure?

marco.dellolio
2018-10-19 02:37
sorry I should have it past it all

mboudreau
2018-10-19 02:40
right, I believe it's because that jest try to run all tests in parallel

mboudreau
2018-10-19 02:40
hence, there will be a port conflict

mboudreau
2018-10-19 02:40
unless, there's an individual pact server ran on a random port

mboudreau
2018-10-19 02:40
for each test

marco.dellolio
2018-10-19 02:42
I?m trying to achieve parallelism. For what concerns the server setup I?m just using the following ``` beforeAll(done => { Promise.all( Object.keys(pactProviders).map(provider => pactProviders[provider].setup()) ).then(() => done()) }) afterAll(done => { Promise.all( Object.keys(pactProviders).map(provider => pactProviders[provider].finalize() ) ).then(() => done()) }) ```

mboudreau
2018-10-19 02:43
instead of using beforeAll/afterAll

mboudreau
2018-10-19 02:43
why don't you just use a single before/after?

mboudreau
2018-10-19 02:43
which will run before and after each individual tests?

marco.dellolio
2018-10-19 02:44
I should set a specific before hook for each test suit?

mboudreau
2018-10-19 02:47
I think so, if you want to go the parallel route :slightly_smiling_face:

marco.dellolio
2018-10-19 02:51
let me try this path and I?ll let you know. Thank you guys!

mboudreau
2018-10-19 02:52
:thumbsup:

abubics
2018-10-19 03:26
Btw, we're aware that this is a frustrating issue (especially with Jest), and @schalkt worked on a proposal for a better DSL: https://github.com/pact-foundation/pact-js/issues/215

marco.dellolio
2018-10-19 03:33
so, I was able to run the test in parallel defining the provider inside the test suit. Thank you all as always and good night

abubics
2018-10-19 03:34
Where are you, Marco? It's only 14:34 here :sweat_smile:

marco.dellolio
2018-10-19 03:35
Atlanta, US. Its 23:35 here!

marco.dellolio
2018-10-19 03:35
Where are you all?

abubics
2018-10-19 03:40
Many of us are in Melbourne, Australia~* :flag-au:

mboudreau
2018-10-19 04:07
:arrow_up:

abubics
2018-10-19 04:08
Haha, many are in other places, too :stuck_out_tongue:

tjones
2018-10-22 03:06
@matt.fellows (and other interested parties) - I'm thinking of closing all of those dependabot pull requests

tjones
2018-10-22 03:07
Many of them introduce breaking changes, and for the ones that don't, I'm not sure we should be upgrading libraries without a reason

tjones
2018-10-22 03:07
Thoughts?

matt.fellows
2018-10-22 04:02
yep, go for it. There?s that branch for pact-js that we?ll fix manually to begin with, at which point we can re-enable it

abubics
2018-10-22 04:11
lol, looks like Github's coming back online

simon.nizov
2018-10-23 10:11
@simon.nizov has left the channel

marco.dellolio
2018-10-23 13:11
Hey Guys good morning (I guess good evening in AU:flag-au:). Thank you for your help with jest, everything is running smoothly! I have a question about Karma

marco.dellolio
2018-10-23 13:13
I define my pact server in `karma.conf.js` and in the test file I create a new provider. ``` provider = new Pact.PactWeb({ consumer: 'Rhapsody', provider: 'Scintillas', port: 9443, host: '127.0.0.1', }) ``` What if in my `karma.conf.js` I define more servers, how do I create a mock provider identifying the right server? Just the port?

tom.hombergs
2018-10-23 19:39
has joined #pact-js

tom.hombergs
2018-10-23 19:40
@marco.dellolio yes, we use it like that. The only difference is the port (and potentially the provider name)

matt.fellows
2018-10-23 20:57
@marco.dellolio, as @tom.hombergs said. You also don?t even need to pass the consumer/provider to the `PactWeb` constructor anymore (no need to duplicate what?s configured in the karma conf anyway). There should be a warning in your console about that I think

marco.dellolio
2018-10-23 21:04
Thank you guys. Yes I was able to dry up my code a little

matt.fellows
2018-10-23 21:18
:+1:

marco.dellolio
2018-10-24 02:14
Hello guys, does anybody have a good use case of Pact working with `$httpBackend` in Angular.js sounds like it prevents to make real http request in the test environment


matt.fellows
2018-10-24 02:32
That?s a pretty old repo, but the idea is probably the same - you?ll need to ensure there is a real http service injected into your configuration

matt.fellows
2018-10-24 02:32
I haven?t used Angular for a few years, and am out of touch with current practices myself

marco.dellolio
2018-10-24 03:00
For me is brand new, we have a good part of our legacy front end with Angular models serving data to React Components, need to cover those with Pact as well

tom.hombergs
2018-10-24 03:20
@matt.fellows thanks for looking into https://github.com/pact-foundation/pact-js/issues/234 for me! What's the difference between the @pact-foundation/pact-web and @pact-foundation/pact packages anyways?

matt.fellows
2018-10-24 04:05
No worries @tom.hombergs. I don?t have time for the longer version, but the TL;DR is https://github.com/pact-foundation/pact-js/#using-pact-in-non-node-environments

abubics
2018-10-26 05:00
new project, who dis? ``` .../node_modules/@pact-foundation/pact/pact.js:40 this.opts = Pact.createOptionsWithDefaults(config); ^ TypeError: Cannot set property 'opts' of undefined ```

abubics
2018-10-26 05:01
Anyone seen this coming from the `Pact({...})` provider constructor?


abubics
2018-10-26 05:05
ahaha omg . . . missing a `new` keyword :ok_hand::innocent:

matt.fellows
2018-10-26 06:34
Lol

matt.fellows
2018-10-27 05:23
Thanks @tom.hombergs

matt.fellows
2018-10-27 05:23
also, in case you haven?t seen it, your eyeballs on https://github.com/pact-foundation/pact-js/issues/209 and https://github.com/pact-foundation/pact-js/issues/215 would be appreciated. Looking to simplify things whilst also making it more powerful/expressive

mmonson
2018-10-30 20:07
has joined #pact-js

anothonyvong
2018-11-01 21:37
has joined #pact-js

hansrd_98
2018-11-02 01:42
has joined #pact-js

romuald.quantin
2018-11-02 08:12
has joined #pact-js

jeffm
2018-11-02 22:41
has joined #pact-js

jjlehva
2018-11-03 12:37
has joined #pact-js

liran.tal
2018-11-05 12:47
yay

liran.tal
2018-11-05 12:47
mostly passed :slightly_smiling_face:

nic
2018-11-06 09:04
has joined #pact-js

rjmcguinness
2018-11-20 16:00
has joined #pact-js

rjmcguinness
2018-11-20 16:29
Hi everyone. Is the intention of the function in this example https://github.com/pact-foundation/pact-js/blob/d8214e6112f3ba26b93f46bee7fa6f3d8d970f76/karma/jasmine/client.js#L8 to show that we need to implement a method in each service we test with pact to override the environment's api base url? Thanks for any advice you can give

rjmcguinness
2018-11-20 17:06
The below code passes when calling `apiService.createPactClient`. I'd prefer not to have to create a new method in this service just to set localhost as the base url instead of the environment's api base url. However if I try to hardcode the base url + my path in the `karma.conf.js` as proxy key, it can't see the request. Am I doing something wrong? Using Angular 6 + Karma + Jasmine ``` // karma.conf.js module.exports = function (config) { ... pact: [{ consumer: 'ApiService', provider: 'backend', port: 7228, logLevel: 'DEBUG', cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), }], proxies: { '/me': 'http://127.0.0.1:7228/me', }, } ``` ``` // api.service.js import environment from './environment'; // simplified from a Typescript + Angular 6 class class ApiService { // Overwrite the environment base api url createPactClient(baseUrl: string) { environment.apiBaseUrl = baseUrl; } getUser() { const path = '/me'; return HttpClient.get(`${environment.apiBaseUrl}${path}`, new HttpHeaders()); } } ``` ``` // api.service.spec.js import * as Pact from '@pact-foundation/pact-web'; describe('PACT ApiService', () => { let apiService; let provider; const dummyUser = { firstName: 'dummy firstName', lastName: 'dummy lastName', }; beforeAll(done => { provider = new Pact.PactWeb({ port: 7228, host: '127.0.0.1', }); done(); provider.removeInteractions(); // Required for `singleRun: false` }); afterAll(done => { provider.finalize().then(done, e => done.fail(e)); }); beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientModule], providers: [ApiService], }); apiService = TestBed.get(ApiService); }); describe('getUser', () => { beforeAll(done => { provider.addInteraction({ state: 'provider responds with a user', uponReceiving: 'a request to GET a user', withRequest: { method: 'GET', path: `/me`, }, willRespondWith: { status: 200, body: Pact.Matchers.somethingLike(dummyUser), }, }).then(done, e => done.fail(e)); }); afterEach(done => { provider.verify().then(done, e => done.fail(e)); }); it('should get user', done => { // Overwrite the environment api base url apiService.createPactClient('http://localhost:7228'); apiService.getUser().subscribe(response => { expect(response).toEqual(dummyUser); done(); }, e => done.fail(e)); }); }); }); ```

matt.fellows
2018-11-21 05:11
Pretty much, yes. Another standard option is to use Environment variables to inject configuration (in non-Karma use cases probably)

matt.fellows
2018-11-21 05:16
I?m not that familiar with `proxies` in Karma/Angular. Is it possible to have another `environment` configuration for `pact` tests, which contains the endpoint/port required for pact tests? This way it?s consistent with the rest of your code base?

rjmcguinness
2018-11-21 09:23
Thanks I will try to set up another environment for pact, but instead I think it would be for karma as that is what I use to run pact along with my other tests. Perhaps having them run independently makes more sense. I'll work out how to set the environment variable for the base url to localhost when running in karma + pact

borsuk.artem034
2018-11-21 15:35
has joined #pact-js

bernardo.guerreiro
2018-11-23 15:11
Hey everyone. I was wondering if people have had experience using this in integration between frontend and backend (for example a React app and a NodeJS backend)? The reason I'm asking is because I am now working on establishing it between frontend and backend (where I see it can definitely bring a lot of value), but I feel like the "Consumer Driven" part gets a bit lost in some parts, depending on how you do it. I saw a couple of examples of people trying it online, and I guess that's what I want to know - what you think is the best approach: - Approach A: you write your consumer tests on the http client or functions dealing with making the requests, and you just concern yourself with the data being handled properly by the HTTP client; - Approach B: you write actual frontend facing consumer tests on how this data is handled by the UI; So, Approach A is simple to implement and still guarantees that when the provider API makes changes, it doesn't break the frontend (the more common use-case). But Approach B is more "consumer driven" , because if you were to make changes to how you handle or expect the data, it would actually break a consumer build. Which one is best? Is there value in both?

liran.tal
2018-11-23 21:13
@bernardo.guerreiro happy you?re bringing up the subject. A sounds more like by-the-book consumer unit testing. B you can still do but in a form of end-to-end integration tests. Meaning that with B you are actually clicking buttons on the UI and driving flows that trigger API calls, which you can then have a stubbed mock server based on the consumer contracts, to return the results for.

matt.fellows
2018-11-24 15:57
I think b, but not in the form that tests via a UI e2e test. You want to test your service delegate code / collaborator. If it still feels closer to a pure unit test then you're in the sweet spot

matt.fellows
2018-11-24 15:58
Most examples use the http client for convenience/ simplicity

matt.fellows
2018-11-24 15:58
See js issues - one is there about expired being contrived

dagarwal
2018-11-26 12:10
Hey Guys , I am writing a provider verification tests and verification is failing due to difference in actual and expected .I am trying to add matchers and see if it works .I am using method verifyProvider and for that i was used the parameter pactBrokerUrl .I want to know is it possible to verify the provider with my local json file and if yes , how ?

liran.tal
2018-11-26 12:17
@dagarwal sure, you can `pactUrls` instead of `pactBrokerUrl` and include contract files from the local filesystem. an example from the docs: ```js pactUrls: [path.resolve(process.cwd(), "pacts", "myjsmessageconsumer-myjsmessageprovider.json")], ```

dagarwal
2018-11-26 12:17
Wow cool thanks :slightly_smiling_face:

liran.tal
2018-11-26 12:17
:+1:

dagarwal
2018-11-26 12:18
~I am gettign * Expected 8061159 but got 15053699 at $[0].id * Expected ?Country? but got ?address? at $[0].name * Expected ?Country? but got ?Address? at $[0].displayName * Actual array is too short and should have contained 10329 at $[0].visibilityIds[1] * Actual array is too short and should have contained 10323 at $[0].visibilityIds[2] * Actual array is too short and should have contained 10240 at $[0].visibilityIds[3] * Actual array is too short and should have contained 17575 at $[0].visibilityIds[4] * Expected ?31 Jan 2018 11:56:48 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].created * Expected ?01 Feb 2018 11:58:49 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].lastModified * Expected 8078165 but got 15053796 at $[1].id * Expected ?demo-tt? but got ?asdf? at $[1].name * Expected ?Demo tt? but got ?asdf? at $[1].displayName * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].created * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].lastModified * Actual array is too long and should not contain a Hash at $[2] * Actual array is too long and should not contain a Hash at $[3] * Actual array is too long and should not contain a Hash at $[4] * Actual array is too long and should not contain a Hash at $[5] * Actual array is too long and should not contain a Hash at $[6] * Actual array is too long and should not contain a Hash at $[7] and so on when i am doing provider verification~

dagarwal
2018-11-26 12:19
I am getting * Expected 8061159 but got 15053699 at $[0].id * Expected ?Country? but got ?address? at $[0].name * Expected ?Country? but got ?Address? at $[0].displayName * Actual array is too short and should have contained 10329 at $[0].visibilityIds[1] * Actual array is too short and should have contained 10323 at $[0].visibilityIds[2] * Actual array is too short and should have contained 10240 at $[0].visibilityIds[3] * Actual array is too short and should have contained 17575 at $[0].visibilityIds[4] * Expected ?31 Jan 2018 11:56:48 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].created * Expected ?01 Feb 2018 11:58:49 +00:00? but got ?10 Jul 2018 11:04:50 +00:00" at $[0].lastModified * Expected 8078165 but got 15053796 at $[1].id * Expected ?demo-tt? but got ?asdf? at $[1].name * Expected ?Demo tt? but got ?asdf? at $[1].displayName * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].created * Expected ?01 Feb 2018 11:03:59 +00:00? but got ?10 Jul 2018 11:21:20 +00:00" at $[1].lastModified * Actual array is too long and should not contain a Hash at $[2] * Actual array is too long and should not contain a Hash at $[3] * Actual array is too long and should not contain a Hash at $[4] * Actual array is too long and should not contain a Hash at $[5] * Actual array is too long and should not contain a Hash at $[6] * Actual array is too long and should not contain a Hash at $[7] and so on when i am doing provider verification.Even if i add PACT.like it starts to give ?visibilityIds?: [ ... , - Fixnum, - Fixnum, - Fixnum, - Fixnum, + Pact::IndexNotFound, + Pact::IndexNotFound, + Pact::IndexNotFound, + Pact::IndexNotFound, ] }, ... , - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex, - Pact::UnexpectedIndex,

dagarwal
2018-11-26 12:19
Can someone help me with what kind of matchers needs to be added

syed.haq
2018-11-26 14:20
has joined #pact-js

matt.fellows
2018-11-26 16:56
What have you tried? Can you please share? Looks like you need an `eachLike`

dagarwal
2018-11-26 16:56
i tried like

dagarwal
2018-11-26 16:59
will try with each like .Basically provider have big array list like { (arr1,val1), (arr2,val2) , (arr3,val3) and so on and I have added just two values {(arrConsumer1,valConsumer1) ,(arrConsumer2,valConsumer2) )

dagarwal
2018-11-26 16:59
Also values are different

dagarwal
2018-11-27 10:19
Hi , I am getting this error after adding matchers : like while doing verification . 1) Verifying a pact between flex-search-app and flex-taxonomy-service Get object for listing taxonomies with GET /api/taxonomies?accountId=4&enabled=true returns a response which has a matching body Failure/Error: expect(response_body).to match_term expected_response_body, diff_options, example [2018-11-27T10:14:07.150Z] WARN: pact-node@6.20.0/41092 on Dollys-MacBook-Pro.local: Pact exited with code 1. Actual: [{?id?:15053699,?name?:?address?,?displayName?:?Address?,?description?:??,?enabled?:true,?accountId?:4,?visibilityIds?:[4],?userId?:5,?created?:?10 Jul 2018 11:04:50 +00:00?,?lastModified?:?10 Jul 2018 11:04:50 +00:00?},{?id?:15053796,?name?:?asdf?,?displayName?:?asdf?,?description?:??,?enabled?:true,?accountId?:4,?visibilityIds?:[4],?userId?:5,?created?:?10 Jul 2018 11:21:20 +00:00",?lastModified?:?10 Jul 2018 11:21:20 +00:00"}, and so on Its a huge array list at provider level . At At consumer level i have added the test as : before(() => { return provider.addInteraction({ given: ?GET call for taxonomies?, uponReceiving: ?Get object for listing taxonomies?, withRequest: { method: ?GET?, path: ?/api/taxonomies?, query: { accountId: term({ generate: ?4?, matcher: ?4? }), enabled: term({ generate: ?true?, matcher: ?true? }) } }, willRespondWith: { status: 200, body: [ like ({ ?id?: like(8061159), ?name?: like(?Country?), ?displayName?: like(?Country?), ?description?: like(??), ?enabled?: like(true), ?accountId?: like(4), ?visibilityIds?: like([ 4, 10329, 10323, 10240, 17575 ]), ?userId?: like(5), ?created?: like(?31 Jan 2018 11:56:48 +00:00?), ?lastModified?: like(?01 Feb 2018 11:58:49 +00:00?) }) ] } }); });

liran.tal
2018-11-27 10:24
@dagarwal it?s really hard to help with partial output. if you don?t have the code publicly available to look at, can you paste the full output of the pact test failure on some place like pastebin and provide a link?

dagarwal
2018-11-27 10:24
Ok sure would do that




liran.tal
2018-11-27 10:38
I can point out several things that look a bit off. on the consumer side - 1. the term matchers on the query doesn?t look like they?re used properly. the matcher is supposed to be a regex syntax 2. the matching for dates is not going to really work the way you think, it?ll just match any string type, not the actual date format you see there now. 3. the visibility ids are using hard coded items

dagarwal
2018-11-27 10:39
cool , let me try updating these and see if it works Thanks !!

liran.tal
2018-11-27 10:39
I suggest that you try to build the contract and verify it step-by-step. it will be easier for you to debug what?s wrong and why it fails

liran.tal
2018-11-27 10:40
if you add many matchers and expectations on the consumer side and something fails on the provider, it?s hard to debug why exactly.

liran.tal
2018-11-27 10:40
I mean, the log is there to help you but if you?re starting out fresh you might want to take it in steps

dagarwal
2018-11-27 10:41
Actually we built in huge tests at consumer level and data has got complex .now we are doing provider verification :disappointed: should have done it from initial stage .I am really struggling now

matt.fellows
2018-11-27 17:46
I can see the problem

matt.fellows
2018-11-27 17:46
when using array matchers, you need to remove the actual array within/ouotside

matt.fellows
2018-11-27 17:46
e.g.

matt.fellows
2018-11-27 17:47
`body: eachLike({?})` not `body: [ like({...}) ]`

matt.fellows
2018-11-27 17:47
or `body: eachLike({?})` not `body: eachLike([{...}])`

matt.fellows
2018-11-27 17:47
`eachLike` implies it?s an array

matt.fellows
2018-11-27 17:48
so pact is expecting an array containing an array

matt.fellows
2018-11-27 17:53
I?ve answered your question on SO also

dagarwal
2018-11-28 08:36
Thanks a lot :dancer: it worked

rjmcguinness
2018-11-28 17:01
Hi, Are there are any recommended ways to automate pact test creation (in my case for an Angular 7 webapp)? Preferably generating tests off an (api) service


rjmcguinness
2018-11-28 17:31
Thanks. We have an api service which is rapidly expanding and are looking for a sustainable way to expand our pact tests without copy and pasting chunks of `describe('...` Really trying to decide where the source of truth is, and how to minimise mistakes in the pact tests

matt.fellows
2018-11-28 17:32
gotcha

matt.fellows
2018-11-28 17:33
great!

matt.fellows
2018-11-28 17:34
Don?t forget to accept the answer :wink:

matt.fellows
2018-11-28 17:35
The key thing is that each test needs to capture the intentions of the consumer, not what is documented in a provider.

matt.fellows
2018-11-28 17:37
It might be possible to automate it, but you?re likely to add in assumptions that your client code is doing that may be incorrect and therefore void all of the pact work

rjmcguinness
2018-11-29 09:22
Understood. Thanks. I think we won't be automating this now.

matt.fellows
2018-11-29 16:38
@dagarwal can you please share what you expect your API response to look like to help you with your matchers?

matt.fellows
2018-11-29 16:39
I suspect you want an object which contains array items (taxon's), not an array of items which always have arrays nested within

matt.fellows
2018-11-29 16:39
This is why it's telling you it's expecting an array, but got a hash

matt.fellows
2018-11-29 16:41
The eachLike matcher says at the location specified, it expects an array

kamilmarkow
2018-11-29 16:57
has joined #pact-js

dagarwal
2018-12-03 09:07
@matt.fellows Yes exactly . It contains array items in taxons . Please find link : https://pastebin.com/2SJnTrfG

matt.fellows
2018-12-03 10:01
So if the root reflect is not an array, reminder the eachlike matcher on it, but leave it for taxons

sai.krishna
2018-12-03 14:34
has joined #pact-js

dagarwal
2018-12-03 15:11
reminder the eachlike matcher on it, means .I dint get it :disappointed:

matt.fellows
2018-12-03 21:18
I?ve updated the example in SO. I think you want this: ``` const firstChild = like({ ?name?: ?Geo?, ?taxons?: eachLike({ ?id?: 115590, ?name?: ?Africa?, ?hasChildren?: false }) }); `` Note that the initial `eachLike` is now just `like`. This means you don?t expect an array at the root of the response, you want an object.

nic
2018-12-04 12:28
~hey pact people, has anyone got an example of updating the provider on a test by test basis for jest? my consumer has contracts with multiple providers so I need to update the provider on a test by test basis to create multiple pacts. I don't think I've seen an example of doing this in JS - i might have missed it. any pointers gratefully received!~

dagarwal
2018-12-04 14:34
Thanks @matt.fellows :slightly_smiling_face:

dagarwal
2018-12-04 14:34
i want to use more than one element in array. I am using eachLike with min .Can you guys tell me whats wrong here : const taxonomiesList = [{ ?id?: 8061159, ?name?: ?Country?, ?displayName?: ?Country?, ?description?: ??, ?enabled?: true, ?accountId?: 4, ?visibilityIds?: like[4], ?userId?: 5, ?created?: ?31 Jan 2018 11:56:48 +00:00?, ?lastModified?: ?01 Feb 2018 11:58:49 +00:00? }, { ?id?: 8078165, ?name?: ?demo-tt?, ?displayName?: ?Demo tt?, ?description?: ??, ?enabled?: true, ?accountId?: 4, ?visibilityIds?: like[4], ?userId?: 5, ?created?: ?01 Feb 2018 11:03:59 +00:00?, ?lastModified?: ?01 Feb 2018 11:03:59 +00:00? ]) const taxonomies = eachLike(taxonomiesList, { min: 2}); module.exports = { taxonomies }; But this is generating both id ( inside body ) two times ( so total 4) in the json file

matt.fellows
2018-12-04 20:25
All good. Did that help you understand how it works?

yousafn
2018-12-04 22:06
has joined #pact-js

dagarwal
2018-12-05 08:31
yes but still I am unable to create data for more than one element in array using eachLike and min

matt.fellows
2018-12-05 10:51
If you need further help, we'll need a code base where we can reproduce the problem your having exactly

dagarwal
2018-12-05 11:28
Okay

matt.fellows
2018-12-05 19:08
Thanks

matt.fellows
2018-12-06 23:05
@dagarwal I?ve mentioned this a few times - _do not_ put an array `[]` inside of the `eachLike` statement for what you are trying to do to. It is trying to create a multi-dimensional array. You want a single dimension array, so simply put _one_ object inside the `eachLike` clause e.g. ``` eachLike({ 'id': 8061159, 'name': 'Country', 'displayName': 'Country', 'description': '', 'enabled': true, 'accountId': 4, 'visibilityIds': like[4], 'userId': 5, 'created': '31 Jan 2018 11:56:48 +00:00', 'lastModified': '01 Feb 2018 11:58:49 +00:00' }) ```

rjmcguinness
2018-12-12 10:09
Hi Matt and all, Could you explain this setTimeout to me please? https://github.com/pact-foundation/pact-js/blob/master/karma/jasmine/client-spec.js#L16 I had intermittently failing tests yesterday (only in our CI build - in docker on VSTS, and very occasionally locally) and putting `done()` into the setTimeout in that beforeAll for each test fixed it. Still can?t work out which interaction clearing this is delaying. Is this preventing tests from clearing each other?s interactions? Or is it preventing one of the below lines from clearing the test?s own interactions before the request is received? `provider.removeInteractions();` `provider.finalize().then(done, e => done.fail(e));` `provider.verify().then(done, e => done.fail(e));` In this failing test we can see the interaction was registered, then cleared and then request was received (so no request was found). ``` I, [2018-12-11T16:32:35.619070 #5595] INFO -- : Registered expected interaction GET /my/stuff D, [2018-12-11T16:32:35.619242 #5595] DEBUG -- : { "description": "a request to GET stuff", "providerState": "provider responds with snapshot ref data", "request": { "method": "GET", "path": "/my/stuff" }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "json_class": "Pact::SomethingLike", "contents": { "0": { "stuff": "dummy stuff", } } } } } I, [2018-12-11T16:32:35.620329 #5595] INFO -- : Cleared interactions I, [2018-12-11T16:32:35.653797 #5595] INFO -- : Received request GET /my/stuff ```

rjmcguinness
2018-12-12 10:40
? then this line triggers the fail ``` E, [2018-12-11T16:32:35.653947 #5595] ERROR -- : No matching interaction found for GET /my/rates-evidence ```

dagarwal
2018-12-12 11:51
yes @matt.fellows thanks

matt.fellows
2018-12-12 20:51
It's a bit of a hack. Its basically saying "wait for 2 seconds and hope the pact mock server is up in time on port 1234

matt.fellows
2018-12-12 20:51
A better way would be to wait for the port to be ready

matt.fellows
2018-12-12 20:51
Is this test failing or one of yours? If you share the code I'm happy to take a look

rjmcguinness
2018-12-13 09:25
I had random failures on my CI build only across all tests until I put the done in a setTimeout. All tests are consistently passing now, but adds +2s for each test. What I?m trying to understand is which line is doing the ?Cleared interactions? in between registering interaction and receiving request. From looking at pact-web.js, could be one of three provider methods (mentioned above). Line 28, 32 or 70 in below gist. Here?s the gist, thanks :slightly_smiling_face: https://gist.github.com/rorymcgit/819f1a3eb697c864fcf47c9e6f8f5fe2

matt.fellows
2018-12-13 09:29
removeInteractions, finalise and verify will all clear them from memory

rjmcguinness
2018-12-13 09:44
Do you know which one of these is causing the ?Cleared interactions? in this case, i.e. if the `done()` on line 25 is not in a setTimeout?

matt.fellows
2018-12-13 11:29
hmm not at a cursory glance i?m sorry. If you had your code to share i?m haappy to look at that too


matt.fellows
2018-12-13 20:37
Hmm the provider removeInteractions in the before all is a promise. Stricly speaking you might want to properly handle it even tho the setTimeout above should prevent it.

matt.fellows
2018-12-13 20:37
Are there any strange Jasmine overlapping behaviours causing strangeness?

rjmcguinness
2018-12-14 10:51
I found that everything ran in the order it should have run (by putting a load of numbered console.logs throughout the code), even for failing tests. That?s interesting that `removeInteractions` isn?t really being handled properly. I might try moving the done from inside the setTimeout to in a `.then`. Thanks for your help - I?ll update you if I find anything interesting

rjmcguinness
2018-12-19 10:08
@matt.fellows I said I?d update if I found anything interesting, and I think I have. https://gist.github.com/rorymcgit/cf7cc8f07c20507f699900f8484435c1#file-api-service-get-foo-pact_v2-spec-ts-L23 Moving the `done()` to happen on resolve of the `removeInteractions` means my CI build does not have pact tests failing intermittently (like it was without being wrapped by the setTimeout) and does not add 2 seconds per test either.

matt.fellows
2018-12-19 23:31
Thanks @rjmcguinness - makes sense!

davegallant
2019-01-02 17:18
has joined #pact-js

dagarwal
2019-01-02 17:28
Hello , Do we have any npm package to install can-i-deploy ?

mboudreau
2019-01-02 23:11
Sorry, I haven't gotten around to enabling that in pact-node yet :confused:

dagarwal
2019-01-03 08:44
@mboudreau Ok thanks .It would be good to have it

dagarwal
2019-01-03 08:45
One more question so to implement in this jenkins , i need to run the command to install it .any other way ? @mboudreau

mboudreau
2019-01-03 08:51
Well, when you use npm, it does install the Ruby binary, so you could hit it directly with the command. There's already a pull request for this change, I just need to spend some time to add it. Could you allow me a day to look the pr over and merge it and release a new version?

dagarwal
2019-01-03 08:52
wow that would be great , Sure .Please let me know when done :slightly_smiling_face:

jdesouza
2019-01-03 13:08
has joined #pact-js

matt.fellows
2019-01-03 22:20
Also if you haven't seen this, take a look


matt.fellows
2019-01-03 22:21
Examples of using the binaries from package.json

matt.fellows
2019-01-03 22:21
Once properly installed into the path it should he even easier

mboudreau
2019-01-04 06:09
@dagarwal I've updated pact-node to include `can-i-deploy`, version 6.21.0

matt.fellows
2019-01-04 06:58
:clap:

dagarwal
2019-01-04 10:18
wow thanks @mboudreau :slightly_smiling_face:

dagarwal
2019-01-04 10:28
Thanks Matt its good , i havent checked that link before

dagarwal
2019-01-04 10:44
@mboudreau Latest version for that is 6.20.2 as of now


dagarwal
2019-01-04 10:53
It gave me this ? Please choose a version of ?@pact-foundation/pact-node? from this list: (Use arrow keys) ? 6.20.2 6.20.1 6.20.0 6.19.12

mboudreau
2019-01-04 10:53
just update your package.json file to use 6.21.0 and do an `npm install`

dagarwal
2019-01-04 10:54
yeah it worked with that .I updated package and file and was doing yarn install and getting error

dagarwal
2019-01-04 10:54
Thanks

mboudreau
2019-01-04 11:04
must have been some caching or something

dagarwal
2019-01-04 11:04
yeah right

yousafn
2019-01-04 11:12
great work @mboudreau , I use pact-node and we were previously using the can-i-deploy standalone, so nice to have this option now :ok_hand:

mboudreau
2019-01-04 11:36
thanks :slightly_smiling_face:

mboudreau
2019-01-04 11:37
it was mostly @tjones doing the work, I just supervised :stuck_out_tongue:

dagarwal
2019-01-04 13:28
Thanks to @tjones too for the efforts :slightly_smiling_face:

dagarwal
2019-01-04 14:05
Hello @mboudreau @tjones thanks for can-i-deploy functionality .but it fails when we do can i deploy because in can-deploy.js file this.__argMapping , we are passing ?version?: ?--version?, but in the function we are using options.pacticipantVersion =options.pacticipantVersion instead of options.pacticipantVersion =options.version .I tried replacing the variables and it works fine .Please fix it . Do let me know if you want any further information .Thanks

mboudreau
2019-01-04 14:20
crap, sorry, you're right

dagarwal
2019-01-04 14:21
np .Please let me know once the update is ready :slightly_smiling_face:

mboudreau
2019-01-04 14:22
I'll do it now

dagarwal
2019-01-04 14:23
Perfect

mboudreau
2019-01-04 14:59
6.21.1 is building now, should be available in about 10 minutes

mboudreau
2019-01-05 08:22
Did this version work @dagarwal?

ilya.markevich1991
2019-01-05 21:07
has joined #pact-js

dagarwal
2019-01-06 15:36
no @mboudreau it is giving me same error

cdaly
2019-01-07 18:59
has joined #pact-js

dagarwal
2019-01-08 10:10
could you Please check @mboudreau

mboudreau
2019-01-08 10:11
whoops, didn't see this

mboudreau
2019-01-08 10:12
I'll get it done now

dagarwal
2019-01-08 10:12
Okay thanks

mboudreau
2019-01-08 10:52
wait, how are you calling can-i-deploy? can you give me an example of the command you use?

dagarwal
2019-01-08 10:54
yes I am doing like this

dagarwal
2019-01-08 10:54
const pactNode = require('@pact-foundation/pact-node'); const checkVerificationForProvider = { pacticipant: [Pacticpant1], version: ['1.0.0'], pactBroker: 'https://pact.ooflex.net/' }; pactNode.canDeploy(checkVerificationForProvider).then(() => { console.log("Verified can i deploy against Provider?); }).catch(err => { console.error("Verification failed for can i deploy Provider service", err); });

mboudreau
2019-01-08 10:55
can you change "version" for "pacticipantVersion" as see if it works?

dagarwal
2019-01-08 10:55
ok let me try

dagarwal
2019-01-08 10:57
The version must be specified using --version or --latest [TAG] for pacticipant flex-taxonomy-service Verification failed for can i deploy against flex taxonomy service Error: The version must be specified using --version or --latest

dagarwal
2019-01-08 10:57
i get this @mboudreau

mboudreau
2019-01-08 10:58
ah, yeah, I see it now

dagarwal
2019-01-08 10:58
i guess here we need to pass version only as in the internal code you are using it as pacticipactVersion

mboudreau
2019-01-08 10:59
the pact binary uses --version but I can't with the CLI in node since it messes up the CLI and thing --version is for the project version

mboudreau
2019-01-08 10:59
hence why I'm trying to use pacticipantVersion since it's also more descriptive

dagarwal
2019-01-08 10:59
okay so will you be changing the code accordingly ?

mboudreau
2019-01-08 10:59
yep, gimme a moment

dagarwal
2019-01-08 11:00
Sure ,thanks

mboudreau
2019-01-08 11:46
there's some tests missing here to make sure this doesn't break again. I'm going to release a quick fix for now, but I'll need to invest more time in the tests so that it won't ever break again :slightly_smiling_face:

dagarwal
2019-01-08 11:47
Sounds good :slightly_smiling_face:

mboudreau
2019-01-08 12:28
you going to be around in the next 10 minutes to make sure it works?

dagarwal
2019-01-08 12:29
Okay

mboudreau
2019-01-08 12:29
cool, sending it off for deployment, I'll let you know when it's up so you can confirm it works on your end and finish this for good :slightly_smiling_face:

dagarwal
2019-01-08 12:30
sure

mboudreau
2019-01-08 13:00
6.21.2 is out, please try it now :slightly_smiling_face:

mboudreau
2019-01-08 13:07
@dagarwal?

dagarwal
2019-01-08 13:07
yes trying

dagarwal
2019-01-08 13:09
it works :slightly_smiling_face: thanks @mboudreau

mboudreau
2019-01-08 13:10
woo!

mboudreau
2019-01-08 13:10
np, thanks for being patient :slightly_smiling_face:

rjmcguinness
2019-01-08 15:29
Hi Matt and all, Using Karma/Jasmine/Angular 7/Typescript with karma-pact, pact-node, pact-web. I have added the eachLike matcher to my tests but have run into a problem with my Jasmine text expectations. The Jasmine test is failing here https://gist.github.com/rorymcgit/7858c2e82f4d70341072d981dc70b54b#file-failing-eachlike-api-service-get-foo-pact-spec-ts-L62 because I have changed the body of the object to include the eachLike matcher. Previously in my `provider.addInteraction` I had: ``` willRespondWith: { status: 200, body: Matchers.somethingLike({ foo: [{ bar: ['a string'], }, { bar: ['another string'], }], }), } ``` Which meant I could `expect(response).toEqual(sameObjectAsWasPassedToBody)`. The only difference being wrapping it in a `somethingLike` above. Now I have: ``` willRespondWith: { status: 200, body: { foo: Matchers.eachLike({ bar: ['a string'], }), }, } ``` So I have to assert that the response is equal to a different object than what I have assigned to the `body` in the interaction. https://gist.github.com/rorymcgit/0bb82714b2de91fde8769b4acd668c2f#file-passing-eachlike-api-service-get-foo-pact-spec-ts-L68 My question is: What is the value of a Jasmine test in our Pact test, if all we are testing anyway is what has been passed into the `body`? We are not testing api method (as it is stubbed by the Pact provider service). The value of Pact from a consumer side is to generate the Pact and test our requests.

rjmcguinness
2019-01-08 16:03
I am tempted to remove the expectation and just `provider.verify()`

tjones
2019-01-09 03:54
The point of `expect` in a pact test like this is to be able to ensure that the correct domain object is returning to the caller of `getFoo()`. In Javascript, that is often (but not always) the same object that's on the wire

tjones
2019-01-09 03:54
if you're just returning the wire object without transformation, you could safely remove the expectation in your test

tjones
2019-01-09 03:56
However, what I like to do instead is to have a file of fixtures that describe the domain objects. This file is shared between the pact test's `expect` line, and the tests for the call site of `getFoo()`.

tjones
2019-01-09 03:58
This means that we can be sure that the callers of `getFoo()` and the pact between your foo client and provider are in sync

tjones
2019-01-09 03:58
With typescript, you probably don't need to do this

tjones
2019-01-09 04:05
without that `expect` call, you're missing out on: 1) Does the api method return the object? (guarding against misuse of the response in your `getFoo()`, eg returning `response` instead of `response.body`) With shared fixtures, or careful typescript types, you also get: 2) Does the api method return the same object that the caller expects?

matt.fellows
2019-01-09 04:07
:point_up: this

rjmcguinness
2019-01-10 09:48
Thanks for this, that?s very clear. I?ll keep the expectation and find a way to share the objects. Do you have any thoughts on programatically adding `eachLike`s? i.e. adding a test helper method that iterates over the object and replaces arrays with `eachLike(array[0])`.

tiago.ferrazmartins
2019-01-10 14:33
has joined #pact-js

tiago.ferrazmartins
2019-01-10 14:43
Have anyone done this before?


tjones
2019-01-14 06:13
I personally wouldn't do that, because the domain object (returned by the call site of your API) is a different object conceptually to the wire object (tested by pact verification), so I prefer them to be separate objects in code, even if they're very similar/the same. However, I don't think it's wrong to try it - If you prefer no duplication, then a helper like you suggest seems like the way to go. I'd be interested to know how you like it after a few months of use.

vicenzo
2019-01-28 22:03
has joined #pact-js

vicenzo
2019-01-28 22:05
Hello,

vicenzo
2019-01-28 22:05
can someone help me understand how the pact term works?

vicenzo
2019-01-28 22:05
i currently have a few done on my poc but when verifying i have no match done

vicenzo
2019-01-28 22:06
mocha is complaining about it

matt.fellows
2019-01-28 22:15
what have you tried so far?

matt.fellows
2019-01-28 22:15
It?s a regex matcher, which must correspond to the Ruby regex format. There are examples in the repo worth looking at first

matt.fellows
2019-01-28 22:16
Why would mocha care about the matcher? can you please elaborate?

vicenzo
2019-01-28 22:16
so I am validation iso8601DateTime

vicenzo
2019-01-28 22:17
the default regex available on the DSL works when using a web based validator

vicenzo
2019-01-28 22:17
but not when I do it on the pact

vicenzo
2019-01-28 22:18
the generate is being hard matched with the expected response

vicenzo
2019-01-28 22:18
I haven?t done the provider side yet I am starting at the consumer

vicenzo
2019-01-28 22:19
for example: ``` state: term({ matcher: 'ReviewPending|Approved|FundsPosted|SentToBank|Completed|RejectedFundsNotPosted|RejectedFundsNotSentToBank|RejectedUnapproved|RejectedValidationFailed|SendToBankFailed|FundsReturned|Postponed|Canceled', generate: 'Postponed', }),```

vicenzo
2019-01-28 22:19
the response from the provider will include any of those states

vicenzo
2019-01-28 22:20
``` transferTime: like('2018-12-18T21:21:28.619Z'), ```

vicenzo
2019-01-28 22:20
or different timestamps

matt.fellows
2019-01-28 22:27
What do you mean hard matched on the response? This doesn't make sense if your doing a consumer test.

matt.fellows
2019-01-28 22:27
Are you matching a response or a request?

matt.fellows
2019-01-28 22:28
Which one isn't working? The time or the other?

vicenzo
2019-01-28 22:34
``` interaction = { state: 'I have a list of transfer', uponReceiving: 'a request for all transfers', withRequest: { method: 'GET', query: 'page_size=5000', path: '/', }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: noFilter, } };``` `noFilter` has the Matchers ``` it('returns the correct response', async() => { await searchRequest().then((response) => { expect(response).to.eql(SEARCH_RESPONSE); }) });``` `SEARCH_RESPONSE` has a static JSON at the moment

matt.fellows
2019-01-28 23:06
What are you expecting to happen here? I expect `response` to have the values `2018-12-18T21:21:28.619Z` and `Postponed` in it

matt.fellows
2019-01-28 23:07
What?s the actual problem?

matt.fellows
2019-01-28 23:08
So this is a consumer test, any `generate` value provided to the `term` matcher will be what comes back from the mock service. Later on during provider verification, it will check what the provider actually responds with, and will use the `matcher` portion of the test to ensure it is what is expected

vicenzo
2019-01-28 23:17
Then why is that the SEARCH_RESPONSE (which is a copy json of the response of the provider) failing?

mboudreau
2019-01-28 23:19
@vicenzo are you sure that `.to.eql` is a deep equal? I thought it was a simple reference check just like `===` which won't work since the response is not the same object as the SEARCH_RESPONSE

mboudreau
2019-01-28 23:19
look to see if it has a `.to.deep.eql` instead

vicenzo
2019-01-28 23:19
the assertion error message is the same

vicenzo
2019-01-28 23:19
`AssertionError: expected { Object (pageCursorId, evaluatedTransfers) } to deeply equal { Object (pageCursorId, evaluatedTransfers) } <Click to see difference>`

mboudreau
2019-01-28 23:20
what's the difference?

tjones
2019-01-28 23:21
can you share the definitions of `noFilter` and `SEARCH_RESPONSE`?

vicenzo
2019-01-28 23:21
let me get a gist wipped up

tjones
2019-01-28 23:22
if it's chai, then I believe `eql` is the deep equal. `equals` is the reference check.

mboudreau
2019-01-28 23:23
wait, you're calling your API to return something that's auto generated?

tjones
2019-01-28 23:24
@vicenzo - are you hitting the pact mock server with this consumer test, or your real API?


vicenzo
2019-01-28 23:32
mock server @tjones

vicenzo
2019-01-28 23:32
```const provider = new Pact({ consumer: 'sentinel-ui', provider: 'sentinel-judge', host: 'localhost', port: MOCK_SERVER_PORT, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', logLevel: 'info', });```

vicenzo
2019-01-28 23:33
`searchRequest()` uses window to define the URL, I am just overriding the window global to point to the mock

vicenzo
2019-01-28 23:37
You are correct on that one

mboudreau
2019-01-28 23:51
why are you using term matchers for your response?

mboudreau
2019-01-28 23:52
I mean, it's fine, but then you have the SEARCH_RESPONSE which is static and then completely different from your interaction

mboudreau
2019-01-28 23:52
and you expect it to be the same

mboudreau
2019-01-28 23:53
which I don't really understand why you're doing this in the first place

vicenzo
2019-01-28 23:54
so maybe I am missing the point completely of how to write these tests

vicenzo
2019-01-28 23:54
I can flip the script

vicenzo
2019-01-28 23:54
would that fix it?

vicenzo
2019-01-28 23:55
oh right that was why

vicenzo
2019-01-28 23:55
when I use the matchers on the expect I get the pact json

vicenzo
2019-01-28 23:55
before it is run through the ruby cli

mboudreau
2019-01-28 23:58
well, I'm not sure why you're testing the response at all, it's kind of what pact does for you. All you want to do is make sure you test your API correctly and it's processing things correctly, and that the incoming body/query (not the response) has matchers so that the interactions are correct

mboudreau
2019-01-28 23:59
so, for instance, you have a `page_size` query with 5000, maybe you want to use a term for that so that it's always a number, and it can't be lower than X or higher than Y, then have tests to make sure that these limits are working with pact and your API

vicenzo
2019-01-29 00:00
I see

mboudreau
2019-01-29 00:00
or that another endpoint is a post and it expects a body of type Z with property blah of type something, but the response is always going to be the same thing

vicenzo
2019-01-29 00:00
this test is a bust basically because it doesn?t have the matcher on the request itself

vicenzo
2019-01-29 00:01
because it is the consumer

vicenzo
2019-01-29 00:01
if it was the provider than it would make sense to have the response matchers

mboudreau
2019-01-29 00:01
well, I wouldn't say it's a bust, you want a test to make sure that this interaction exists and it returns something, and that your consumer can parse the response and interact with it


vicenzo
2019-01-29 00:01
that was the point of this particular one

mboudreau
2019-01-29 00:02
but with the matchers and the like, not so much

mboudreau
2019-01-29 00:02
you don't need the matchers for the response

vicenzo
2019-01-29 00:02
``` willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: SEARCH_RESPONSE, } };```

vicenzo
2019-01-29 00:02
so here should be like that

vicenzo
2019-01-29 00:02
and the expect should be that the response.eql(SEARCH_RESPONSE)

vicenzo
2019-01-29 00:02
something like that?

mboudreau
2019-01-29 00:03
yes

mboudreau
2019-01-29 00:03
however, making sure that response equals response is a bit redundant

mboudreau
2019-01-29 00:03
maybe there's something in your consumer you want to test to make sure that this triggers and returns, then displays correctly?

mboudreau
2019-01-29 00:04
the point of your consumer test is to test the consumer, including the interaction with the API

mboudreau
2019-01-29 00:04
so, what's the function that calls this particular API endpoint? that's what you want to test

vicenzo
2019-01-29 00:04
`searchRequest()`

vicenzo
2019-01-29 00:04
this one

vicenzo
2019-01-29 00:05
```export function searchRequest(params) { const query = parseSearchQueryParams(params); return requests.get(`${URL(getAppConfigSetting('apiUrl'))}?${query}`); }```

mboudreau
2019-01-29 00:05
and it doesn't take any arguments or return anything?

mboudreau
2019-01-29 00:05
okay, that's better

mboudreau
2019-01-29 00:05
so, plenty of tests that can be done here based on the params

mboudreau
2019-01-29 00:05
see if the response fails, what does it do when it fails, what does it do when it succeeds, etc


vicenzo
2019-01-29 00:06
I see

mboudreau
2019-01-29 00:06
you can make it more complex as well if it's suppose to show something on the screen or update a state somewhere

vicenzo
2019-01-29 00:06
not this one

mboudreau
2019-01-29 00:06
ie. whatever in your consumer that calls `searchRequests`

vicenzo
2019-01-29 00:07
could I use pact to mock the api during a ui test?

mboudreau
2019-01-29 00:07
you sure can :slightly_smiling_face:

vicenzo
2019-01-29 00:07
:shocked_face_with_exploding_head:

mboudreau
2019-01-29 00:08
you can make it as minute as a test (unit tests, single function) or much wider and complex (e2e, ui)

mboudreau
2019-01-29 00:08
with state or multiple states

vicenzo
2019-01-29 00:11
right now I am just trying to get a POC done for consumer and provider

vicenzo
2019-01-29 00:11
maybe I should move to the provider and see if I can break the contract

vicenzo
2019-01-29 00:12
you?ll be seeing more of me soon =P

vicenzo
2019-01-29 00:12
thank you for the help and lesson!

mboudreau
2019-01-29 00:13
np :slightly_smiling_face:

vicenzo
2019-01-29 00:15
now back to the company network where I can;t send messages

dagarwal
2019-01-29 12:04
Hello guys , when i add pact matching with term here on path withRequest: { method: ?GET?, path: term({ matcher: ?/api/assets/[0-9]+?, generate: ?/api/assets/10006? }), }, ( I am getting 404 when i try to load the data on UI :disappointed: ) .Without adding matcher it just works fine for me . Any suggestions on what went wrong and how to achieve it ?

vitaliy.grigoruk
2019-01-30 20:05
has joined #pact-js

vitaliy.grigoruk
2019-01-30 20:08
Hey folks! Does pact-js has a full support for pact-specification v3 (https://github.com/pact-foundation/pact-specification/tree/version-3)? I'm wondering how can I specify providerStates as an array in my JS code instead of a single string.

matt.fellows
2019-01-30 20:18
@vitaliy.grigoruk no it doesn?t support all of v3, just the bits required to allow message pacts to work. So it?s v 2.x compatible you might say

vitaliy.grigoruk
2019-01-30 20:26
does anything speaks against adding support for providerStates then? I may contribute with a PR.

rafael.anachoreta
2019-02-01 13:46
has joined #pact-js

rafael.anachoreta
2019-02-01 13:57
hey! I'm trying to validate my Pact, but my consumer uses fetch and when I run it through node that fails :confused: (fetch is not defined, etc) any pointers on how I could solve it?

matt.fellows
2019-02-01 22:00
You could swap out the engine for something else (e.g. super agent) during test

matt.fellows
2019-02-01 22:01
Another option is to use the pact-web dependency which runs in browser test environments

matt.fellows
2019-02-01 22:01
There are examples in the repo of karma / Jasmine tests

abubics
2019-02-02 00:00
Or `isomorphic-fetch`?

matt.fellows
2019-02-02 00:01
Yep. I'd look to replace fetch as the simpler option. Pact is the easier library to deal with than pact web

rafael.anachoreta
2019-02-04 08:10
awesome, thanks for the responses. I was skeptical at first thinking this would mean replacing the actual behavior of my consumer, but looks like that isn?t the case

rafael.anachoreta
2019-02-04 15:01
another one: is there any matcher that would help with a return that can be a string or an object? ``` { target: "2019" } ``` or ``` { target: { value: 1000 } } ```

rafael.anachoreta
2019-02-04 15:02
my first idea was to use the term regex, but I figured that won?t work for objects

rafael.anachoreta
2019-02-04 15:02
p.s.: I realize that is probably not the best API design there can be, but it is what I must use :disappointed:

tomw
2019-02-04 17:23
has joined #pact-js

matt.fellows
2019-02-04 20:15
There is no single matcher that would do that. You would write (at least) two separate tests to ensure that it?s covered. You may use a provider state to document in which state the provider should be in too return either of the two formats (assuming it?s a similar looking requests that produces the two different shapes)

rafael.anachoreta
2019-02-05 08:16
thanks Matt, that helped :slightly_smiling_face:

karishnu
2019-02-05 11:06
has joined #pact-js

rafael.anachoreta
2019-02-05 14:33
okay hopefully my last question :slightly_smiling_face: I have my pact file ready but when I try to validate it against my provider, it fails. That happens because our infra has a proxy in place that changes the endpoints of the provider. Consumer: ``` GET local/api/zoo/animals ``` Provider: ``` GET local/zoo/animals ``` How can I handle this scenario? I?ve tried changing the host to use the /api (`localhost/api`) but that made my consumer tests fail :thinking_face:

rafael.anachoreta
2019-02-05 14:35
another thing to note is that the paths could be completely different depending on how it was set up (though that is less like)

matt.fellows
2019-02-05 19:44
Is it always consistently this new path? Or just in test or something?

rafael.anachoreta
2019-02-06 08:32
yes, it is consistent. We have explicit rules to route one thing to the other, but the consumer / provider don?t know about them :confused:

matt.fellows
2019-02-06 09:18
How/why do the consumer tests fail? Surely it's just a config item that sets the host and context path

rafael.anachoreta
2019-02-06 10:19
Sadly not a config file on either end. We have HAProxy set up doing the routing between the provider?s endpoint to something else entirely (in this case, adding /api/). The consumer (correctly) sends its requests to `/api/zoo/animals` and when the contract?s path is set to `/api/zoo/animals` the mock server is able to receive the request. With the same path, however, I?m unable to verify the provider is receiving the data from the mock server as requests are now being sent to `/api/zoo/animals` instead of `/zoo/animals` (as the provider expects). does that make sense?

matt.fellows
2019-02-06 13:14
Yes it does, I'm mostly confused as to how you can't modify the path the consumer uses during these tests. This is most bizarre. Can you explain why?

matt.fellows
2019-02-06 13:15
It's common. Some people will just test the apt with the proxy in front of it, some will remove it from the equation (there is commentary on our side Wendie about this).

rafael.anachoreta
2019-02-06 13:24
> Yes it does, I?m mostly confused as to how you can?t modify the path the consumer uses during these tests. This is most bizarre. Can you explain why? I?m not sure I follow. Do you mean implement a configuration system of sorts that changes the basepath in the implementation? Or by setting the path = ?/api/?? using Pact? this is the part (I think?) I shouldn?t change or it breaks the provider: ``` // in provider.addInteractions() withRequest: { method: "GET", path: "/zoo/animals", headers: { Accept: "*/*", }, }, ```

dagarwal
2019-02-06 15:17
how do we fail the build when can i deploy method is invoked and if verification was failed at provider side as we don?t return any exit code from the method ( can-deploy.js)?

dagarwal
2019-02-06 15:18
@mboudreau @matt.fellows

rafael.anachoreta
2019-02-06 16:18
I feel like I?m missing something important that would trivialize this, but I can?t figure out what :cold_sweat:

matt.fellows
2019-02-06 22:12
I haven't seen the API for can I deploy in JS yet so can't comment I'm afraid

matt.fellows
2019-02-06 22:16
Sure. So usually you have an http client that is configurable. When you setup your consumer application, you probably have to give it some information. Like where to find its provider (http url and path). Sometimes you can configure this with environment variables (e.g. `const providerBaseUrl = process.env.MY_PROVIDER_API = 'http://foo.com/path/to/api'`)

mboudreau
2019-02-06 22:25
@dagarwal is this for pact-node?

mboudreau
2019-02-06 22:25
because I'm fairly sure the pact-node version throws an error

matt.fellows
2019-02-06 22:46
Sounds about right to me. Can you programmatically detect which contract failed?

mboudreau
2019-02-06 22:47
hm, that I do not know. My gut says no, it just does the exit code but no extra data

mboudreau
2019-02-06 22:47
that sounds like a great feature to have though

mboudreau
2019-02-06 22:47
not sure how feasible it is with the current ruby binary however

matt.fellows
2019-02-06 23:01
I know that HA proxy is in the mix there - who manages that? The provider or another team? So this is the setup in prod: `[consumer] -> [HAProxy] -> [provider]` right? HAProxy is responsible for adding the `/api` bit of the path and performing the routing to the provider. If this is _not_ tested as part of provider verification (ie. you verify by pointing directly at the provider, bypassing HAProxy, which I?m guessing is the case) then you only have 3 options: 1. Put in a path that omits the `/api` is part of your consumer tests, but make sure the configuration in production puts this there. 2. Test the provider _via_ the HAProxy service 3. Wrap the provider in a teeny lightweight proxy when you test it, so that the paths don?t get out of alignment

dagarwal
2019-02-07 10:14
yes pact node .so when i use canDeploy we have console error as of now so even if i catch the error , build keeps on going and does not fail

rafael.anachoreta
2019-02-07 10:15
That makes sense, thanks a lot for sharing, Matt! :bow: I?ll discuss the options with the team and go from there. Do you think a feature request for it for Pact would fly? Another optional entry to the contract in `providerPath: string`?

matt.fellows
2019-02-07 10:18
It?s worth tabling. I can see it helping some, like yourself :slightly_smiling_face:

matt.fellows
2019-02-07 10:18
and no probs@

mboudreau
2019-02-07 10:50
if you catch the error without throwing another one, it'll gobble it up

mboudreau
2019-02-07 10:50
what are you using for your build system?

dagarwal
2019-02-07 10:50
jenkins

mboudreau
2019-02-07 10:51
okay, and how do you run it? what's the command?

dagarwal
2019-02-07 10:52
i am runnign like this return pactNode.canDeploy(checkVerification).then(() => { console.log(?Verified can i deploy against service?); }).catch(err => { console.log(?Verification failed for can i deploy against service?,err); });

dagarwal
2019-02-07 10:52
i am doing like this in code and runnign the js file on jenkins

dagarwal
2019-02-07 10:52
simply with node ?FileName?

mboudreau
2019-02-07 10:53
right, like I said, since you're catching the error, it never bubbles up to the node top level and thinks you handled it appropriately

dagarwal
2019-02-07 10:53
no even if i dont have catch in it, it does not fail my build

mboudreau
2019-02-07 10:54
there's a few different ways of doing it, one is to just throw the error again: ``` return pactNode.canDeploy(checkVerification).then(() => { console.log(?Verified can i deploy against service?); }).catch(err => { console.log(?Verification failed for can i deploy against service?,err); throw err; }); ```

mboudreau
2019-02-07 10:54
ah right, because it's a promise. You're probably not using something that handles promises in that way

dagarwal
2019-02-07 10:55
yes

dagarwal
2019-02-07 10:55
it just gives unhandled warning

dagarwal
2019-02-07 10:55
and the build goes on

mboudreau
2019-02-07 10:55
yeah

mboudreau
2019-02-07 10:56
one way of doing it is to just do `process.exit(1);` when the catch happens

mboudreau
2019-02-07 10:57
it'll make the program quit with an error code and jenkins will see that as a failed build

dagarwal
2019-02-07 10:57
so whats the way then ? i tried wrapping up the logic in test and did add expect condition to fail it .But i was being suggested its not a test .its part of build .

dagarwal
2019-02-07 10:58
okay i will try with process.exit and see

matt.fellows
2019-02-07 11:41
Also worth checking your Jenkins config. Make sure that any shell environment that you?re running in will also fail on non-zero exit codes

matt.fellows
2019-02-07 11:41
i.e. in in bash, make sure `set -e` is set

dagarwal
2019-02-07 11:47
okay will check

matt.fellows
2019-02-07 11:55
:thumbsup:

dagarwal
2019-02-07 16:00
it worked that way , thanks :slightly_smiling_face:

matt.fellows
2019-02-07 21:06
great!

matt.fellows
2019-02-07 21:06
Specifically, which way worked?

mboudreau
2019-02-07 22:45
the process.exit way :wink:

dagarwal
2019-02-08 09:08
yeah that way :stuck_out_tongue: but it would be good if canDeploy method return the same as its actually checking for if we can deploy or not so it should fail the build :slightly_smiling_face:

matt.fellows
2019-02-08 09:28
Process.exit is an antipattern for libraries - it makes sense for cli tools which check for error codes. Throwing errors or rejecting promises is much more idiomatic in JS. Errors are values and can be used as control flow. Process.exit is a blunt hammer

dagarwal
2019-02-08 09:29
oh i see ..makes sense

matt.fellows
2019-02-08 09:30
:ok_hand:


matt.fellows
2019-02-09 10:26
Thanks Rashi - i?m actually doing a few things now, will look at this :slightly_smiling_face:

arvindr3
2019-02-11 13:23
has joined #pact-js

arvindr3
2019-02-11 13:23
i m getting the issue while i m running the Pact Workshop - js Error: Error from response: undefined at request.get.query.then.err (D:\Pact\pact-workshop-js-master\consumer\client.js:33:15) at process._tickCallback (internal/process/next_tick.js:68:7)

matt.fellows
2019-02-11 20:24
At which step? What have you tried to fix it?

zach.the.hammer
2019-02-12 01:15
has joined #pact-js

arvindr3
2019-02-12 05:17
I m following the instructions given in the github page.I m first running the provider.js and in the seperate terminal i m running the Consumer.js file,while running consumer.js file i m getting the error that i have stated above.

robin
2019-02-15 13:59
has joined #pact-js

bernardo.guerreiro
2019-02-18 08:43
Hey @matt.fellows any update on this spike? I think this looked really good, do you have any plans to add it in a future release?

matt.fellows
2019-02-18 08:47
I plan on releasing in the next drop. Did you have any comment or feedback? Even a thumbs up on that issue would be great

vitaliy.grigoruk
2019-02-18 13:04
I?ll write down some feedback soon.

matt.fellows
2019-02-18 20:00
that?d be awesome

vinod.baradwaj
2019-02-19 17:06
I have an endpoint in my app which is like, `/api/actions?context=type;type=publish;assetIds=10006` with different matrix params `;` now when i create a consumer test with the same path, it throws `500` error. Can anyone here let me know how this can be fixed ? TIA

yousafn
2019-02-19 17:27
you may need to URLencode your path, I had the same issue sending `somepath/£$%` which becomes `somepath%2F%C2%A3%24%25` when encoded. In JS `const path = encodeURI("£$%");`

rickard.andersson
2019-02-20 07:04
has joined #pact-js

vinod.baradwaj
2019-02-20 13:14
this didn't solve my issue :disappointed:

matt.fellows
2019-02-21 07:45
Can you please share your test code so we can see? Logs would he nice too

vinod.baradwaj
2019-02-21 07:50
Hi Matt, this is my test code, ``` describe('Getting available action for publish', () => { before(() => { return provider.addInteraction({ given: 'GET call', uponReceiving: 'Get available action', withRequest: { method: 'GET', path: "/api/actions?context=type;type=publish;assetIds=10006" }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: actions } }); }); it('Get available actions for publish', () => { return request.get(`http://localhost:${PORT}/api/actions?context=type;type=publish;assetIds=10006`) .set({ 'Accept': 'application/json' }).then((response) => { return expect(Promise.resolve(response.status)).to.equal(200); }).catch(err => { console.log("Error in available actions", err); }); }); });``` and this is the logs which i get when i run the consumer tests,

vinod.baradwaj
2019-02-21 07:50
and this is the logs,


matt.fellows
2019-02-21 07:53
Thanks. I can take a look later when back at a desk

vinod.baradwaj
2019-02-21 07:53
thank you :slightly_smiling_face:

matt.fellows
2019-02-21 07:54
I'm actually not sure if or how we support matrix params.

matt.fellows
2019-02-21 07:55
What do the pact logs say?

matt.fellows
2019-02-21 07:55
From that, it just didn't match

vinod.baradwaj
2019-02-21 07:56
i see status `500` response in pact logs, ``` at process._tickCallback (internal/process/next_tick.js:180:9) status: 500, text: '{"message":"No interaction found for GET /api/actions?context=type;type=publish;assetIds=10006","interaction_diffs":[]}\n', method: 'GET', path: '/api/actions?context=type;type=publish;assetIds=10006' },```

vinod.baradwaj
2019-02-21 07:56
like you said it is not matching with the path with matrix params

matt.fellows
2019-02-21 07:57
That's the unit test logs, I'm talking about the one pact itself generates

vinod.baradwaj
2019-02-21 07:59
not sure... how can i get pact logs ?

matt.fellows
2019-02-21 08:01
There's an option in your pact test to specify where it goes. There is probably a log file in a `logs` or `pact` dir now

vinod.baradwaj
2019-02-21 08:06
got it, here goes the logs


vinod.baradwaj
2019-02-21 08:07
```I, [2019-02-21T13:33:57.330594 #6869] INFO -- : Received request GET /api/actions?context=type;type=publish;assetIds=10006 D, [2019-02-21T13:33:57.330712 #6869] DEBUG -- : { "path": "/api/actions", "query": "context=type;type=publish;assetIds=10006", "method": "get", "headers": { "Host": "localhost:30044", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Accept": "application/json", "Connection": "close", "Version": "HTTP/1.1" } } E, [2019-02-21T13:33:57.330820 #6869] ERROR -- : No matching interaction found for GET /api/actions?context=type;type=publish;assetIds=10006 E, [2019-02-21T13:33:57.330845 #6869] ERROR -- : Interaction diffs for that route: E, [2019-02-21T13:33:57.330869 #6869] ERROR -- :```

matt.fellows
2019-02-21 08:12
Based on that, you're library is sending thru the query string correctly (as a query string)

matt.fellows
2019-02-21 08:12
But your test is putting it the path only. Use the query option of the pact interaction

vinod.baradwaj
2019-02-21 08:14
let me try passing it as a param

matt.fellows
2019-02-21 10:10
How?d you go?

vitaliy.grigoruk
2019-02-21 13:18
@matt.fellows this is a tiny fix, will appreciate if we can get this merged/released

matt.fellows
2019-02-21 19:44
+:thumbsup: done


matt.fellows
2019-02-23 01:52
Would love your feedback gents, also on the examples/docs if they need further improvementn

matt.fellows
2019-02-23 02:02
:point_up: We?ve just removed one of the biggest complaints / pain points in Pact JS - the need for a `/setup` endpoint attached to your provider api. You can also now use `requestFilter`s to modify the req/res before sending to the provider. This is perfect for short lived bearer tokens: Example: ``` let token let opts = { provider: 'Animal Profile Service', ... stateHandlers: { "is authenticated": () => { token = "1234" Promise.resolve(`Valid bearer token generated`) }, "is not authenticated": () => { token = "" Promise.resolve(`Expired bearer token generated`) } }, // this middleware is executed for each request, allowing `token` to change between invocations // it is common to pair this with `stateHandlers` as per above, that can set/expire the token // for different test cases requestFilter: (req, res, next) => { req.headers["Authorization"] = `Bearer: ${token}` next() }, // This header will always be sent for each and every request, and can't be dynamic // (i.e. passing a variable instead of the bearer token) customProviderHeaders: ["Authorization: Bearer 1234"] } return new Verifier(opts).verifyProvider().then(...) ```

matt.fellows
2019-02-23 02:04
As you can see, to setup state all you need to do is register a handler in the verifier and it will be invoked by the framework before the test case is run. We use `requestFilter` to set an authorization header depending on the current state


m.r.green
2019-02-25 09:05
has joined #pact-js

vitaliy.grigoruk
2019-02-25 09:34
I?m sorry, I didn?t get back with results of my experiments last week. Due to specifics of our app, we need to wrap each pact verification (state setup + actual test request) into a single transaction (we run express server and launch pact from the same process). So, we need to start transaction before we actually set up state and rollback after a response is received from a server. So, I took your code from ^ spike and modified it to serve our needs. I?ve added `afterResponse` hook (to rollback a transaction) and `beforeSetup` hook to start a transaction. I?m passing transaction id via a header to app server inside `requestFilter`.

vitaliy.grigoruk
2019-02-25 09:35
I can contribute via a PR, in case this could be useful for others.

matt.fellows
2019-02-25 09:36
Ok thanks for feedback - not too late to add, but too late break :laughing:

matt.fellows
2019-02-25 09:38
I thought of having more hooks, but the request filter has the ability to do things to the response. The after hook could be useful for other purposes. If you have time, raising a feature enhancement on the repo is the best next step to get it in

vitaliy.grigoruk
2019-02-25 09:38
great, will do that!

matt.fellows
2019-02-25 10:02
:+1:

punarjit.singh
2019-03-01 03:10
has joined #pact-js

punarjit.singh
2019-03-01 03:10
Hi there... how are we supposed to pass request parameters in Pact Verifier ? are there any opts or do we need to use requestFilters... ?

matt.fellows
2019-03-01 03:11
what do you mean, sorry? Can you step back a bit and please let us know what you?re trying to do and where you?re at?

punarjit.singh
2019-03-01 03:32
Hi @matt.fellows so I am quite new to pact. I might be interpreting the docs in a wrong way. but here is what I'm trying to do: - I have followed the https://github.com/pact-foundation/pact-js#http-api-testing docs.... and created a mock provider within consumer spec. - the pacts are getting generated as expected. - next, I am trying to call the actual provider service (which is a real service hosted on my staging env). - Within my provider spec I am trying to verify the pacts.. - So I am calling Verifier().verifyProvider(opts) - to hit the actual api and verify the pacts... I am not sure how to pass the query parameters in the get request...

matt.fellows
2019-03-01 03:39
So the `verifyProvider` call should be configured to fetch pacts somehow (either from a local folder or from a pact broker). ALl of the details of the requests are in there, and pact will issue the requests against the provider for you

matt.fellows
2019-03-01 03:40
If there are query parameters that should be in the requests, you should have those defined in your consumer tests

punarjit.singh
2019-03-01 03:41
great... thanks a lot for pointing me in the right direction... will update my consumer tests

matt.fellows
2019-03-01 03:42
:thumbsup:

punarjit.singh
2019-03-01 04:35
Hey @matt.fellows .. m passing them as params: {abc: "xyz"} in consumer... pacts are getting generated but still without the params. I am using *axios* request

matt.fellows
2019-03-01 04:45
can you please share the test code ? Have you looked at the examples in the pact-js repo to see how they?re doing it?

punarjit.singh
2019-03-01 04:53
sorry I being so tempted to ask questions as its easy... yes m following the examples and tired a couple of things. trying a few more options... will share the test code if I couldn't resolve it soon

punarjit.singh
2019-03-01 04:54
well yes :smile: I got it working

matt.fellows
2019-03-01 04:57
hehe yes, asking is easier :slightly_smiling_face:

matt.fellows
2019-03-01 04:57
Doing is better! good job

punarjit.singh
2019-03-01 05:04
thanks.. here's the code snippets .. might help someone who's new to pact like me //index.js (provider mock) `'use strict';` `const axios = require('axios');` `exports.getPrices = endpoint => {` ` const url = endpoint.url;` ` const port = endpoint.port;` ` return axios.request({` ` method: 'GET',` ` baseURL: '${url}:${port}',` ` url: '/root/data?abc=XYZ',` ` headers: { "Content-Type": "application/json",}` ` });` `};` //Snippet from consumer.spec.js ` describe('get /root/data', () => {` ` before(done => {` ` const interaction = {` ` uponReceiving: 'a request for data',` ` withRequest: {` ` method: 'GET',` ` path: '/root/data',` ` headers: { "Content-Type": "application/json",},` ` query: {"abc": "XYZ"},` ` },` ` willRespondWith: {` ` status: 200,` ` headers: {` ` 'Content-Type': 'application/json'` ` },` ` body: EXPECTED_BODY` ` }` `};`

punarjit.singh
2019-03-04 01:43
Hey Guys... another quick question. My pact has two interactions, but when I run provider tests to verify this pact... only one interaction is verified. why is that ? Am I missing something Thanks!

matt.fellows
2019-03-04 01:45
hi!

punarjit.singh
2019-03-04 01:46
hey Matt

matt.fellows
2019-03-04 01:46
can you show us why it?s not working, or what leads you to think that?

matt.fellows
2019-03-04 01:46
also the pact contract that?s being verified

punarjit.singh
2019-03-04 01:48
sure. lemme remove any confidential info.. sharing in a while

matt.fellows
2019-03-04 01:49
:thumbsup:

punarjit.singh
2019-03-04 01:54
my pact looks like this... has 2 interactions (a request for data AND a request with missing or parameter)

punarjit.singh
2019-03-04 01:59
Provider (actual service) Pact Test

punarjit.singh
2019-03-04 02:01
please check if this info helps...

punarjit.singh
2019-03-04 02:04
also m not setting the PACT_DESCRIPTION env variable to run any individual interactions

matt.fellows
2019-03-04 02:04
ok, so the provider test is just a single ?test? but how do you know it?s not making multiple calls to your provider?

matt.fellows
2019-03-04 02:04
Try modifying the pact.json file (by hand if you need) so that it hits a different path, and see if it fails

punarjit.singh
2019-03-04 02:06
I thought the single test would run all the interactions... newbie mistakes maybe... by hitting diff path you mean I should change the endpoint uri ?

matt.fellows
2019-03-04 02:09
The single test does run all the interactions - how do you know it?s not?

matt.fellows
2019-03-04 02:10
so i mean modify `"path": "/root/data",` to something else like `"path": "/path/doesnt/exist/so/i/should/see/a/failure,`

matt.fellows
2019-03-04 02:10
then you can see if it?s performed both tests

punarjit.singh
2019-03-04 02:10
coz in the run log.. it only shows one interaction passed

punarjit.singh
2019-03-04 02:10
sure

matt.fellows
2019-03-04 02:10
oh I see

matt.fellows
2019-03-04 02:10
sorry it was hard to see that

punarjit.singh
2019-03-04 02:11
sorry about that.

matt.fellows
2019-03-04 02:11
np

matt.fellows
2019-03-04 02:11
Are you sure it?s reading the correct pact file?

punarjit.singh
2019-03-04 02:11
yes

punarjit.singh
2019-03-04 02:11
there's only one

matt.fellows
2019-03-04 02:11
the one you shared with me has 2

punarjit.singh
2019-03-04 02:11
no wait.. you're right

matt.fellows
2019-03-04 02:12
:smile:

punarjit.singh
2019-03-04 02:12
pact file is wrong

punarjit.singh
2019-03-04 02:12
my bad

matt.fellows
2019-03-04 02:12
haha

punarjit.singh
2019-03-04 02:13
silly me.. sorry for your time mate. thank you so much

matt.fellows
2019-03-04 02:13
np

josh.mccure
2019-03-05 01:07
has joined #pact-js

jeffm
2019-03-05 19:24
I'm having a bit of trouble understanding how matchers work with request paths. Is there a good example to look at?

jeffm
2019-03-05 19:26
The API I'm testing has a path segment which is a timestamp

matt.fellows
2019-03-05 19:26
what have you tried?

jeffm
2019-03-05 19:28
I presume I have to setup matchingRules with $.path in the request?

matt.fellows
2019-03-05 19:31
yep

matt.fellows
2019-03-05 19:31
look at the e2e example in the repository, there is a matcher example for paths in there

matt.fellows
2019-03-05 19:33
``` provider.addInteraction({ state: "Has an animal with ID 1", uponReceiving: "a request for an animal with ID 1", withRequest: { method: "GET", path: term({ generate: "/animals/1", matcher: "/animals/[0-9]+" }), headers: { Authorization: "Bearer token" }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: animalBodyExpectation, }, }) ```

matt.fellows
2019-03-05 20:37
How'd you go?

jeffm
2019-03-05 21:05
~Thanks, will try again this afternoon~

jeffm
2019-03-05 21:06
Thanks, we'll give it a try this afternoon.


matt.fellows
2019-03-05 21:08
Yep

jeffm
2019-03-05 23:35
Using `term` worked. Thank you. We're now matching the expected request, although struggling through debugging why the body of the provider response does not match: `Expected a Hash but got a String`

jeffm
2019-03-05 23:39
``` body: { 't': { 't': Matchers.term({ generate: `${subscribeTime}`, matcher: '[0-9]+' }), 'r': 2 }, 'm': [] }, -{ - "t": { - "t": "15518280219750000", - "r": 2 - }, - "m": [, - - ] -} +"{\"t\":{\"t\":\"15518279409297495\",\"r\":2},\"m\":[]}" ```

matt.fellows
2019-03-06 00:12
I think you need to match on the content type

matt.fellows
2019-03-06 00:12
As json

matt.fellows
2019-03-06 00:13
Either that, or your app is not sending JSON and is sending a string

rjmcguinness
2019-03-06 09:49
Hi pact-js team, Do you have any recommendations for dealing with matching nested arrays? For example, I have a payload object with a property `option` which is an array of objects containing arrays, see below. ``` const dummyPayload = { options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], }, {name: 'option name 2, data...} ], }; ``` The below works, but is quite hard to read. This is a simplified example, and some of our responses have deeper nesting. ``` const dummyResponsePact = { options: Matchers.eachLike({ ...dummyPayload.options, data: Matchers.eachLike(dummyPayload.options[0].data[0]), }), }; ```

matt.fellows
2019-03-06 09:50
Can you just not wrap the whole thing in a single `like` matcher?

rjmcguinness
2019-03-06 09:59
Looks like `like` is just an alias for `somethingLike`, which I am actually currently wrapping this object with when adding interactions (sorry that was not visible in the example). The `somethingLike`/`like` matcher doesn?t deal with arrays like `eachLike` does though. My intent is to have all the arrays in my object, however deeply nested, match at the one or more level, outputting the below in the pact: ``` "matchingRules": { "$.body": { "match": "type" }, "$.body.options": { "min": 1 }, "$.body.options[*].*": { "match": "type" }, "$.body.options[*].data": { "min": 1 }, "$.body.options[*].data[*].*": { "match": "type" } } ```

matt.fellows
2019-03-06 11:15
My understanding is that wrapping the entire block in just a `like` - with no nested matchers - should automatically and recursively set type matchers (incl. to arrays) as it goes down the tree. Is this not happening?

rjmcguinness
2019-03-06 11:21
This is the only type matcher I get in the Pact json when passing the raw object into `Matchers.like()` ``` "matchingRules": { "$.body": { "match": "type" } } ```

asad
2019-03-06 12:28
has joined #pact-js

asad
2019-03-06 12:34
Hi i have a provider test as follow (using jest and using message queue) ``` /* eslint-disable no-undef */ const { MessageProviderPact } = require('@pact-foundation/pact'); const path = require('path'); const { getMsg } = require('./../mock-prestac'); describe('Message provider tests', () => { const p = new MessageProviderPact({ messageProviders: { 'a request for prepare': () => getMsg(), }, log: path.resolve(process.cwd(), 'logs'), provider: 'prestac', providerVersion: '1.0.0', logLevel: 'fatal', pactUrls: [ path.resolve(process.cwd(), 'pacts', 'prepare-prestac.json'), ], }); describe('send a prepare message', () => { it('sends a valid prepare message', () => { p.verify(); }, 30000); }); }); ``` its working test pass but it dont exit and produce some error as follow ``` PASS tests/provider.test.pact.js (5.797s) Message provider tests send a prepare message ? sends a valid prepare message (18ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 7.742s Ran all test suites. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. (node:11280) UnhandledPromiseRejectionWarning: Error: INFO: Reading pact at /xampp/htdocs/prepare-service/pacts/prepare-prestac.json Verifying a pact between prepare and prestac Given message is valid a request for prepare has matching content (FAILED - 1) Failures: 1) Verifying a pact between prepare and prestac Given message is valid a request for prepare has matching content Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'message is valid' for consumer 'prepare' at http://localhost:63714/_pactSetup. response status=415 response body=<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at C:\xampp\htdocs\prepare-service\node_modules\body-parser\lib\read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (C:\xampp\htdocs\prepare-service\node_modules\raw-body\index.js:224:16)<br> &nbsp; &nbsp;at process.internalTickCallback (internal/process/next_tick.js:70:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * A request for prepare given message is valid (node:11280) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:11280) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ```

matt.fellows
2019-03-06 19:44
I think that's correct. Is it not doing what you would expect? Forget the serialisation into pact for a second, does the consumer and provider test work as expected?

matt.fellows
2019-03-06 21:34
you need to return the `p.verify()` as it?s a promise. That?s why you?re getting a green test but an error printed out after

matt.fellows
2019-03-06 21:35
You should also setup a state handler for the ?message is valid? state

asad
2019-03-07 09:03
Thank for help will try your suggestion :+1:

asad
2019-03-07 09:58
hey can you provide me example of state handler? m not able to find it in https://github.com/pact-foundation/pact-js/tree/master/examples/messages

asad
2019-03-07 10:17
found it in https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/provider.spec.js i am now returning `p.verify()` but still getting same error (no green test this time, guess it was not green before either just was not throwing error before showing test as green) This is the output i am getting ``` $ npm run test:provider > render-service@1.0.0 test:provider C:\xampp\htdocs\render-service > jest --testRegex "/*(provider.test.pact.js)" --runInBand --setupFiles ./tests/config/pactSetup.js --setupTestFrameworkScriptFile=./tests/config/pactTestWrapper.js [2019-03-07T10:14:23.616Z] INFO: pact-node@6.21.5/3360 on DESKTOP-KOB10PR: Creating Pact Server with options: consumer = render, cors = false, dir = C:\xampp\htdocs\render-service\pacts, host = 127.0.0.1, log = C:\xampp\htdocs\render-service\pact logs\pact-tests.log, pactFileWriteMode = update, port = 8991, provider = prestac, spec = 2, ssl = false, sslcert = , sslkey = FAIL tests/provider.test.pact.js (6.689s) Message provider tests send a render message × sends a valid render message (2046ms) ? Message provider tests ? send a render message ? sends a valid render message INFO: Reading pact at /xampp/htdocs/render-service/pacts/render-prestac.json Verifying a pact between render and prestac Given message is valid a request for rendering has matching content (FAILED - 1) Failures: 1) Verifying a pact between render and prestac Given message is valid a request for rendering has matching content Failure/Error: raise "An error was raised while verifying the message.The response body is: #{response.body}" RuntimeError: An error was raised while verifying the message. The response body is: {} 1 interaction, 1 failure Failed interactions: * A request for rendering given message is valid at ChildProcess.<anonymous> (node_modules/@pact-foundation/pact-node/src/verifier.ts:172:57) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 10.63s Ran all test suites. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ```

krzysztof.stepniak
2019-03-07 10:34
has joined #pact-js

krzysztof.stepniak
2019-03-07 10:38
Hi guys, I have problem with matchers when I?m using them on headers and body for post wiht header `mulipart/form-data`. When I use regex which should enable all characters `[\\s\\S]*` post always end with 500 on mock server. I can send you part of code if its more descriptive.

matt.fellows
2019-03-07 10:41
My apologies, you don?t need a state setup for this. Att least, it?s not mandatory.

matt.fellows
2019-03-07 10:41
What?s the pact logs say? It appears as if the content isn?t matching, which means its a legitimate failure

matt.fellows
2019-03-07 10:49
The state is also passed in to the registered handler, so that can setup any state required if needed too

krzysztof.stepniak
2019-03-07 10:52
Funny thing is that the commented matchers are not matched by pact correctly inspite of that they goes through ruby and js regex. Pactjs shows two the same with error that is not the same /shrug

matt.fellows
2019-03-07 10:54
What does the pact logs have to say about it?

krzysztof.stepniak
2019-03-07 10:55
oh wait

krzysztof.stepniak
2019-03-07 10:55
not that

matt.fellows
2019-03-07 10:55
as an aside, this is a bit wrong: ``` after(async () => { return await platformBFF.finalize(); }); ``` remove the async and await

matt.fellows
2019-03-07 10:55
you can simply return the promise here - no need to await for it and then return. That?s just a double wrapped promise :slightly_smiling_face:

krzysztof.stepniak
2019-03-07 10:56
mkay

matt.fellows
2019-03-07 10:57
(there?s a few examples of that)

matt.fellows
2019-03-07 10:58
also, what?s this all about? It looks like you?re trying to ensure a project is created before running the consumer tests? is that right? ``` projectId = (await setup.createProject('floor', token)).body._id; ```

krzysztof.stepniak
2019-03-07 10:58
yes it is for provider side

krzysztof.stepniak
2019-03-07 10:59
i want to extract id and create project on real service and pass his id

krzysztof.stepniak
2019-03-07 10:59
it works fine in other tests

matt.fellows
2019-03-07 11:03
you can?t do that in pact

krzysztof.stepniak
2019-03-07 11:03
Test is all about creating via POST new floor which have picture and name. To get there you need to create previously project and there you are creating floor

matt.fellows
2019-03-07 11:04
I understand, but that is a scenario / functional tests.

matt.fellows
2019-03-07 11:04
I?d suggest taking a read through the FAQ


krzysztof.stepniak
2019-03-07 11:05
this path is used by mobile team

krzysztof.stepniak
2019-03-07 11:05
i only want to check this one endpoint

matt.fellows
2019-03-07 11:05
Aside from that, it just won?t work. Your consumer tests, if using Pact, hit the Pact mock server. . So creating a project and then hitting the pact endpoint has no impact on that test

matt.fellows
2019-03-07 11:06
I?ve added a state handler example to message pact just now too

krzysztof.stepniak
2019-03-07 11:07
Im not sure if i understand it correctly.

matt.fellows
2019-03-07 11:07
Have you read those FAQs?

krzysztof.stepniak
2019-03-07 11:07
Im just mocking floor endpoint thats all

krzysztof.stepniak
2019-03-07 11:07
yep

krzysztof.stepniak
2019-03-07 11:15
So im digging too deep in this test?

asad
2019-03-07 11:16
Attached the logs. it include warn and error ``` W, [2019-03-07T12:19:48.394818 #17152] WARN -- : Could not load existing consumer contract from C:/xampp/htdocs/render-service/pacts/render-prestac.json due to undefined method `gsub' for nil:NilClass. Creating a new file. E, [2019-03-07T12:19:48.394818 #17152] ERROR -- : undefined method `gsub' for nil:NilClass (NoMethodError) ```

matt.fellows
2019-03-07 11:18
sorry, was afk

matt.fellows
2019-03-07 11:19
so take me through what yoou?re doing

matt.fellows
2019-03-07 11:19
1. the `createProject` 2. the `postFloor` bit

matt.fellows
2019-03-07 11:20
Something is wrong with the contract - how did it get created? Did you create it by hand?

asad
2019-03-07 11:21
no i have consumer test which creates it, i delete it and create from consumer again

matt.fellows
2019-03-07 11:21
ok

matt.fellows
2019-03-07 11:22
could you please share the contract with us? Or a minimal version of it that creates that error? It seems that it is not being serialised correctly. That?s a bug somewhere

krzysztof.stepniak
2019-03-07 11:30
ok

krzysztof.stepniak
2019-03-07 11:31
createProject is just for provider side to reach floor with exact id which im passing into consumer contract

asad
2019-03-07 11:31
my consumer test code ``` const { MessageConsumerPact, asynchronousBodyHandler, } = require('@pact-foundation/pact'); const path = require('path'); const { validateMessage } = require('./../render'); const msg = { identifier: {}, body: { projectId: 538481, projectPath: 'C:/xampp/htdocs/render-service/538481.aep', movPath: 'C:/xampp/htdocs/render-service/538481.mov', mp4Path: 'C:/xampp/htdocs/render-service/538481.mp4', }, }; describe('Message consumer tests', () => { const messagePact = new MessageConsumerPact({ consumer: 'render', dir: path.resolve(process.cwd(), 'pacts'), pactfileWriteMode: 'update', provider: 'prestac', logLevel: 'fatal', }); describe('Receive a valid message for rendering', () => { it('Process rendering', () => messagePact .given('message is valid') .expectsToReceive('a request for rendering') .withContent(msg) .verify(asynchronousBodyHandler(validateMessage)), 600000); }); }); ``` and the contract it generate is ``` { "consumer": { "name": "render" }, "provider": { "name": "prestac" }, "messages": [ { "description": "a request for rendering", "providerStates": [ { "name": "message is valid", "params": null } ], "contents": { "identifier": { }, "body": { "projectId": 1, "projectPath": "path", "movPath": "path", "mp4Path": "path" } }, "matchingRules": { "body": { } }, "metaData": { } } ], "metadata": { "pactSpecification": { "version": "3.0.0" } } } ```

krzysztof.stepniak
2019-03-07 11:31
Project ---> Floor . You cant create floor without project

matt.fellows
2019-03-07 11:32
does that actually create a project in the provider side?

matt.fellows
2019-03-07 11:32
or mock it out, as you said before?

krzysztof.stepniak
2019-03-07 11:32
It creates real project on service.

krzysztof.stepniak
2019-03-07 11:32
not mocked

krzysztof.stepniak
2019-03-07 11:33
Consumer gets just id which is passed into path

matt.fellows
2019-03-07 11:33
> You cant create floor without project This is what we are referring to as a functional test, specifically for the provider. This sort of test belongs in the provider, not the consumer.

matt.fellows
2019-03-07 11:33
Further more, with Pact, if your next test is to create the floor you?re not going to hit the provider service - you?re going to hit the Pact mock server. It doesn?t need the project to be created - it has no idea

krzysztof.stepniak
2019-03-07 11:34
so in that case when i use verify from provider side it didn?t get through

krzysztof.stepniak
2019-03-07 11:35
because real service did not get id and so on

matt.fellows
2019-03-07 11:35
No, nothing you do in the consumer tests touches the real provider. That?s by design - otherwise you don?t need Pact, you can just do the usual e2e testing. Pact means that you can test each system separately as _unit tests_

matt.fellows
2019-03-07 11:35
correct

krzysztof.stepniak
2019-03-07 11:36
mkay

matt.fellows
2019-03-07 11:36
each interaction should be tested on its own, and as close to a unit test as possible. The more setup you find yourself doing for a test is a smell that something is not right, and the test is getting too broad

krzysztof.stepniak
2019-03-07 11:36
ok

krzysztof.stepniak
2019-03-07 11:38
ok, so lets back to interaction provided by me

krzysztof.stepniak
2019-03-07 11:38
why this return 500 from mocked server

krzysztof.stepniak
2019-03-07 11:39
I know you are talking that my test is not correct because I am setting up things from provider side in consumer test but it has nothing to do with 500 from mock server

matt.fellows
2019-03-07 11:40
Something to do witht ASCII-8BIT

krzysztof.stepniak
2019-03-07 11:41
yeah encoding stack

krzysztof.stepniak
2019-03-07 11:42
I saw that it is common stack in pact

matt.fellows
2019-03-07 11:42
mmm yeah I?ve seen this before, but I?m not sure it?s ever been resolved


matt.fellows
2019-03-07 11:42
Might be worth looking at the ruby standalone ruby and giving it a bump

krzysztof.stepniak
2019-03-07 11:44
mkay, thanks for your help Randy :wink:

matt.fellows
2019-03-07 11:44
hahaha

matt.fellows
2019-03-07 11:44
no probs, and sorry. I?ll have a look again tomorrow, but it?s late here and I should get to bed

matt.fellows
2019-03-07 11:44
good luck!

krzysztof.stepniak
2019-03-07 11:44
cya

rjmcguinness
2019-03-07 11:50
I didn?t think so, but I am not part of the provider team so will have to dig into this to see. Thanks, I?ll let you know what I find

phil.a.herbert
2019-03-07 15:57
has joined #pact-js

phil.a.herbert
2019-03-07 16:06
Hello! Does anyone know if there has been any work done towards matching on dynamic object keys? (see https://github.com/pact-foundation/pact-specification/issues/47, https://github.com/DiUS/pact-jvm/issues/313). It?s seemingly in the v4 spec (https://github.com/pact-foundation/pact-specification/tree/version-4#ignoring-the-keys-in-a-map), but given that it?s been implemented in pact-jvm, I?m curious to know if anyone has thought about it for pact-js. I would also be happy to have a go at implementing it if: a) it?s not too complicated for someone new to the repo b) people think it?s a good idea

matt.fellows
2019-03-07 23:22
It?s definetely a good idea, but you would need to get it into the Ruby implementation (as that?s used under the hood in all but the JVM based ones)

matt.fellows
2019-03-07 23:22
You want to raise an issue at https://github.com/pact-foundation/pact-ruby/

matt.fellows
2019-03-07 23:22
(if there?s not already one)

asad
2019-03-08 07:24
hey @matt.fellows did you looked into message i sent? is there something wrong with my code or bug in pactjs?

matt.fellows
2019-03-08 07:44
Which message, sorry

asad
2019-03-08 08:21
in the previous thread :stuck_out_tongue: guess i will add it here agian


matt.fellows
2019-03-08 11:04
Sorry I must have missed it. But it's not showing up well on my phone (I'm out tonight). I'll try to look tomrrow sorry


asad
2019-03-11 07:23
any updates on this @matt.fellows :slightly_smiling_face:

matt.fellows
2019-03-11 07:43
Hmm no sorry, could you please raise a ticket on pact-js repo?

matt.fellows
2019-03-11 07:43
You shouldn?t be able to create a problem with the contract file using nothing but our tools

matt.fellows
2019-03-11 07:43
sorry!

asad
2019-03-11 07:48
ok i will and np

matt.fellows
2019-03-11 07:51
thanks mate!

asad
2019-03-11 07:59
created the issue let me know if you would need more info :slightly_smiling_face:

matt.fellows
2019-03-11 08:54
:+1:

matt.fellows
2019-03-11 23:09
@yousafn let me know how the above goes, hopefully has sorted the issue!

yousafn
2019-03-11 23:25
hey mate will try it now :slightly_smiling_face:

yousafn
2019-03-11 23:45
good spot on the v2 in the url. pact-js now passing which means the pact-node job is failing for same reason, click on the pact-node job to see. https://circleci.com/workflow-run/28225c87-ffb3-4ad2-bed6-37e627b9a2a2 I can raise an issue against pact-node if you want? also got an aside issue, I can?t call a https pact broker that doesn?t have a CA, (default nginx config from the example docs) that job is also shown in that workflow thanks again dude

matt.fellows
2019-03-12 02:31
no probs. I?m having accessing that link (getting a 404) - is it a public build?

matt.fellows
2019-03-12 02:32
nvm, just needed to login

matt.fellows
2019-03-12 02:33
The pact node job i think is failing because it?s hitting the same problem i.e. `/v2/v2/...`

matt.fellows
2019-03-12 02:33
Note the error is a `404` not an SSL issue

matt.fellows
2019-03-12 02:33
oh, hmmm

matt.fellows
2019-03-12 02:35
Not sure why it?s 404ing, but you might want to bump the log level and see if anything useful turns up

yousafn
2019-03-12 10:46
Morning chap (probably late night for you) - Will have a look into it today whilst I?m at work. Not entirely clear on how to bump the log level as there doesn?t appear to be a logging param on the verifyPacts

matt.fellows
2019-03-12 10:57
`logLevel: "DEBUG"` should do it

matt.fellows
2019-03-12 10:57
oh, right. Pact-node probably doesn?t have that, no

matt.fellows
2019-03-12 10:57
just pact-js

yousafn
2019-03-12 12:15
It will only work if `pact.logLevel('DEBUG');` outside of the pact.verifyPacts(opts) block but that only outputs the debug output for the pact-binary. Not really an issue for me now that we have the ability to switch off sslverification in pact-js. I will propose a PR in the next couple of days just to add that new option to the readme

adamgreen
2019-03-12 15:37
Hi all, having some trouble getting a pact test to run using the ApolloGraphQLInteraction in Angular using Karma etc. When I run ng test I get the following error (see thread), any ideas what i'm probably doing wrong? Thanks in advance

matt.fellows
2019-03-12 22:20
Hmm `ApolloGraphQLInteraction` is not a type in the `pact-web` package. Could you please raise an issue for this? It probably should be.

matt.fellows
2019-03-12 22:20
You _should_ be able to get it from the `@pact-foundation/pact` package, though in the mean time

adamgreen
2019-03-13 07:55
Hi Matt, thanks for getting back to me, i'll raise that right now. I did try taking it from /pact as i'd noticed in the example for graphql, but i get a different error ERROR in src/app/pact/pact-component.pact.spec.ts(62,33): error TS2345: Argument of type 'ApolloGraphQLInteraction' is not assignable to parameter of type 'InteractionObject | Interaction'. Type 'ApolloGraphQLInteraction' is not assignable to type 'Interaction'. Property 'state' is protected but type 'Interaction' is not a class derived from 'Interaction'. Thanks again

matt.fellows
2019-03-13 08:13
Ok cool, looks like we need to port that across. Should be straightforward

matt.fellows
2019-03-13 08:21
Your could probably do some nasty casting there in the meanwhile

asad
2019-03-15 12:33
Hi i am trying to run https://github.com/pact-foundation/pact-js/tree/master/examples/messages locally on my system (windows 10) as it is, i pulled repo pact-js moved to example messages did `npm i` after that m trying to run consumer and provider test but both are giving same error ` Error: The system cannot find the path specified.`

asad
2019-03-15 12:33
provider test output

matt.fellows
2019-03-15 20:49
Have you run npm I the root folder and project folder?

sergiy
2019-03-17 14:34
has joined #pact-js

asad
2019-03-18 06:55
yes i run npm I in root folder as-well

evan_l00
2019-03-20 00:49
has joined #pact-js

evan_l00
2019-03-20 00:52
Hi, based on my understand, there are many libraries could do the contract testing and why pact stands out? I think I can use newman(postman's command line) to automate the requests and verify the response like the pact does.

matt.fellows
2019-03-20 00:53
sure, but that?s not contract testing

matt.fellows
2019-03-20 00:53
that?s just API/HTTP testing

evan_l00
2019-03-20 00:53
What's the difference between contract testing and API testing. I read this link By read this link https://docs.pact.io/best_practices/consumer/contract_tests_not_functional_tests

evan_l00
2019-03-20 00:54
I think the contract testing mention in the link just a loose API testing. contract just test fewer cases

matt.fellows
2019-03-20 00:54
Contract tests checks both sides of the API contract - the consumer and the provider. It ensures that _both_ sides of the contract are in sync, preventing drift

matt.fellows
2019-03-20 00:55
It?s easy to have a swagger defined for a provider API, and even check that the provider is compatible with it (if that?s what yyou do). It?s harder to be sure, that the consumer implements the contract correctly

matt.fellows
2019-03-20 00:56
Contract testing let?s you test each side of this _independently_ - meaning you don?t need to have both services running to ensure they are compatible. This enables much simpler continuous delivery

matt.fellows
2019-03-20 00:57
Without contract testing, you can?t be sure, and therefore have to start up all the services together and test them at the same time to make sure they?re compatible. This is slow, problematic, fragile and cumbersome

evan_l00
2019-03-20 00:58
Firstly thank you for your kind help and detailed answer!! :slightly_smiling_face: My further question is for the corps that one team owns the consumer and the other team owns the provider.

evan_l00
2019-03-20 00:59
The provider team cannot wait the consumer team to provide the pact.

matt.fellows
2019-03-20 00:59
you?re welcome

evan_l00
2019-03-20 01:00
because in most of the case, the provider will be developed first. And in the provider developing time, the provider team needs to test their service.

matt.fellows
2019-03-20 01:00
Sure, and they should absolutely test their service through whatever means makes sense. The contract can be generated later by the consumer when they?re ready, at which point the provider can verify it.

matt.fellows
2019-03-20 01:01
All of the functional testing of the provider still needs to be done, it just should be done by the provider team (not the consumer team, via e2e tests).

matt.fellows
2019-03-20 01:01
for that, whatever tool gets the job done is fine

matt.fellows
2019-03-20 01:01
so newman can definitely be used with Pact

matt.fellows
2019-03-20 01:01
newman = functional test, pact = contract test

matt.fellows
2019-03-20 01:02
functional test = the API does what it says it does contract test = the parties that use the API are always in sync with how the API should be used

matt.fellows
2019-03-20 01:03
bbl sorry, in meeting

evan_l00
2019-03-20 01:05
Please be proud that you can answer questions from new comers like me :slightly_smiling_face:.

evan_l00
2019-03-20 01:07
These days I have tried with do a API-test with my new provider with the pact-js. Your answers clear most of the doubts I met during the process. Thank you very much!

evan_l00
2019-03-20 01:13
So contract testing is an extra insurance for the software. If the consumer and provider teams develop separately, provider team will still need the verify the provider by API-testing. And the consumer team will provide the contract pact while writing the consumer and later give the pact to the provider to verify the provider. In the future, the provider could use the pact to verify its new change and the consumer could verify itself by the pact. Is my understanding correct? Last but not least, deeply thank you for you answer!

bethskurrie
2019-03-20 01:14
Yes, this is correct.

evan_l00
2019-03-20 01:14
Thank you, Beth!

abubics
2019-03-20 03:19
@evan_l00 Another thing you can do (from the provider side, while waiting for consumers to exist) is write your own test consumer. It doesn't have the full value of a real consumer, but it can exercise your CI/CD testing infrastructure :slightly_smiling_face:

evan_l00
2019-03-20 23:21
Create a thread

evan_l00
2019-03-20 23:22
@abubics CI/CD testing infrastructure could be also exercise by other test frameworks. I don't any pros here

matt.fellows
2019-03-20 23:23
I think by ?infrastructure? in this context, Boris means ?your CI/CD scripting process?. Not testing actual server/cloud infrastructure.

matt.fellows
2019-03-20 23:23
i.e. it prepares you for when the ecosystem grows to multiple consumers and providers

evan_l00
2019-03-20 23:25
It seems this a over-thinking idea. Too many purposes on one framework seems bring too much complexity

evan_l00
2019-03-20 23:27
and with a fake consumer, you have too pacts to obey. one is the real, one is the one you are testing

matt.fellows
2019-03-20 23:28
I?m not sure what you mean? Pact is not a CI/CD tool, but is designed fit _within_ them.

matt.fellows
2019-03-20 23:28
as for the fake consumer, you would delete it as soon as a real one comes on board

evan_l00
2019-03-20 23:29
I mean other libraries/framework also designed fit within them

evan_l00
2019-03-20 23:29
Yeah. Deleting the fake would be the solution.

matt.fellows
2019-03-20 23:30
it just prepares you for when a consumer is ready, rather than you having to setup the process to fetch and verify consumer pacts, integrate the ?can-i-deploy? tool etc. only after a consumer comes on board.

evan_l00
2019-03-20 23:32
I just struggle with why I need to write unit test, api test and contract test. If the API test cover the change, how can the provider break the contracts set by API test. An example about why the pact/contract test rescue would be very appreciated

evan_l00
2019-03-20 23:33
When we do API test, we actually set up contracts between consumer and provider. If the adding change in the provider pass the API test, how can he breaks the contract set up by the API test?

matt.fellows
2019-03-20 23:40
> how can the provider break the contracts set by API test Because the provider is free to change the contract, and then validate that the (new) contract is satisfied by its own testing > When we do API test, we actually set up contracts between consumer and provider How do you do this now? > If the adding change in the provider pass the API test, how can he breaks the contract set up by the API test? don?t also forget that the _consumer_ is a key part of this, and they may inadvertently get out of sync also > I just struggle with why I need to write unit test, api test and contract test Even if you assumed that you had the right level of coverage, traditional e2e testing that ensures they _do_ work together, is slow, fragile, hard to maintain and hard to debug. Contract tests let you test each component in isolation, whilst guaranteeing that they are still compatible

abubics
2019-03-20 23:42
Basically, contract testing like this is further towards the bottom of the testing pyramid, rather than e2e and functional tests that: - have many moving parts, - are slower to run, and - are inherently more flaky

abubics
2019-03-20 23:43
so you can focus on faster feedback, and smaller tests :ok_hand:

abubics
2019-03-20 23:44
Contract testing like this also decouples the consumer and provider. This helps you debug quicker, because you find out which side broke the contract at the start of the test failure, instead of through your own investigation :slightly_smiling_face:

abubics
2019-03-20 23:44
Then you can decide which version of the contract is correct (new or old)

evan_l00
2019-03-20 23:45
@matt.fellows thank you very much! As for "How do you do this now", when we do API test, we definitely assume that provider gives certain responses. And the consumer will work with these responses. Later when I change provider, if I pass the API-test, it means that the consumer could work as before because the certain responses still exists

abubics
2019-03-20 23:45
Because of that, you can also ensure that you only deploy backwards-compatible contract changes

abubics
2019-03-20 23:46
So, the contract is the set of matching interfaces, not a specification artifact?

evan_l00
2019-03-20 23:47
Could you give an example that with API-test, there is something will be broke?

evan_l00
2019-03-20 23:51
I have read DIUS/pact-workshop-js 's example. In the step 3 or 4 says that http://Pact.io to rescue. But I see that the consumer will fail because it does not follow the API that the provider gives instead consumer test the API response based on its imagination.

abubics
2019-03-20 23:55
that's the "consumer-driven" part :slightly_smiling_face:


abubics
2019-03-21 00:00
You need to make a philosophy shift for Pact to give you a benefit. Have you read anything about consumer-driven vs provider-driven APIs? e.g. https://docs.pact.io/#consumer-driven-contracts

abubics
2019-03-21 00:01
A large part of the value of making the API design consumer-driven is that you usually don't know what your consumers need, or how they want to interact with any API you're building.

abubics
2019-03-21 00:03
Oftentimes, you'll have many different consumers, with slightly different needs and use cases. e.g. They won't all use all of the API endpoints. You can write smaller test suites for each consumer, and granularly find out if API changes will break individual consumers.

abubics
2019-03-21 00:04
Then you can talk to those teams and find out why they want to use the API in that way, and either accommodate them, or get them to accommodate your API design.

abubics
2019-03-21 00:04
Pact doesn't replace having conversations between teams, but it can help you have better conversations with the right people :slightly_smiling_face:

evan_l00
2019-03-21 00:11
I get it that it can avoid a lot of communication and negotiation between teams

abubics
2019-03-21 00:11
nono, it's meant to facilitate communication & shared understanding

abubics
2019-03-21 00:12
(but higher quality comms)

evan_l00
2019-03-21 00:15
Thank you @abubics I'll try to figure out left parts with my coding experience grows

abubics
2019-03-21 00:18
There are some good talks and blog posts about it, so let us know if you get stuck again :slightly_smiling_face:

matt.fellows
2019-03-21 00:18
I?d recommend the Atlassian talk, they have nice animations and talk about how they use it with swagger

yousafn
2019-03-21 00:21
^ this. that talk is brilliant. It definitely a philosophical shift into the world of CDC, it should be called collaboration driven contract testing however. I see it as a provider now has a view as to how the consumer is using their service, and exactly what they use, rather than just a load of requests. Provider can put out a new release without breaking all their clients. Without CDC, providers have no view until they put out a release and get broken consumers on the phone, or you have painful integration testing phases where everyone needs to line up at the same time.

evan_l00
2019-03-21 00:22
Thank you all. I google them and read them. If I still get question, I'll will bother you again.


krzysztof.stepniak
2019-03-26 09:38
Hi, guys do you support in stateHandlers async functions?

matt.fellows
2019-03-26 09:52
Yes, they accept promises. They must be a promise, in fact

krzysztof.stepniak
2019-03-26 10:08
Ok, I handled it.

krzysztof.stepniak
2019-03-26 10:11
how should I use `providerStatesSetupUrl`. I can?t find any useful information. Where should it point?

matt.fellows
2019-03-26 10:22
what docs are you looking at?

matt.fellows
2019-03-26 10:23
that field is deprecated in favour of the field you just mentioned (i.e. `stateHandlers` is the new `providerStatesSetupUrl`)


krzysztof.stepniak
2019-03-26 10:31
also I have warning after executing tests: `WARN: Skipping set up for provider state 'Project in db' for consumer 'spaces-web' as there is no --provider-states-setup-url specified.`

matt.fellows
2019-03-26 10:43
how are you running the tests? If you?re using Pact JS, you don?t need to manually run that verifier

krzysztof.stepniak
2019-03-26 10:47
well im using mocha `"provider:pact": "./node_modules/.bin/mocha pact/provider/*.test.js"`

krzysztof.stepniak
2019-03-26 10:48
and yes I am using Pact JS

matt.fellows
2019-03-26 10:48
can you please share your verification code? You shouldn?t be getting that ?skipping?? message

matt.fellows
2019-03-26 10:48
also, as importantly, what?s the version of Pact you?re using?

krzysztof.stepniak
2019-03-26 10:49
?@pact-foundation/pact?: ?^7.3.0", ?@pact-foundation/pact-node?: ?^6.21.4",

krzysztof.stepniak
2019-03-26 10:58
btw. your HAL browser is dead?

bethskurrie
2019-03-26 10:59
Is it?

krzysztof.stepniak
2019-03-26 10:59
i can?t get in API version

krzysztof.stepniak
2019-03-26 10:59
404 everywhere

bethskurrie
2019-03-26 11:02
Thank you for letting us know. I will fix this asap.

matt.fellows
2019-03-26 11:05
`return await new Verifier().verifyProvider(opts);`

matt.fellows
2019-03-26 11:05
the await is superflous here.

matt.fellows
2019-03-26 11:06
Also not that `customProviderHeaders` is evaluated at compile time, so the value _will not change throughout the tests_

bethskurrie
2019-03-26 11:07
Have to wake up all the build nodes :stuck_out_tongue: It's late here so they've all gone to sleep.


matt.fellows
2019-03-26 11:13
oh, you need to update to version 8.x.x - stateHandlers is not in v7

krzysztof.stepniak
2019-03-26 11:43
Ok, I?ll update it. Thanks once again Randy.

matt.fellows
2019-03-26 11:51
hehe

bethskurrie
2019-03-26 11:56
Hal browser is back. Thanks @krzysztof.stepniak

krzysztof.stepniak
2019-03-26 11:56
thanks

krzysztof.stepniak
2019-03-26 13:44
I have one more question when you awake. I have such warn: `WARN: pact@8.0.5/50601 on MacBook-Pro-krzysiek.local: No state handler found for "Project in db", ignorning` Inspite of spelling bug, I have declared state but it is ignoring it but test works fine

krzysztof.stepniak
2019-03-26 13:44
¯\_(?)_/¯

rjmcguinness
2019-03-26 17:04
Hi all, Do you have any recommendations for dealing with matching arrays, particularly nested arrays? For example, I have a payload object with a property `options` which is an array of objects each of which have a property `data` which is an array, see below. ```const dummyPayload = { options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], }, {name: 'option name 2, data: ['sub option 1', 'sub option 2']}, ...repeating on and on ], };``` The below works, but is quite hard to read. This is a simplified example, and some of our responses have deeper nesting. ```const dummyResponsePact = Matchers.somethingLike({ options: Matchers.eachLike({ ...dummyPayload.options, data: Matchers.eachLike(dummyPayload.options[0].data[0]), }), });``` Without the `eachLike` matcher the provider tests fail with a variation of: `Actual array is too long and should not contain a Hash at $.options[1].data[1]` because the provider is doing an exact comparison between the objects (including length). The number of items the provider responds with in either array is variable because it comes from test db data.

matt.fellows
2019-03-26 20:34
I'm not sure it's an actual function assignment there, might want to expand it to make sure the value is a function that returns a promise, and not the value that function returns

matt.fellows
2019-03-26 20:35
I think the framework might be detecting that it's not a function and bails iut

matt.fellows
2019-03-26 20:37
`stateHandlers: {'Project in db': await states.projectInDb(token)}` should be something like `stateHandlers: {'Project in db': () => states.projectInDb(token)}`

krzysztof.stepniak
2019-03-27 07:43
ok, stack dissapeared but when promise is resolved? Since `projectInDb(token)` is async function. Is it resolved before proper tests?

matt.fellows
2019-03-27 07:46
the framework will wait for the promise to resolve. It wants a promise, not a value

krzysztof.stepniak
2019-03-27 07:47
ok, now i understand

matt.fellows
2019-03-27 07:47
Look at the e2e test example in the repository if you need a working example

krzysztof.stepniak
2019-03-27 07:47
m?kay

matt.fellows
2019-03-27 08:23
:thumbsup:

paras.vora
2019-03-27 08:34
has joined #pact-js

krzysztof.stepniak
2019-03-27 15:33
Ok guys I know I am harrasing you alot lately but I have another problem. This time with jenkins. Long story short on localhost pact tests works fine but on jenkins I have such thing on consumer side:

matt.fellows
2019-03-27 19:37
That doesn?t look to relate to Jenkins specifically, what is the runtime environment? If Alpine, do some searches as their are extra things you?ll need to make it work

vitaliy.grigoruk
2019-03-28 09:06
@krzysztof.stepniak Here: ``` [90m [36mPact Binary Error: /var/lib/jenkins/workspace/Contract tests/platform-e2e-test/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.63.0/lib/ruby/bin/ruby: line 14: tests/platform-e2e-test/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.63.0/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory ``` I?d avoid having spaces in a path. I belive you should just replace a space in ?/Contract tests/?

krzysztof.stepniak
2019-03-28 09:08
I?ll try

krzysztof.stepniak
2019-03-28 09:11
Yep, you were right. Thanks @vitaliy.grigoruk.

vtambourine
2019-03-28 14:01
has joined #pact-js

mboudreau
2019-03-29 01:09
good release that one :wink:

joseph.s.egan
2019-03-30 18:46
has joined #pact-js

krzysztof.stepniak
2019-04-01 07:04
Hi, guys. Have you ever had problem with provider side on jenkins? I struggling with it for two days and I starting to loose any hope wit resolving this issue. Test is setting up but after setting up state above Error shows. Certificates are set in provider side and ssl flag is set on false ( i see them in console log). Do you have any idea where should I look ?

matt.fellows
2019-04-01 07:07
Can you please share your setup and any/all log files. Haven't seen that before

matt.fellows
2019-04-01 07:08
Any reason why you need SSL?

krzysztof.stepniak
2019-04-01 07:11
do you need provider file ?

matt.fellows
2019-04-01 07:11
Well, not necessarily. I need to know as much as possible to help diagnose, so the more the merrier

krzysztof.stepniak
2019-04-01 07:12
btw. on localhost works fine on two different computers

krzysztof.stepniak
2019-04-01 07:13
Provider file

matt.fellows
2019-04-01 07:17
What's the value of providerBaseUrl?

krzysztof.stepniak
2019-04-01 07:19
depends of env but in this case https://api.platform-dev.silvair.com

matt.fellows
2019-04-01 07:23
And you say it works locally?

matt.fellows
2019-04-01 07:24
Are you running in docker or does that host not have the standard can bundle installed?

matt.fellows
2019-04-01 07:24
CA bundle*

krzysztof.stepniak
2019-04-01 07:24
yes, but on localhost connect with my local service

matt.fellows
2019-04-01 07:24
Right. What happens if you point to that host?

krzysztof.stepniak
2019-04-01 07:25
let me try, wait a sec

matt.fellows
2019-04-01 07:27
:+1:

matt.fellows
2019-04-01 07:27
I'm just hoping in a car and will check-in later

matt.fellows
2019-04-01 07:27
We need to know who h specific request at what point is failing.

krzysztof.stepniak
2019-04-01 07:27
well stack like on jenkins -_-?

matt.fellows
2019-04-01 07:28
I'd look to repro locally and go from there

krzysztof.stepniak
2019-04-01 07:28
mkay

matt.fellows
2019-04-01 19:33
Howd you go?

krzysztof.stepniak
2019-04-02 07:49
not good actually

matt.fellows
2019-04-02 07:50
Bugger

krzysztof.stepniak
2019-04-02 07:50
Im not sure why pact asks for localhost `Uncaught Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: localhost. is not in the cert's altnames: DNS:http://platform-dev.silvair.com, DNS:*.http://platform-dev.silvair.com`

matt.fellows
2019-04-02 07:50
Any reason why you don't do the provider testing on Jenkins like you do on your workstation - hit localhost?

krzysztof.stepniak
2019-04-02 07:51
it is different server

matt.fellows
2019-04-02 07:51
Why?

matt.fellows
2019-04-02 07:53
What's the contract file look like? Is there a host header in there set to localhost? That could explain why it's failing with a certificate mismatch but hitting the correct server

krzysztof.stepniak
2019-04-02 07:54
Do you want consumer side file or just contract?

matt.fellows
2019-04-02 07:54
Contract is fine. Specifically the interaction that fails if possible

krzysztof.stepniak
2019-04-02 07:55
ok

krzysztof.stepniak
2019-04-02 07:56
here is interaction:

krzysztof.stepniak
2019-04-02 07:59
what i Can see that states are done, but in the beginning of the interaction brokes

matt.fellows
2019-04-02 08:05
Nothing in that other interaction that is a cause for concern

matt.fellows
2019-04-02 08:05
The fact that it works locally is telling

matt.fellows
2019-04-02 08:05
There is something wrong with the Jenkins setup

krzysztof.stepniak
2019-04-02 08:05
naah

krzysztof.stepniak
2019-04-02 08:06
when im trying to start script from my pc against dev server the same error comes up.

matt.fellows
2019-04-02 08:06
Why can't you start up the provider on Jenkins like t you would locally?

krzysztof.stepniak
2019-04-02 08:06
I would need to setup docker with enviroment

matt.fellows
2019-04-02 08:07
How do you change provide states against a remote API?

krzysztof.stepniak
2019-04-02 08:07
Is there any problem with https on verify?

krzysztof.stepniak
2019-04-02 08:08
I didn?t change them

krzysztof.stepniak
2019-04-02 08:08
what I see in debug is that provider state is creating on localhost

krzysztof.stepniak
2019-04-02 08:09

krzysztof.stepniak
2019-04-02 08:11
but it use client to make request to dev db and create project

matt.fellows
2019-04-02 08:11
Sorry I'm just driving home but I might have an idea as to what it could be

krzysztof.stepniak
2019-04-02 08:12
ok, drive safely

matt.fellows
2019-04-02 11:52
Thanks. So I think we don't fully support proxying remote APIs (it's very much not a standard thing to do). If you don't mind submitting an issue that would be great. I'll take a look tomorrow to see if it's an easy fix

krzysztof.stepniak
2019-04-02 11:56
ok

matt.fellows
2019-04-02 19:35
Thx

laxmi.somni
2019-04-03 14:10
has joined #pact-js

adamgreen
2019-04-03 14:27
Apologies for the late reply Matt, i've not had much joy in the casting, being a bit new to TS/JS as I am. I'll wait and see how my Issue gets along in the mean time, hopefully it's an easy fix. Thanks again for the help :+1:

paras.vora
2019-04-04 12:51
Hello, there is a jwt authorization implemented in my project. Can anyone please help with any working code repo to deal with this scenario? Note - the life of the bearer token is only 3 mins.


paras.vora
2019-04-04 12:52
However, I am unable to figure out what would be the value of the `${token}` variable ?

vitaliy.grigoruk
2019-04-04 20:22
as people are normally running provider verification from within production codebase, it shouldn?t be an issue to call some method that generates a valid JWT token.

matt.fellows
2019-04-04 23:07
@paras.vora request filters lets you amend the request to the provider during provider side verification. How are you sending the JWT to the provider now? e.g. is it an authorization header?

matt.fellows
2019-04-04 23:08
whatever mechanism, request filters allow you to actually modify the entire request object - fields, headers etc.. So your job is to create a valid JWT (whether a ?real? one or a valid but fake one as @vitaliy.grigoruk notes) and then add it.

paras.vora
2019-04-05 07:03
@matt.fellows I have no way to generate a valid token & even I generate it, the token validation service wont be available for authorization at the time provider test is running.

matt.fellows
2019-04-05 10:06
So my suggestion is to stub the auth service during provider verification, so the contents of the JWT can be stored in the pact and there is no need for using those more complicated features

paras.vora
2019-04-05 10:32
@matt.fellows the authorization would fail anyways as the life of the token is only 3 mins.

matt.fellows
2019-04-05 10:35
So what can we do?

matt.fellows
2019-04-05 10:36
Why can't you generate a valid token?

matt.fellows
2019-04-05 10:41
If you can't generate a valid token, how could you ever test it? Can't you stub the auth service and send a dummy token?

paras.vora
2019-04-05 11:12
You mean mocking the authorization service

paras.vora
2019-04-05 11:12
?

vitaliy.grigoruk
2019-04-05 11:37
rather stubbing than mocking

matt.fellows
2019-04-05 11:55
But yes, whatever is easiest for you.

matt.fellows
2019-04-05 11:57
You want to test each component in isolation. If your provider has downstream dependencies, stub them out during testing and then apply the same contract testing process to them. Repeat this process until you get to the end of dependency chain

matt.fellows
2019-04-05 11:57
Voila, you have contract tests for your whole app and you don't have to setup an e2e environment to test it

mo.balghonaim
2019-04-08 00:45
has joined #pact-js

mo.balghonaim
2019-04-08 00:48
Hello, I'm trying to debug a failing provider verification. Is there a way to see outgoing request? I'm getting this test failure output:

mo.balghonaim
2019-04-08 02:23
I noticed that the `providerBaseUrl` I provided in the options passed to `verifyProvider()` has been overwritten with 'localhost', which is what responds with '503'. Does this proxy server make the actual call to my original `providerBaseUrl`?

asad
2019-04-08 07:45
Hi i am getting this `ERROR: The process "12956" not found.` issue on windows , when i run my pact consumer/provider test ``` [2019-04-08T07:33:55.650Z] INFO: pact-node@6.21.5/20088 on DESKTOP-KOB10PR: Created 'standalone\win32-1.63.0\bin\pact-mock-service.bat service --consumer 'afterfx' --pact_dir 'C:\xampp\htdocs\afterfx-service\tests\pacts' --host '127.0.0.1' --log 'C:\xampp\htdocs\afterfx-service\tests\pact logs\pact-tests.log' --pact-file-write-mode 'update' --port '8991' --provider 'prestac' --pact_specification_version '2'' process with PID: 12956 ERROR: The process "12956" not found. ``` weird thing is its working on other project on same device, it was working for above project too but because of some error jest did't terminated the test process and so i did `ctr+c` to end it and the error showed up afterwards.

matt.fellows
2019-04-08 08:46
I think a process might be hanging around.

matt.fellows
2019-04-08 08:46
Check to see if there are any dangling Ruby or Node processes

asad
2019-04-08 09:55
ok thank will look into it

matt.fellows
2019-04-08 11:25
yes, that is the case

matt.fellows
2019-04-08 11:26
you might get some more data by turning the log level up to ?DEBUG? or better, but we may need more instrumentation to help with it.

matt.fellows
2019-04-08 11:26
Is the broker URL external to the local host / running a cert?

mo.balghonaim
2019-04-08 20:03
Hello, it seems like I'm missing a required header or something, because I tried it with a different API and it seems to work. I'll re-ask the question if it appears to be an issue with the framework. Thanks!

simon.nizov
2019-04-10 08:47
has joined #pact-js

rjmcguinness
2019-04-10 10:32
Do you have any recommendations for matching arrays, particularly nested arrays? For example, I have a payload object with a property `options` which is an array of objects each of which have an array `data` as a property, see below. ```const dummyPayload = { options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], }, {name: 'option name 2, data: ['sub option 1', 'sub option 2']}, ...repeating on and on ], };``` The below works, but is quite hard to read. This is a simplified example, and some of our responses have deeper nesting. ```const dummyResponsePact = Matchers.somethingLike({ options: Matchers.eachLike({ ...dummyPayload.options, data: Matchers.eachLike(dummyPayload.options[0].data[0]), }), });``` Without the `eachLike` matcher the provider tests fail with a variation of: `Actual array is too long and should not contain a Hash at $.options[1].data[1]` because the provider is doing an exact comparison between the objects (including length).

simon.nizov
2019-04-10 11:25
@simon.nizov has left the channel

andrew.nicholson
2019-04-11 19:36
has joined #pact-js

rjmcguinness
2019-04-12 08:27
@matt.fellows are you able to answer this? I feel like this isn?t the way I should be doing things, to just provide a ?1 or more of this item in the array? matcher

matt.fellows
2019-04-12 08:50
Will take a look at bit later. Happy to help (just cooking tea :grinning:)

rjmcguinness
2019-04-12 10:30
Thanks :slightly_smiling_face:

matt.fellows
2019-04-12 10:59
Have you tried simply ``` like({ options: [ { name: 'option name 1', data: ['sub option 1', 'sub option 2', 'sub option 3'], } ], }) ``` Matchers should propagate down to nested arrays, so you shouldn?t need to repeat yourself

rjmcguinness
2019-04-12 11:00
like() is an alias to somethingLike, correct? I tried this but still need the eachLike to say min 1 from the array/matching an item in the array

matt.fellows
2019-04-12 11:02
what is it doing instead?

rjmcguinness
2019-04-12 11:05
It spits out the pact as expected, just without the array matching rules. So our provider has to have the same amount of items in that array in their fixtures for it to validate

matt.fellows
2019-04-12 11:05
hmm I?ll double check this behaviour, it sounds suspicious

rjmcguinness
2019-04-12 11:14
I would think this is expected behaviour as per https://github.com/pact-foundation/pact-js#match-based-on-arrays These are the matchers that eachLike produces: ``` "$.body.propertyA[*].something": { "min": 1 }, "$.body.propertyA[*].something[*].*": { "match": "type" }, ``` Without eachLike we would only have: ``` "$.body": { "match": "type" }, ``` which matches everything recursively, but requires the response?s arrays to have the same lengths as those in the pact

matt.fellows
2019-04-12 11:18
Yep. It?s the verification side I was hoping that would propagate, but I guess not

matt.fellows
2019-04-12 11:19
I?m checking with maintainers, it would certainly be nice if we could have a matcher that did this

matt.fellows
2019-04-12 13:33
Np

vitaliy.grigoruk
2019-04-15 10:31
Hey @matt.fellows. What do you think about ?un-deprecating? `providerStatesSetupUrl` (so either `providerStatesSetupUrl` or `handlers` needs to be passed to pact verifier, but not both)? I know that a new way to setup provider state is to specify state handlers. This will work for majority of projects I guess. In a project I?m working on right now we need to ensure each pair of `state setup + test request` run within `sequelize` transaction (so, DB is left untouched after test run). We managed to implement a desired setup using pact v7 (basically, we are running our own proxy server, heavily inspired by your work on `handlers`). Now, pact v8 is released with its own proxy for state handling and v7 doesn?t get security updates anymore. We would like to run on the latest version, but we can?t as our implementation of state + transaction handling won?t work with pact v8. The simplest solution I see is to still allow people to use `providerStatesSetupUrl` if `requestFilters` and `stateHandlers` are not enough. I?ll be happy to make a PR if you?re ok with the proposal

asite-rshah
2019-04-15 11:22
has joined #pact-js

matt.fellows
2019-04-15 20:52
I saw your PR, I?ll answer there. I need to think about it, but thanks for the feedback. Perhaps others have the need also.

martin.green
2019-04-16 15:47
has joined #pact-js

marc
2019-04-17 13:28
has joined #pact-js

nodkane12
2019-04-17 14:23
has joined #pact-js

albertot
2019-04-18 16:35
has joined #pact-js

albertot
2019-04-18 16:47
(Moved to #general)

mitchell.davis
2019-04-23 06:51
has joined #pact-js

jjlehva
2019-04-25 12:37
hey, should I use `pact-js` or `pact-node`? What is the difference?

vitaliy.grigoruk
2019-04-25 12:40
use pact-js (it uses pact-node as a dependency)

jjlehva
2019-04-25 12:40
ok, thanks :+1:

jjlehva
2019-04-25 12:41
is there some purpose of having both of them? :smile:

vitaliy.grigoruk
2019-04-25 12:46
long term goal AFAIK is to get rid of pact-node

vitaliy.grigoruk
2019-04-25 12:46
pact-node is a wrapper for pact-ruby-standalone binaries

vitaliy.grigoruk
2019-04-25 12:47
while pact-js is a DSL to use in your JS / TS CDC test suites

vitaliy.grigoruk
2019-04-25 12:47
Hey folks, could somebody explain me the difference between `tags` and `consumerVersionTag` here? https://github.com/pact-foundation/pact-js/blob/master/src/dsl/verifier.ts#L40-L45

vitaliy.grigoruk
2019-04-25 12:54
I?m trying to figure out the right setup for triggering provider verification CI job for a recently updated consumer contract. I?m tagging my contracts with branch names and versioning them with ?git commit sha?. My pact broker webhook passes contract tag (e.g. `master`) when it triggers provider contract verification CI job. This works well with 1 consumer, but doesn?t work so well if I have 2+ consumers (as I?ll run contract verification for all consumers). Ideally, I?d like to be able to pass consumer name, but such option doesn?t exist.

vitaliy.grigoruk
2019-04-26 10:47
ok, after some investigation I found out that `tags` are not used at all in `pact-provider-verifier` and `consumerVersionTag` actually can be an array. Here is a PR to fix this in pact-node: https://github.com/pact-foundation/pact-node/pull/155 I?ll appreciate fast feedback on this one.

matt.fellows
2019-04-26 13:21
Thanks for all of your digging / support. The changes merged are now released (8.2.2). I?ll wait for review of this change before sending it out.

ian.mcwilliams
2019-04-29 12:05
has joined #pact-js

ian.mcwilliams
2019-04-29 12:07
hey all :wave: i am setting up a kafka test and using `messagePact` `.withContent`; so the object from there is passed into the handler specified in `.verify(handlerFunction)`

ian.mcwilliams
2019-04-29 12:09
when the object is passed to the handler it is wrapped in `contents` (eg `{ contents: [object] }`) - i don't think it's right to expect the handler to deconstruct the contents, does anyone have a way of managing this more cleanly?

ian.mcwilliams
2019-04-29 12:11
```describe('receive record', () => { it('accepts a valid record', async () => { return ( messagePact .expectsToReceive('a valid record') .withContent({ data: { feed_date: term({generate: "2019-01-01", matcher: "^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$"}), item: { record_id: 123, record_name: like('someRecord') } } }) .verify(handlerFunction) ); }); });```

paras.vora
2019-04-29 12:50
Hello, my Chrome is getting crashed frequently upon running the tests frequently.

paras.vora
2019-04-29 12:51
Please check the error....

matt.fellows
2019-04-29 12:53
What has this got to do with Pact, exactly?

matt.fellows
2019-04-29 15:42
There are a couple of helpers that wrap this for you e.g. `synchronousBodyHandler`

matt.fellows
2019-04-29 15:42
You wouldn?t want your domain code handling this, no

matt.fellows
2019-04-29 15:43
It?s provided to allow access to the metadata, which we?ll eventually (in JS at least) validate

pascal.wilbrink
2019-04-29 20:35
has joined #pact-js

pascal.wilbrink
2019-04-29 20:37
Hi all, it seems that my karma config is not setup correctly. But i'm using the same setup as all the examples i can find (I think). The pact-mock-server is starting correctly, but none of my tests are ran. Did this happen to anyone else? My setup: ``` const path = require('path') module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular-devkit/build-angular', 'pact'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('@angular-devkit/build-angular/plugins/karma'), require('@pact-foundation/karma-pact') ], client: { clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { dir: require('path').join(__dirname, '../../coverage/movies-lib'), reports: ['html', 'lcovonly'], fixWebpackSourcePaths: true }, files: [ 'node_modules/@pact-foundation/pact-web/pact-web.js', ], reporters: ['progress', 'kjhtml'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, restartOnFileChange: false, pact: [{ cors: true, port: 1234, dir: "pacts/", spec: 2, log: path.resolve(process.cwd(), 'logs', 'pact.log') }], proxies: { '/api/': 'http://localhost:1234/' } }); }; ```

pascal.wilbrink
2019-04-29 20:41
when i run the test (ng test --project movies-lib) i see this: ```29 04 2019 22:37:23.668:INFO [pact]: Pact Mock Server running on port: 1234```

pascal.wilbrink
2019-04-29 20:50
it's working now, i had to delete my node_modules and re-install them again

paras.vora
2019-04-30 06:49
@matt.fellows Wrong window. Sorry.

ian.mcwilliams
2019-04-30 08:03
I see - yes that's worked, thanks @matt.fellows :+1:

jjlehva
2019-04-30 09:54
has anyone been able to get `pact-js` working with `jest` ? Jest is always finishing before the `afterAll` part where I call the `finalize()` etc. Something really strange going on. I am about to give up :sweat_smile:

jjlehva
2019-04-30 09:55
I got pact to properly create the contracts but Jest still just prints errors such as `Cannot log after tests are done. Did you forget to wait for something async in your test?`

yousafn
2019-04-30 10:03
yeah i run all my pact tests with jest

jjlehva
2019-04-30 10:03
and I am also getting this every time `setup` and `finalize` are called: ``` console.warn node_modules/request-promise/node_modules/bluebird/js/release/debuggability.js:873 Unhandled rejection RequestError: Error: connect ECONNREFUSED 127.0.0.1:6060 at new RequestError (/Users/user/workspace/project/node_modules/request-promise-core/lib/errors.js:14:15) at Request.plumbing.callback (/Users/user/workspace/project/node_modules/request-promise-core/lib/plumbing.js:87:29) at Request.RP$callback [as _callback] (/Users/user/workspace/project/node_modules/request-promise-core/lib/plumbing.js:46:31) at self.callback (/Users/user/workspace/project/node_modules/request/request.js:185:22) at Request.emit (events.js:189:13) at Request.Object.<anonymous>.Request.onRequestError (/Users/user/workspace/project/node_modules/request/request.js:877:8) at ClientRequest.emit (events.js:189:13) at Socket.socketErrorListener (_http_client.js:392:9) at Socket.emit (events.js:189:13) at emitErrorNT (internal/streams/destroy.js:82:8) at emitErrorAndCloseNT (internal/streams/destroy.js:50:3) at process._tickCallback (internal/process/next_tick.js:63:19) ```


jjlehva
2019-04-30 10:04
cool! thanks, I?ll have a look

yousafn
2019-04-30 10:05
feel free to share any example code and we can have a look at it


jjlehva
2019-04-30 10:10
I had a look at this but I didn?t get much out of it

jjlehva
2019-04-30 10:11
I didn?t really like the idea of setting things to the global scope etc. I tried the approach though and had the same result :smile:

jjlehva
2019-04-30 12:50
so I wasn?t able to figure out why the tests were not working properly with Jest. No idea really. I had two of my colleagues also trying to figure it out with no luck

jjlehva
2019-04-30 12:51
I ended up also refactoring the test to a simple node script that runs everything in a promise chain in the correct order. That worked OK

jjlehva
2019-04-30 12:52
after that I tried using nyc and mocha. So I simply changed the `afterAll` to `after` and `beforeAll` to `before`. And surprisingly the test just works :shrug:

jjlehva
2019-04-30 12:53
so `node` and `mocha` are ok but `jest` just fails to those `ECONNREFUSED` and `Cannot log after tests are done` errors

krzysztof.stepniak
2019-04-30 12:56
@yousafn did you just post working example with sending file on github?

yousafn
2019-04-30 12:57
I did chap

yousafn
2019-04-30 12:57
just had to get it working for a client at work, so thought I would pass back my learnings!

krzysztof.stepniak
2019-04-30 12:59
Cool, thanks. I?ll try it in node :stuck_out_tongue:.

yousafn
2019-04-30 13:05
gimme two secs and ill post up an edit

krzysztof.stepniak
2019-04-30 13:06
Sure

yousafn
2019-04-30 13:11
just tested this now so should be good to go, updated comment on your issue too

ian.mcwilliams
2019-04-30 14:54
aren't beforeAll and afterAll jasmine rather than jest?

rjmcguinness
2019-04-30 15:10
They?re in both

abubics
2019-04-30 22:58
Last time I tried, Jest didn't properly nest befores and afters (but mocha does)... So I usually fall back to mocha for sanity :sweat_smile:

bethskurrie
2019-04-30 23:21
I had a feeling @tjones had done a pact-jest "plugin", but only in a private project.

matt.fellows
2019-04-30 23:27
He just has his way of using (DRYing) it, from memory. It?s probably documented in a GitHub issue/enhancement somewhere

tjones
2019-04-30 23:41
Yep, I wrote a small wrapper that gives a DRYer and slightly nicer (in my opinion) DSL.

tjones
2019-04-30 23:41
I *think* it?s on an issue in pact-js

tjones
2019-04-30 23:41
And if not, I can dig it up and post it here

bethskurrie
2019-04-30 23:41
Hello Tim! We miss you!

tjones
2019-04-30 23:41
I?ve been planning to make it a module

tjones
2019-04-30 23:41
Hello! I miss you all too!

tjones
2019-04-30 23:42
I?ll be back next week. I think? How does time work?

tjones
2019-04-30 23:42
The 8th

bethskurrie
2019-04-30 23:42
Woot!

tjones
2019-04-30 23:49
Scrolling up- I?ve had no issues with running pact through Jest, but it?s worth noting that Jest runs suites in parallel by default. It?s easiest to turn this off, or write a wrapper so you don?t have collisions

tjones
2019-04-30 23:49
(If you have multiple pact suites)

tjones
2019-04-30 23:50
Also: I find that *not* running Jest tests in parallel results in faster execution time on my machine (recent MacBook Pro). I haven?t looked in to why this is.


tjones
2019-04-30 23:54
I think I have a more recent version that is better. This version can result in overwriting log files if you have multiple pact suites

tjones
2019-04-30 23:55
It?s hard to solve that without having opinions on what does and doesn?t go in a test suite (eg, should each provider/consumer combo be only one test suite?).

tjones
2019-04-30 23:59
I?d really like to improve the wrapper and release a module that you can import and not have to write so much boilerplate, but I?m not yet sold on where to draw the line on conventions that are generally useful vs what is useful if you are me (which I assume you aren?t)

ian.mcwilliams
2019-05-01 08:19
i'm now struggling to debug what seems like quite a general message, i've been through and double checked everything and it all seems to be working - in fact it works fine running normally, it's failing when i try to run it in a container (trying to add kafka tests to CI) - the container itself appears to be handling things just fine

ian.mcwilliams
2019-05-01 08:19
``` Timeout - Async callback was not invoked within the 10000ms timeout specified by jest.setTimeout. 16 | 17 | describe('receive item', () => { > 18 | it('accepts a valid item', async () => { | ^ 19 | return (messagePact 20 | .expectsToReceive('a valid item record') at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:92:20) at http://Suite.it (__tests__/contract/kafka-client.test.pact.js:18:3) at Object.describe (__tests__/contract/kafka-client.test.pact.js:17:1)```

ian.mcwilliams
2019-05-01 08:24
the verify method in messagePact is returning a Promise

ian.mcwilliams
2019-05-01 08:24
```.verify(synchronousBodyHandler(handlerFunction))```

ian.mcwilliams
2019-05-01 08:25
the handlerFunction itself is returning a raw object

matt.fellows
2019-05-01 08:38
Which part is running in the container? (the whole lot?) I?d check a couple of things: 1. Ports / expose (running on `127.0.0.1` will prevent it from being exposed out of the container) 2. If `./node_modules` is being shared, there might be a binary incompatibility if your host is a different os/arch (e.g. linux docker image with Mac OSX host). Make sure to `npm i` in the container to ensure native deps

ian.mcwilliams
2019-05-01 09:38
yeah, the whole thing is running in container, no ports need to be exposed; i'm seeing output straight from stdout from within the container

ian.mcwilliams
2019-05-01 09:40
a volume is being shared between host machine and container so i can get to my code from within the container; but i removed node_modules and ran yarn install from inside the container - it's part of the build command: `docker-compose run backend sh -c 'yarn && yarn db:rebuild && yarn test:contract'`

ian.mcwilliams
2019-05-01 09:41
to remove node_modules i ran it as:

ian.mcwilliams
2019-05-01 09:41
```docker-compose run backend sh -c 'rm -rf node_modules && yarn && yarn db:rebuild && yarn test:contract' ```

ian.mcwilliams
2019-05-01 10:26
i'm looking at this with our devops lead, it seems like there's a difference in the config being called - it's test in local, dev in the container, so perhaps this is the root of the issue

matt.fellows
2019-05-01 11:12
ok interesting

matt.fellows
2019-05-01 11:12
If you have an example I can use to repro I?d happily take a look for you

matt.fellows
2019-05-01 11:12
Unfortunately a bit hard going off the detaili so far

ian.mcwilliams
2019-05-01 11:23
have lined up the local vs container and no change, it passes locally but fails in container

ian.mcwilliams
2019-05-01 11:23
i'll see what i can do to provide a concrete example

matt.fellows
2019-05-01 11:25
thanks

matt.fellows
2019-05-01 11:25
sorry hear - what a pain!

matt.fellows
2019-05-01 11:25
oh, what?s the container image?

matt.fellows
2019-05-01 11:25
(sorry I?ve been at a conference all week, so my responses are often bursty and from a mobile)

matt.fellows
2019-05-01 11:26
s/been/am


ian.mcwilliams
2019-05-01 11:33
we've switched from alpine previously as it wouldn't run ruby

ian.mcwilliams
2019-05-01 11:33
now using node:10-slim

ian.mcwilliams
2019-05-01 11:33
here's a stripped down version of the test file - this has the same result (passes local, fails container)

matt.fellows
2019-05-01 11:37
perfect thanks - I?ll look shortyl

matt.fellows
2019-05-01 11:37
regarding alpine, see above for how to make it work (tl;dr - needs bash)

andrewspinks
2019-05-01 23:18
has joined #pact-js

jjlehva
2019-05-02 07:46
is it not possible to have a matcher for values which can be either `string` or `null` ? Or `number` or `null` ?


matt.fellows
2019-05-02 07:47
It's not, see the FAQ at doc'http://s.pact.io as to why

matt.fellows
2019-05-02 07:47
:point_up::laughing:

jjlehva
2019-05-02 07:55
Ok, makes sense. Thanks for the fast response :smile:

matt.fellows
2019-05-02 07:55
:ok_hand:

jjlehva
2019-05-02 07:56
I am just about to finish writing my thesis about consumer-driven contract testing and I still managed to miss / forget about that :face_with_rolling_eyes:

matt.fellows
2019-05-02 07:57
Hehe np

yousafn
2019-05-02 11:12
Hey Tim, I started work on publishing an npm module, based on your initial proposal, as we needed to cut down on the boilerplate stuff we are writing at work as the amount of services we are covering keeps growing Adapter is here https://github.com/YOU54F/jest-pact A repo using it https://github.com/YOU54F/jest-pact-typescript I am building up a little toolset that we can use across our work projects, as we have common pact scripts used in all repos and it?s becoming a pain to maintain them all!

matt.fellows
2019-05-02 11:49
did you have the docker container for that too?

matt.fellows
2019-05-02 12:09
package.json ``` { "name": "ian", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "jest" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@pact-foundation/pact": "^8.2.2", "jest": "^24.7.1" } } ``` Dockerfile: ``` FROM node:8-alpine RUN apk add --no-cache --virtual build-dependencies build-base RUN apk --no-cache add ca-certificates wget bash \ && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \ && apk add glibc-2.29-r0.apk WORKDIR /app COPY package*.json /app/ RUN npm install COPY . /app/ RUN npm t ``` Run the following: `docker build .`

matt.fellows
2019-05-02 12:09
works ok for me: ``` > jest [2019-05-02T12:07:03.905Z] INFO: pact@8.2.2/15 on a08d3744bcf1: Verifying message [2019-05-02T12:07:03.909Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: Creating Message [2019-05-02T12:07:03.910Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: Creating message pact [2019-05-02T12:07:03.923Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: Created './standalone/linux-x64-1.64.1/bin/pact-message 'update' '{"description":"a valid item record","contents":{"data":{"dummy":1}}}' --consumer 'some-consumer' --pact_dir '/app/__tests__/pacts' --provider 'some-provider' --pact_specification_version '3'' process with PID: 45 PASS __tests__/kafka-client.test.pact.js receive item ? accepts a valid item (632ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 2.803s Ran all test suites. [2019-05-02T12:07:04.531Z] INFO: pact-node@8.2.0/15 on a08d3744bcf1: ```

matt.fellows
2019-05-02 12:12
Working repo


joostvanwollingen
2019-05-02 13:00
has joined #pact-js

dagarwal
2019-05-02 15:35
Hi , I have generated json using pact test but then request is giving me 404 , can you point me to what am i missing here ? ==> Received request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sort?: [?desc?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sortBy?: [?Last_Modified?], ?status?: [?failed?, ?cancelled?]}), headers: Some({?User-Agent?: ?Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36?, ?Access-Control-Request-Headers?: ?content-type?, ?Host?: ?127.0.0.1:18159?, ?Access-Control-Request-Method?: ?GET?, ?Origin?: ?http://localhost:4200?, ?Connection?: ?keep-alive?, ?Accept-Encoding?: ?gzip, deflate, br?, ?Accept?: ?*/*?, ?Referer?: ?http://localhost:4200/fmp/index?, ?Accept-Language?: ?en-US,en;q=0.9"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [INFO] | 15:29:19 [INFO] comparing to expected request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sortBy?: [?Last_Modified?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sort?: [?desc?], ?status?: [?failed?]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: {?query?: Category { name: ?query?, rules: {?status[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?criteria[0]?: RuleList { rules: [Regex(?first_load?)], rule_logic: And }, ?sort[0]?: RuleList { rules: [Regex(?desc|asc?)], rule_logic: And }, ?sortBy[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?lastModifiedFrom[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }} }} }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [WARN] No matching request found, sending 404 Not Found flex-usersetting-service | 15:29:19 [INFO]

abubics
2019-05-02 23:54
Nothing obvious to me

abubics
2019-05-02 23:54
the matchers look like it should work ``` ==> Received request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sort?: [?desc?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sortBy?: [?Last_Modified?], ?status?: [?failed?, ?cancelled?]}), headers: Some({?User-Agent?: ?Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36?, ?Access-Control-Request-Headers?: ?content-type?, ?Host?: ?127.0.0.1:18159?, ?Access-Control-Request-Method?: ?GET?, ?Origin?: ?http://localhost:4200?, ?Connection?: ?keep-alive?, ?Accept-Encoding?: ?gzip, deflate, br?, ?Accept?: ?*/*?, ?Referer?: ?http://localhost:4200/fmp/index?, ?Accept-Language?: ?en-US,en;q=0.9"}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [INFO] | 15:29:19 [INFO] comparing to expected request: Request { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: Some({?sortBy?: [?Last_Modified?], ?lastModifiedFrom?: [?24 Apr 2019"], ?criteria?: [?first_load?], ?sort?: [?desc?], ?status?: [?failed?]}), headers: None, body: Missing, matching_rules: MatchingRules { rules: { ?query?: Category { name: ?query?, rules: { ?status[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?criteria[0]?: RuleList { rules: [Regex(?first_load?)], rule_logic: And }, ?sort[0]?: RuleList { rules: [Regex(?desc|asc?)], rule_logic: And }, ?sortBy[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And }, ?lastModifiedFrom[0]?: RuleList { rules: [Regex(?.*?)], rule_logic: And } } } } }, generators: Generators { categories: {} } } flex-usersetting-service | 15:29:19 [WARN] No matching request found, sending 404 Not Found flex-usersetting-service | 15:29:19 [INFO] ```

abubics
2019-05-02 23:54
I'd recommend using the formatting markup to make it easier for people to help you, btw :slightly_smiling_face:

matt.fellows
2019-05-03 01:32
That JSON looks to have AND matchers - did you generate the Pact from a v3 spec (e.g. Java)?

matt.fellows
2019-05-03 01:32
JS does not support the v3 spec yet

dagarwal
2019-05-03 08:12
I generated it with JS v2 spec

dagarwal
2019-05-03 08:12
Can this be the reason ?status?: [?failed?, ?cancellled?] ?

matt.fellows
2019-05-03 08:19
Can you please share the test? Generators and RuleList don't look like things JS can support

matt.fellows
2019-05-03 08:19
Is this a consumer or provider test?

matt.fellows
2019-05-03 08:20
It looks like a library that can deal with Optional types has made this, which is why I think JVM is involved (e.g. Scala or Kotlin)

dagarwal
2019-05-03 08:21
consumer test

dagarwal
2019-05-03 08:21
describe(?Get the user profile?, () => { before(() => provider.addInteraction({ given: ?GET call to get user profile?, uponReceiving: ?Get call for user profile?, withRequest: { method: ?OPTIONS?, path: ?/header/api/user/profile?, query: { lastModifiedFrom: term({ generate: ?24 Apr 2019?, matcher: ?.*? }), sort: term({ generate: ?desc?, matcher: ?desc|asc? }), sortBy: term({ generate: ?Last_Modified?, matcher: ?.*? }), criteria: term({ generate: ?first_load?, matcher: ?first_load? }), status: term({ generate: ?failed?, matcher: ?.*? }) } }, willRespondWith: { status: 200, headers: { ?Access-Control-Request-Headers?: ?content-type?, ?Referer?: ?http://localhost:4200/fmp/index', ?Access-Control-Request-Method?: ?GET? }, body: userProfile } })); it(?should generate data for user profile?, () => request.options(`http://localhost:${PORT}/header/api/user/profile?lastModifiedFrom=24 Apr 2019&sort=desc&sortBy=Last_Modified&criteria=first_load&status=failed`) .set({ Accept: ?application/json? }) .then((response) => { expect(response.statusCode).to.equal(200); }) .catch((err) => { console.log(?Error in generating user profile?, err); })); });

matt.fellows
2019-05-03 08:33
What does `userProfile` look like?

matt.fellows
2019-05-03 08:34
Is this a failure on the consumer or provider test?

dagarwal
2019-05-03 08:35
consumer is generating the json . but when its compared to the provider side ..it fails

dagarwal
2019-05-03 08:35
as the requests are not matched

matt.fellows
2019-05-03 08:37
is the proovider a JVM one?

dagarwal
2019-05-03 08:39
no its also in js .Plus I am using it through pact stub server

matt.fellows
2019-05-03 08:57
Aha! Ok the response we are seeing is coming from rust, that helps

matt.fellows
2019-05-03 08:58
The stub server is rust, just FYI

matt.fellows
2019-05-03 08:58
So your provider is not sending a request to the stub server that it recognises

dagarwal
2019-05-03 08:58
ok i dint know stub server is rust .

dagarwal
2019-05-03 08:58
then what i need to change in the request?

matt.fellows
2019-05-03 09:01
I'm on a mobile so it's hard to see, and about to fly out of Sydney so will be afk soon. Looks like it's expecting order and orderBy query strings (and you're only sending one of them) but not sure. Find out what's the minimum request to the stub server and then work backwards from there

matt.fellows
2019-05-03 09:02
Your provider API is the problem, not the consumer

dagarwal
2019-05-03 09:03
okay will try and keep you posted

matt.fellows
2019-05-03 09:04
:+1: thanks

dagarwal
2019-05-03 09:07
thanks to you :slightly_smiling_face: but i will bother you again :stuck_out_tongue:

matt.fellows
2019-05-03 09:07
Haha I'm sure :laughing:

krzysztof.stepniak
2019-05-06 09:05
Well I tried your way but it doesn?t work for me. :confused:

asad
2019-05-07 08:55
hey anyone have idea about this error ``` FAIL tests/provider.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 2 | beforeAll(done => provider.setup().then(() => done())); 3 | > 4 | afterAll(done => provider.finalize().then(() => done())); | ^ 5 | at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.finalize (tests/config/pactTestWrapper.js:4:27) ``` i have 2 different projects consumer/provider test are working on one but on other one m getting above error

asad
2019-05-07 08:57
complete output when i run consumer/provider tests

matt.fellows
2019-05-07 09:07
Is provider being shared across the different consumer/providers? (It shouldn't)

matt.fellows
2019-05-07 09:08
I'd you share your code I can take a peek later

asad
2019-05-07 09:17
no its, and it was typical issue, somehow a node event was left kept running and was not detached, so when i tried to run again it gave , got it fixed by removing dangling node events

asad
2019-05-07 09:17
thank for reply though much appreciated :slightly_smiling_face:

asad
2019-05-07 09:31
or scratch the above comments its still there, No provider is not being shared

asad
2019-05-07 09:37
a quick question should i make different file for each consumer test of one service?

matt.fellows
2019-05-07 10:24
(Sorry I just got home an hour ago so will be intermittent with my responses)

matt.fellows
2019-05-07 10:24
I would generally have at _least_ one file per consumer/provider pair

matt.fellows
2019-05-07 10:25
I wouldn?t have multiple consumers of a provider in a single file.

matt.fellows
2019-05-07 10:25
But that is just how you organise code

matt.fellows
2019-05-07 10:28
In any case, the only thing I can think of is that you aren?t calling `provider.setup()` somewhere as that?s where that assignment is made

asad
2019-05-07 11:01
only one service is giving that issue other services are running consumer/provider tests fine.

asad
2019-05-07 11:01
i have a file named pactTestWrapper.js with following content ``` /* eslint-disable no-undef */ beforeAll(done => provider.setup().then(() => done())); afterAll(done => provider.finalize().then(() => done())); ```

asad
2019-05-07 11:02
and command m using to run provider/consumer tests is as follow ``` "test:provider": "jest --testRegex \"/*(provider.pact.js)\" --runInBand --setupFiles ./tests/config/pactSetup.js --setupTestFrameworkScriptFile=./tests/config/pactTestWrapper.js" ```

asad
2019-05-08 07:56
also when i run the consumer test even if it gives error, it still create the pact file (with changes if any)

asad
2019-05-08 09:06
also getting this error in that project `ERROR: The process "2480" not found.`

matt.fellows
2019-05-08 11:40
So if it's working for the other projects you need to find out what's different. Are you using different ports etc?

asad
2019-05-08 13:48
no configurations are same for all projects, i further debug it and found out if the project path is shorter (`C:\xampp\htdocs\afterfx-service` changed to `C:\afterfx-service`) than atleast consumer tests are working but provider tests gives an error. (file with output of console attached)

asad
2019-05-08 13:48
even thought other projects are in same directory level (`C:\xampp\htdocs\{project}`) but still working

noel.yap_slack.pact.i
2019-05-08 16:47
has joined #pact-js

asad
2019-05-10 10:28
tried solutions mentioned in this https://github.com/pact-foundation/pact-js/issues/237 Windows registry hack or moving to shallower path both did't worked :confused:

james.hattersley-dyke
2019-05-10 10:35
has joined #pact-js

james.hattersley-dyke
2019-05-10 10:41
@asad I'm having the exact same error, everything works on my local machine even when running in a Docker container. Yet CI machine dumps out the same error as yours

asad
2019-05-10 10:42
its bit more weird that with same configurations its working in other projects on local and in same directory level i have 4 different service it works in other 3 but 1 gives that error

asad
2019-05-10 10:43
tried debuging and when i moved that project with error to less shallow directory consumer tests start working but now provider test giving error < https://github.com/pact-foundation/pact-js/issues/237 > tried both solutions from that issue (window registry and moving to less shallow path still same error)

matt.fellows
2019-05-10 10:44
Is CI windows too?

matt.fellows
2019-05-10 10:44
Thanks for the debugging @asad, nicely done

james.hattersley-dyke
2019-05-10 10:45
no, linux. What's really odd is that everything works fine on Windows dev machine and a linux dev machine, also in a Docker container running on the Linux dev machine using the same imge as the CI machine

matt.fellows
2019-05-10 10:45
One possibility is that the test that is failing has something different in the contract (e.g. provider state or something). It looks like Ruby needs another file to service that request which takes the path over the limit

matt.fellows
2019-05-10 10:46
Interesting

james.hattersley-dyke
2019-05-10 10:46
I also see this ```36mPact Binary Error: /var/lib/jenkins/jobs/FE Fragment Product/branches/pact-testing/workspace@2/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.64.1/lib/ruby/bin/ruby: line 14: Fragment: command not found```

james.hattersley-dyke
2019-05-10 10:46
on CI

matt.fellows
2019-05-10 10:46
Of you can share a repro I'm happy to look. Linux should be very stable, windows is the problematic OS for reasons that should be obvious

matt.fellows
2019-05-10 10:47
Looks like a space in the path is causing issues


asad
2019-05-10 10:51
thought issue is still there :confused: will try it on linux env and see what happens

matt.fellows
2019-05-10 10:51
Thanks yep

matt.fellows
2019-05-10 10:51
Can you try removing spaces from the project path?

james.hattersley-dyke
2019-05-10 10:51
I could, but that's a jenkins workspace

james.hattersley-dyke
2019-05-10 10:53
OK renamed the project... probably gonna get lambasted by the other devs

james.hattersley-dyke
2019-05-10 11:01
that rename got me a bit further

james.hattersley-dyke
2019-05-10 11:03
wow worked!

james.hattersley-dyke
2019-05-10 11:03
Pact file was corrupted so the next build failed, the one after didn't though

james.hattersley-dyke
2019-05-10 11:04
@asad FWIW I had spaces in the file path to the ruby binary - removing those and doing a couple of rebuilds worked

asad
2019-05-10 11:11
hmm contract seems fine to me, only thing i can think is that i dont have state_handler (which is optional) so it could be cuz of that it needs extra file to handle that situation. i have attached my provider code and contract generated by consumer service.

asad
2019-05-10 11:14
@james.hattersley-dyke thank for the hint , thought given other services works on same local env i doubt there will be something wrong with anything with global settings

james.hattersley-dyke
2019-05-10 11:15
I'd just check your project paths don't contain any spaces or odd characters

asad
2019-05-10 11:27
my project is in `C:/afterfx-service` and this is the error i am getting after moving project to less shallow path ```C:/afterfx-service/node_modules/@pact-foundation/pact/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.21.0/lib/pact/provider_verifier/app.rb:3:in `require' : cannot load such file -- pact/provider_verifier/provider_states/remove_provider_states_header_middleware (LoadError) ``` still digging to solve the issue

matt.fellows
2019-05-10 11:32
ok, good to hear that worked (but not so good that spaces cause issues. I?ll raise an issue once I can repro it properly)

matt.fellows
2019-05-10 11:37
Thanks. Might be worth adding a state handler to see if that helps, but looks like the standard path length issue on Windows

matt.fellows
2019-05-10 11:38
There is an e2e example in the pact-js repository. If you can get the appveyor build to fail with the same issue, then raise an issue and we can dig into it


asad
2019-05-10 12:50
ok thank i will look into it

asad
2019-05-13 08:55
tested on linux environment with same configs and its working

asad
2019-05-13 08:55
can't seems to reproduce this issue other than that service :stuck_out_tongue:

asad
2019-05-13 08:56
will update you if i find any solid point for it to fail only in that service.

matt.fellows
2019-05-13 11:40
thanks Asad

asad
2019-05-13 13:45
np, thank to you for creating and maintaining suck a great thing :slightly_smiling_face: :+1:

phall
2019-05-13 17:20
has joined #pact-js

scott.riley111
2019-05-13 17:35
has joined #pact-js

matt.fellows
2019-05-13 21:10
You?re welcome

krzysztof.stepniak
2019-05-14 06:39
Guys, i have question. I have generated contract and after publishing it, tests are in different order than previously were on my machine. Is it intentional?

bethskurrie
2019-05-14 06:42
Yes. If you have tests that depend on the results of previous tests, you're in for a world of pain. It is actively discouraged.

bethskurrie
2019-05-14 06:43
Set up any required data in the provider state.

krzysztof.stepniak
2019-05-14 06:43
In my case it won?t help me :confused:

krzysztof.stepniak
2019-05-14 06:43
But thanks for the answer

bethskurrie
2019-05-14 06:44
Then perhaps pact is not the best tool for your scenario.

bethskurrie
2019-05-14 06:44
Gotta use the right tool for the right job :blush:

bethskurrie
2019-05-14 06:45
Would you like to explain what your problem is? Maybe someone can help you.

krzysztof.stepniak
2019-05-14 06:48
Well I think I need to setup new fresh state which include other states and it should help.

bethskurrie
2019-05-14 06:52
I usually delegate the actual set up to a nice builder object.

matt.fellows
2019-05-14 06:58
@krzysztof.stepniak people usually ask this question because the order matters to the provider. e.g. `POST /user`, and then `GET /user`

matt.fellows
2019-05-14 06:58
This is where the concept of provider states comes in

matt.fellows
2019-05-14 06:58
I say this, although I do recognise your name/avatar from previous chats - so I think you probably know this :smile:

krzysztof.stepniak
2019-05-14 06:59
:wink:

krzysztof.stepniak
2019-05-14 07:00
Ok guys, I think I?ll handle this one. Thanks once again.

matt.fellows
2019-05-14 07:01
:thumbsup:

matt.fellows
2019-05-14 07:01
you?re welcome

rjmcguinness
2019-05-14 10:59
@krzysztof.stepniak I found this in my case was due to Karma randomising order of running tests (a feature to prevent tests passing that depends on other tests running). Not sure if you?re using karma to run your pact tests, if so this might be useful https://stackoverflow.com/questions/39693307/how-to-specify-randomtrue-through-karma-jasmine (Set it to false instead of true)

krzysztof.stepniak
2019-05-14 11:00
Thanks, but I already handled it with new state. I am using mocha.

ian.mcwilliams
2019-05-14 15:48
hi @matt.fellows, i've finally gotten some time to look at this with our devops

ian.mcwilliams
2019-05-14 15:49
the codebase works fine and we can reproduce in our project codebase which is great :+1:

ian.mcwilliams
2019-05-14 15:49
trouble is, as soon as we try to use docker-compose it no longer works

ian.mcwilliams
2019-05-14 15:50
i've submitted a PR to the above project with the compose file and updated the README with the results I'm seeing, could i ask you to have a look and see if anything seems amiss please?

ian.mcwilliams
2019-05-14 15:50
@matt.fellows have sent an update to my earlier query in thread :slightly_smiling_face:

konrad.winkler
2019-05-14 19:17
has joined #pact-js

matt.fellows
2019-05-15 04:04
looking now

matt.fellows
2019-05-15 04:17
Looks just to be running slow in Docker (for me). Updating the timeout == :thumbsup:

ian.mcwilliams
2019-05-15 06:44
So simple...? :smile:

matt.fellows
2019-05-15 06:44
:man-shrugging:

ian.mcwilliams
2019-05-15 06:44
Yes, passing for me - I'll update into our project and test there

matt.fellows
2019-05-15 06:45
did it work for you?

ian.mcwilliams
2019-05-15 06:45
Sure did, will try in our project now and let you know!

ian.mcwilliams
2019-05-15 06:48
well, our devops didn't push his changes so i'll jump on him when he gets in :wink:

ian.mcwilliams
2019-05-15 06:48
will advise - thanks!

matt.fellows
2019-05-15 06:48
haha no worries :crossed_fingers:

james.hattersley-dyke
2019-05-15 09:13
Hi, I'm seeing a weird error which is causing my CI to fail - I'm using the `can-i-deploy` tool with pact-node (i think) it doesn't return a success message or often exits with exit code 2....can anyone advise? https://gist.github.com/jameshd/5a6176ce02692d7268ca7c9874dcd52f

matt.fellows
2019-05-15 09:19
can you please share the code you?re using?

james.hattersley-dyke
2019-05-15 09:20
it's v 8.3.0 of pact-node

bethskurrie
2019-05-15 09:20
James, I'd recommend find the underlying pact-broker can-i-deply executable in the node package, and calling it directly if the node is giving you problems.

james.hattersley-dyke
2019-05-15 09:27
@bethskurrie thanks, is there a ruby version you'd recommend?

bethskurrie
2019-05-15 09:28
it's baked in - you don't need ruby

bethskurrie
2019-05-15 09:28
the node can-i-deploy just wraps an underlying pact CLI (it's implemented in ruby, but the ruby is packaged with it, so you don't need to know or care about that)

bethskurrie
2019-05-15 09:29
you'll find it in one of the bin directories of the node package

james.hattersley-dyke
2019-05-15 09:29
yeah i did think that, starting to doubt myself though!

james.hattersley-dyke
2019-05-15 09:31
trying to use `find ./node_modules -name pact-broker | grep -e 'bin/pact-broker$'`

james.hattersley-dyke
2019-05-15 09:31
from CI I get: ```+ ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.64.1/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/bin/pact-broker can-i-deploy --participant fe-fragment-product --participant-version 0.4.3 --pact-broker https://sdrebuild.pact.dius.com.au --token iY8yd02Epz6MvGPARFtokA /usr/bin/env: ruby: No such file or directory```

matt.fellows
2019-05-15 09:32
are you using alpine?

james.hattersley-dyke
2019-05-15 09:32
```agent { docker { image 'node:8' } }```

bethskurrie
2019-05-15 09:33
oh, you've gone too deep

bethskurrie
2019-05-15 09:33
there should be a binary file up the top of the node package.

bethskurrie
2019-05-15 09:33
that will eventually call the line you've got there, but it has to have some things set up first in the top script.

james.hattersley-dyke
2019-05-15 09:33
`./node_modules/.bin/pact`

james.hattersley-dyke
2019-05-15 09:33
?

james.hattersley-dyke
2019-05-15 09:34
that's what I called first

bethskurrie
2019-05-15 09:34
Hm. I'd expect it to be in the standalone folder

matt.fellows
2019-05-15 09:34
It?s an open issue Beth

james.hattersley-dyke
2019-05-15 09:38
I'll just tack on a `|| true ` to the can-i-deploy for now...

bethskurrie
2019-05-15 09:38
Oh dear!

james.hattersley-dyke
2019-05-15 09:39
it's only to demo what pact can give us...

bethskurrie
2019-05-15 09:39
oh, I have a better solution

james.hattersley-dyke
2019-05-15 09:39
I gotta say you've done an awesome job with this

matt.fellows
2019-05-15 09:39
thanks James

james.hattersley-dyke
2019-05-15 09:40
the docs and support are 1st class.

matt.fellows
2019-05-15 09:40
something not right. The check you showed above looked good to me - can you show us the JS code you used to run the can-i-deploy?

bethskurrie
2019-05-15 09:40
``` docker run --rm \ -e PACT_BROKER_BASE_URL \ -e PACT_BROKER_USERNAME \ -e PACT_BROKER_PASSWORD \ pactfoundation/pact-cli:latest \ broker can-i-deploy \ --pacticipant Foo \ --latest ```

bethskurrie
2019-05-15 09:41
DOCKER ALL THE THINGS!

matt.fellows
2019-05-15 09:41
ha

james.hattersley-dyke
2019-05-15 09:41
@matt.fellows it's coming from a Jenkinsfile using the node:8 image ```sh "./node_modules/.bin/pact can-i-deploy --participant '${serviceName}' --participant-version '${serviceVersion}' --pact-broker https://sdrebuild.pact.dius.com.au --token 123456 || true"```

james.hattersley-dyke
2019-05-15 09:41
@bethskurrie i'll give that a go next :slightly_smiling_face:

bethskurrie
2019-05-15 09:42
The or true defeats the whole purpose!

bethskurrie
2019-05-15 09:42
Please try the docker!

james.hattersley-dyke
2019-05-15 09:42
i know :slightly_smiling_face:

james.hattersley-dyke
2019-05-15 09:42
ok - i'll have a go!

matt.fellows
2019-05-15 09:42
:thumbsup:

matt.fellows
2019-05-15 09:43
ahhh . Right. yeah you don?t need Pact Node for that :smile:

james.hattersley-dyke
2019-05-15 09:43
hat tip for using `--rm` no one here does that!

matt.fellows
2019-05-15 09:43
do what Beth says

bethskurrie
2019-05-15 09:43
Oh, the mess!

james.hattersley-dyke
2019-05-15 09:47
ok!

james.hattersley-dyke
2019-05-15 10:02
does this command use a accept a PACT_BROKER_TOKEN too ?

bethskurrie
2019-05-15 10:02
yes

james.hattersley-dyke
2019-05-15 10:02
sweet!

james.hattersley-dyke
2019-05-15 10:02
thanks for all your help

bethskurrie
2019-05-15 10:03
np

james.hattersley-dyke
2019-05-15 12:43
Hey Beth, I finally got the Docker command to run. I was using a Jenkinsfile and getting an error about entrypoints when running via Jenkins. Using the raw `docker run --rm ` worked

james.hattersley-dyke
2019-05-15 12:45
not sure if that's a jenkins issue or not, colleague seems to think it is


james.hattersley-dyke
2019-05-15 12:48
yeah deffo jenkins problem :slightly_smiling_face:

yousafn
2019-05-15 13:38
Hey all, I released https://github.com/YOU54F/jest-pact the other week, based on an initial proposal by @tjones, basically a simple wrapper to cut down on some of the boilerplate required work setting up a jest project with pact

matt.fellows
2019-05-15 20:52
Awesome! I'll get this referenced in the pact repo

tjones
2019-05-16 00:33
I'm excited to see this happen, @yousafn! Would have liked to be involved.

tjones
2019-05-16 00:38
but it's cool that you're taking the initiative. You can move the `test()` call inside the wrapper so that the tests read a bit cleaner (I think my current version does this).

tjones
2019-05-16 00:40
I don't think I understand the supertest bit - feels like it might be a separate wrapper?

yousafn
2019-05-16 00:48
Hey up homie :fist: , I?m up late over this side of the pond! Didn?t mean to tread on your toes, and would love for you to be involved, evolve it, do something different. After all, I am already standing on the shoulders of giants with the awesome work you guys have already done. We needed a wrapper for our services at work, as the number that wanted to consume pact was multiplying so I wanted to get something out there that we could start consuming. The supertest stuff is intertwined with our current setup at work, so it was nice to have that in there, as we won?t have to worry about setting a different port to every new provider we add in to our consuming services writing tests with the wrapper :slightly_smiling_face: Looking forward to hearing your thoughts!

yousafn
2019-05-16 00:50
ps, since late last year has been my first real foray into the world of dev / open source software, after being a tester for the past 10 years, so feedback is very much welcome and will be well received

tjones
2019-05-16 00:52
No worries at all! I probably should have released it already - I'm super pleased that someone wanted to do that :slightly_smiling_face:

tjones
2019-05-16 00:52
This is probably the kick I needed to get my thoughts on the next steps out of my head and into code

tjones
2019-05-16 00:52
I love the todo list that's at the head of the readme

tjones
2019-05-16 00:53
Seems like we're largely on the same page there. I might look at some PRs for you, if you'd like? Even if it means I have to use typescript :stuck_out_tongue_winking_eye:

tjones
2019-05-16 00:54
I think my initial reaction was a bit "aw" because I was expecting I'd release it soon - but honestly getting it out there is more valuable than my "soon"

tjones
2019-05-16 00:55
So, thanks for taking the initiative!

yousafn
2019-05-16 04:00
Sorry to steal your thunder chap, wasn?t my intention, I am just really enjoying learning about programming at the moment, lots of different languages and stacks, releasing modules, importing them in projects, is all pretty new to me, so I thought I would expand on your idea as it was useful to us, and as you said, it gives you a bit of a kick to start progressing with your thoughts into code, as I imagine there is some top knowledge stowed away in there! I am relatively new to the world of pact ( 6 months or so, same with typescript), it?s nice for people to use who are consuming your projects as they ship with types, but we can write it in pure javascript if you prefer and we can still create type definitions. I?ve added you as a contributor now :ok_hand:

bethskurrie
2019-05-16 04:09
Cross continent collaboration for the win!

ian.mcwilliams
2019-05-17 10:28
@matt.fellows just to let you know that we've now been able to integrate the kafka tests to our pipeline - thanks again for your advice!

matt.fellows
2019-05-17 10:54
Awesome! :the_horns:

matt.fellows
2019-05-17 10:54
Glad to hear

asad
2019-05-20 13:06
Hi i am bit confused regarding this example ``` // This is an example of a pact breaking // uncomment to see how it works! it.skip("Does not accept an invalid dog", () => { return messagePact .given("some state") .expectsToReceive("a request for a dog") .withContent({ name: "fido", }) .withMetadata({ "content-type": "application/json", }) .verify(dogApiHandler) }) ``` given in https://github.com/pact-foundation/pact-js/blob/master/examples/messages/consumer/message-consumer.spec.ts is it to check what consumer will do when an invalid request is given? what i am looking for and want to do is create pact/test for case when provider sends an invalid request and consumer returns an error response. Or pacts are only for success case not for failure case ?

asad
2019-05-20 13:51
*when provider sends an valid request and consumer returns an error response (cuz something went wrong on consumer side).

matt.fellows
2019-05-20 22:23
Hi Assad. It doesn?t work that way. You write the tests from the consumer?s point of view, and then the Provider must produce messages that meet those expectations - this is the ?consumer-driven? aspect. We are thinking about how to do provider-driven in this and other contexts, but are not yet ready

matt.fellows
2019-05-20 22:24
The consumer test here is about asserting that the function under test is able to handle a specific message. It?s a unit test that checks your assumptions about the interface are correct

asad
2019-05-21 06:28
hmm ok thank for help, so just to make sure the above example of `it.skip` it wont effect the pact, that is just to make sure consumer ignore/give error messages with invalid input?

matt.fellows
2019-05-21 07:21
correct, it?s just tells mocha to skip the tests

matt.fellows
2019-05-23 13:01
Hmm did I add dependabot? I recall a while ago testing some of these tools out but not applying it

yousafn
2019-05-23 13:25
Pact-js has become self aware


sankalan13
2019-05-24 06:26
has joined #pact-js

sankalan13
2019-05-24 06:36
Hey guys I am using PactWeb to generate my pact file and push to broker. I have been working on both authenticated and unauthenticated APIs from my provider. The unauthenticated APIs pacts are being verified properly on the provider verification (for which I am using the standalone ruby package). But I can't figure out how to add the Auth Header on my consumer side for the Auth API. I know that I can add it to my pact-provider-verifier by using the ```--custom-provider-header="Authorization: Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T"``` but this is the pact I am sending from my consumer side: ```beforeAll((done) => { provider.addInteraction({ state: 'workshop customer with payment option razorpay exists', uponReceiving: 'a request to GET a payment option', withRequest: { method: 'GET', path: '/springpay/api/payment-options/1/', headers: { 'Authorization' : 'Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T', 'Accept': 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json, text/plain, */*', }, body: EXPECTED_BODY, } }).then(() => { console.log('Inside 1 then'); done(); }, (err) => { console.log('Inside 1 error'); done.fail(err); }); });``` This is the error that I am getting: ```E, [2019-05-24T12:04:08.152143 #62858] ERROR -- : Diff with interaction: "a request to GET a payment option" given "workshop customer with payment option razorpay exists" Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "headers": { - "Authorization": "Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T" } } Description of differences -------------------------------------- * Could not find key "Authorization" (keys present are: X-Forwarded-Host, X-Forwarded-Proto, X-Forwarded-Port, X-Forwarded-For, Cookie, Accept-Language, Accept-Encoding, Referer, User-Agent, Accept, Connection, Host, Version) at $.headers``` Can someone please guide me to how I can send my dummy auth token to my pact file to use it to verify with the provider? I have a feeling I can use Matchers.term too but not really sure how. Please help.

vitaliy.grigoruk
2019-05-24 07:17
your consumer code should have an ability to set Authorization, so it is then passed in request headers to your provider/mockserver

vitaliy.grigoruk
2019-05-24 07:20
but it is better to relax this expectation in the contract a bit

vitaliy.grigoruk
2019-05-24 07:21
so, simply use ``` headers: { 'Authorization' : like('Basic WrWgrIbkH5zHuP8Rr4UZY5ZWK8s0PX5T'), 'Accept': 'application/json, text/plain, */*', }, ```

vitaliy.grigoruk
2019-05-24 07:21
where ``` const { like } = require('@pact-foundation/pact').Matchers; ```

sankalan13
2019-05-24 07:22
We use 'X-CSRFToken' for authentication and pass a cookie so I am not sure if Basic would work. I will try it once. Thanks Vitalii

sankalan13
2019-05-24 07:24
```* Could not find key "Authorization" (keys present are: X-Forwarded-Host, X-Forwarded-Proto, X-Forwarded-Port, X-Forwarded-For, Cookie, Accept-Language, Accept-Encoding, Referer, User-Agent, Accept, Connection, Host, Version) at $.headers``` Still not able to find the Authorization key here. Do I pass it on Accept instead?

vitaliy.grigoruk
2019-05-24 09:56
I think your actual consumer doesn?t send the header?

sankalan13
2019-05-24 10:21
Yeah that's exactly it. This isn't something pact is doing wrong. Will share my solution here when I find it so that others can reference it if needed. :slightly_smiling_face: Thanks Vitalii!!

diandra
2019-05-28 00:21
has joined #pact-js

sankalan13
2019-05-29 09:29
So when are you guys gonna provide a teardown feature for provider states? Currently its very hacky to delete the entire database objects every time I run my pact tests. I would be really happy to just leave my provider verifier server up and running between my pact tests. Another question I have for provider states is: Lets say I need a state where my customer exists. Now I need the customer's credentials to access an API but since I am using provider states, I am either hardcoding my values on setup (email and password) or I am creating another API to return the customer that was created on setup. Wouldn't it be awesome to have the pact provider return the data that was created so that the tester can catch it and use it inturn?

bethskurrie
2019-05-29 09:30
@sankalan13 why do you delete all the database objects each time? Can't you just clear the records?

bethskurrie
2019-05-29 09:30
The reason there is no teardown is that any teardown that relies on tearing down only the items that were supposedly created in the set up is that they will inevitably leak.

sankalan13
2019-05-29 09:31
What do you mean clear the records? I would need a fresh database every time I test.

bethskurrie
2019-05-29 09:31
It is much more reliable to clear the entire databsae before running a test, than to attempt to clear up data created within a test afterwards.

bethskurrie
2019-05-29 09:31
What sort of database are you talking about?

sankalan13
2019-05-29 09:31
I am using django with mysql so I was thinking of doing a ./manage.py flush

bethskurrie
2019-05-29 09:32
I tend to use relational databases at the moment. I have some code that truncates each table, that I call at the start of the set up.

bethskurrie
2019-05-29 09:32
I don't drop and recreate the tables each interaction. That would be very slow.

sankalan13
2019-05-29 09:33
Ahh so do you use a state mapping to call this truncate or do you do it separately before each test?

sankalan13
2019-05-29 09:33
Exactly, it'd be very slow to drop and recreate the database

bethskurrie
2019-05-29 09:33
at the start of each set up call, I clear the previous records, and then insert the new ones for this test.

sankalan13
2019-05-29 09:36
Got it. Thanks @bethskurrie :slightly_smiling_face:

sankalan13
2019-05-29 09:37
What about getting the auth data of my customer from the database once the provider state creates it? Is there an easy way to do that?

bethskurrie
2019-05-29 09:38
that's trickier. You can use Ruby middleware to intercept the request, or you can manually update the credentials of the customer to a known value during provider state set up.

bethskurrie
2019-05-29 09:38
I tend to prefer the second one.

sankalan13
2019-05-29 09:39
Yeah I think I will also go with the second one. Thank you Beth. You're super helpful :slightly_smiling_face:

bethskurrie
2019-05-29 09:40
no problem

jinal
2019-05-29 09:54
has joined #pact-js

matt.fellows
2019-05-29 10:54
@sankalan13 how are you managing provider states in the JS code? Are you using these functions (https://github.com/pact-foundation/pact-js#api-with-provider-states) or the old way with a dynamic endpoint?

matt.fellows
2019-05-29 10:55
state handlers in combination with the `requestFilter` are a good combination for this sort of thing.

sankalan13
2019-05-29 11:02
@matt.fellows out FE is in angular and our backend is in django. So we have a url: _pact/provider_states/ exposed with a POST method which calls the state mapping with different setup functions. So we are using python for the setup: ```class PactProviderSpringPayViewSet(APIView, PactMixin): permission_classes = (PactPermissions,) def post(self, request): STATES_DICT[request.data['state']]() return Response(status=HTTP_200_OK)```

sankalan13
2019-05-29 11:02
And I am using a decorator which maps the state to the specific function for setup

matt.fellows
2019-05-29 11:10
ah fair enough. Then yes, you may not have that sort of luxury yet I?m afraid.

sankalan13
2019-05-29 15:52
Haha yes. When will I have that luxury though?

shalygai.a
2019-05-29 16:05
has joined #pact-js

shalygai.a
2019-05-29 16:24
Hi! I use a https://www.npmjs.com/package/@mattersight/karma-pact-reporter to send pact file to pact broker. console displays the following error: Could not publish pact: ../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/cli/broker.rb:4:in `require' : cannot load such file -- pact_broker/client/cli/version_selector_options_parser (LoadError) from ../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/cli/broker.rb:4:in `<top (required)>' from .../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/app/pact-broker.rb:1:in `require' from ../node_modules/@mattersight/karma-pact-reporter/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/app/pact-broker.rb:1:in `<main>' What can I do? :no_mouth:

yousafn
2019-05-29 18:56
Hey up, `cannot load such file -- ` are you passing a file in? possibly raise an issue on the repository, as it doesn?t look to be owned by the pact team

matt.fellows
2019-05-29 22:04
Ask / check the question on their GH issues page

sankalan13
2019-05-30 09:20
:smile: Will do sir will do

matt.fellows
2019-05-30 10:45
Thanks!

yousafn
2019-05-30 14:49
Pretty sure you just need bash installed? There?s been a few of these issues raised if you do a search

thakkarjinal29
2019-06-01 11:28
has joined #pact-js

antonello
2019-06-03 08:05
Morning everyone. I seem to recall from previous conversations (and I found a reference to it in a comment written by @bethskurrie in an issue on github) that if you decorate the whole response body with `like` matcher, that applies to all objects and properties inside the body and that you don?t need any more matchers nested in the response for specific objects. However, this does not seem to work like this in our case.

antonello
2019-06-03 08:07
``` { "body": { "pageData": [ { "type": "account", "data": {} } ], "context": { "environment": "prod" }, "canonicalUri": {redacted}/", "indexingForbidden": true, "alternateLocaleUris": [ { "locale": "de-AT", "uri": "https://{redacted}/" } ] }, "matchingRules": { "$.body": { "match": "type" } } } ```

antonello
2019-06-03 08:07
I would expect `matchingRules` to be more specific when it comes to the description of `alternateLocaleUris`

antonello
2019-06-03 08:08
Just realised I should?ve posted in #pact-node instead.

bethskurrie
2019-06-03 08:09
@antonello ita really hard to pinpoint the exact issue on slack. Can you fork the pact js project, and modify the E2E example to demonstrate your issue?

antonello
2019-06-03 08:11
I can certainly put something together, but I just wanted to make sure first that my expectation is correct.

bethskurrie
2019-06-03 08:12
Yes. If you put a like around a top level object, it carries down to all the children.

antonello
2019-06-03 08:12
and that if I do ``` const accountPage: AccountPageOutput = { pageData: [ { type: 'account', data: {}, }, ], alternateLocaleUris: [ { locale: 'de-AT', uri: '{redacted}', }, ], }; const accountPageExpectation: InteractionObject = { ... willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', Ruid: 'adedb5d9-7d9f-4110-982c-55043fc18b27', }, body: like(accountPage), }, }; ```

bethskurrie
2019-06-03 08:13
It doesn't apply an each like to the children though.

bethskurrie
2019-06-03 08:13
Sorry, I'm on a phone. I really can't read the json!

antonello
2019-06-03 08:13
Sorry, it?s too long. but the eachlike might be the problem

antonello
2019-06-03 08:14
so if there are arrays of objects, an eachLike is still needed

bethskurrie
2019-06-03 08:14
Yes

antonello
2019-06-03 08:14
:boom:

bethskurrie
2019-06-03 08:14
The like just says match by type

bethskurrie
2019-06-03 08:14
It doesn't say anything about number.

antonello
2019-06-03 08:15
but you need an eachLike even if you?re not saying anything specific about the number of objects in the array

bethskurrie
2019-06-03 08:16
Yes

antonello
2019-06-03 08:16
perfect! that explains it then!

matt.fellows
2019-06-03 08:29
no no - this is the right place!

antonello
2019-06-03 08:29
phew

matt.fellows
2019-06-03 08:29
Thanks Beth.

antonello
2019-06-03 08:30
by the way, in order to use the matchers in typescript, we?re resorting to doing ``` import { like as pactLike, eachLike as pactEachLike } from '@pact-foundation/pact/dsl/matchers'; export function like<T>(value: T): T { return pactLike(value) as unknown as T; } export function eachLike<T>(value: T): T[] { return pactEachLike(value) as unknown as T[]; } ```

antonello
2019-06-03 08:57
actually, that doesn?t work

antonello
2019-06-03 09:14
Is there any documentation or examples on how to use matchers with typescript?

matt.fellows
2019-06-03 09:45
I'm just finishing up dinner and the bed routine for the little one, will look after

antonello
2019-06-03 09:51
I haven?t managed to find any reference to it anywhere

yousafn
2019-06-03 10:18
We use matchers with ts at work without any need for additional defs. We just import like, or eachLike. I?ve never seen anyone define the as keyword in a curly braced import.

yousafn
2019-06-03 10:19
Pact-is is written in typescript now and has type defs out the box after a rewrite by Matt

antonello
2019-06-03 10:19
@yousafn

yousafn
2019-06-03 10:22
That looks like an issue in your type def for alternatelocaluri which looks to be expecting an array but it looks like your trying to pass it an object. I?m a novice dev so that?s just my initial thinking so I might be completely wrong

antonello
2019-06-03 10:23
this is what I?m battling against. If I cast (`as unknown as AlternateLocaleUri[]`), it works. But then, I cannot reuse the same body for the smoke check against the mock server.

antonello
2019-06-03 10:23
because obviously the response object is not as expected


antonello
2019-06-03 10:25
:eyes:

matt.fellows
2019-06-03 10:29
granted it?s a local reference (rather than a proper global import) because it?s run as part of the CI to ensure the release is good, but i?m fairly confident it works!

antonello
2019-06-03 10:29
thanks Matt, what what with there is an eachLike nested in the response?

matt.fellows
2019-06-03 10:29
feedback certainly welcome on the API

matt.fellows
2019-06-03 10:30
Sorry, I did?t understand that question?

antonello
2019-06-03 10:30
You can do `expect(response.data[0]).to.deep.eq(dogExample)` because the `eachLike` is around the whole response

antonello
2019-06-03 10:36
What we?re trying to do is something like ``` const kennel: Kennel = { kennelName: "my kennel", dogs: eachLike({dogName = "my dog"}) } ... body = like(kennel); ```

antonello
2019-06-03 10:38
and lets say that dogs is of type Dog[]

matt.fellows
2019-06-03 10:39
Yep...


antonello
2019-06-03 10:54
and then you get a type error on applying `eachLike` to `dogs`

matt.fellows
2019-06-03 10:57
I thought you might say that. I've thought about raising it to a typed interface but haven't yet had the time to think it thru. If you'd be so kind as to raise an enhancement request with your example we could look at it

antonello
2019-06-03 10:58
sure, will do - but what do you recommend in the meantime?

antonello
2019-06-03 11:00
doing `as unknown as Dog[]` is sufficient to work around the type issue, but the comparison between the actual and expected response fails.

antonello
2019-06-03 22:36
@matt.fellows, I have a workaround that I can post tomorrow (on my phone ready for bed now).

matt.fellows
2019-06-03 22:37
Ah, sorry I missed this (before also heading to bed)

matt.fellows
2019-06-03 22:37
I?d be keen to see what you?ve done, and more keen to see how we can make it better for you going forward

antonello
2019-06-03 22:38
Perfect, let?s catch up about this tomorrow!

antonello
2019-06-04 10:51
Hey @matt.fellows. This is how I?m thinking we can work around the problem for now. https://github.com/anto-ac/pact-js/commit/b09545b8d11c06875de494fca679ee999f767ba8

antonello
2019-06-04 10:52
However, it would be nice we could just use `kennelWithMatchers` both when setting up the interaction and when verifying it.

phall
2019-06-04 21:17
Hi everyone, I?ve been looking into moving from a provider state REST endpoint (`providerStatesSetupUrl`) to using stateHandlers. This looks like a much cleaner way of setting up the state, but I?m having some trouble. The way we currently use states is something like: ``` { state: { description: 'object exists', objectId, }, uponReceiving: `a request to fetch an object with objectId [${objectId}]`, withRequest: { method: 'GET', path: `/v1/objects/${objectId}`, }, willRespondWith: { status: 200, body: { things: eachLike({ connection: { publicIp: like('1.2.3.4') } }, { min: 1 }), }, }, } ``` Note that our state is currently an object, not a string. The provider REST endpoint receives this object and makes sure that the object exists in the database. This has been working fine. In going back through the documentation, all the examples use strings (not objects). Is our approach not recommended? Is there an alternative approach? Or am I completely missing the point?

antonello
2019-06-04 21:35
And, finally, this is an alternative approach, which is our favourite option at the moment https://github.com/anto-ac/pact-js/commit/d32add9a96c2eb935e5f0628312212156a64eb9b

rob.clarken
2019-06-04 22:47
has joined #pact-js

matt.fellows
2019-06-04 23:37
hmm technically the state is supposed to be a string. I recall somebody (it might have been you!) was doing something like this. It?s technically not designed to be used this way, but was probably more of a ?feature? bug.

matt.fellows
2019-06-04 23:37
I?ll review to see if the state handler can do something like this, but it?s certainly not portable across language implementations - so it?s not ideal.


antonello
2019-06-05 06:14
Let me know your thoughts @matt.fellows :blush:

matt.fellows
2019-06-05 06:16
Thanks Anto. It?s on my TODO for today (it?s a long list, but I?m sure I?ll at least get to read it :smile: )

vitaliy.grigoruk
2019-06-05 07:02
it was me, @matt.fellows

matt.fellows
2019-06-05 07:03
it seems there are _lots_ of clever people in this channel :stuck_out_tongue:

vitaliy.grigoruk
2019-06-05 07:03
I?m doing almost the same, passing array of js objects (using the syntax from v3 basically)

vitaliy.grigoruk
2019-06-05 07:03
however, I?m having my own proxy on provider side to handle states

vitaliy.grigoruk
2019-06-05 07:06
there is some demand for v3 in pact-js? I?m wondering if there is a roadmap of what needs to be done in order to be v3 compatible on the ?writing side?? I?ll be happy to contribute

matt.fellows
2019-06-05 08:43
I?ll put it on the list to get the roadmap published. TL;DR - we need to update the Ruby binary which is the engine under the hood. From there, we need to update any DSL with the new features

matt.fellows
2019-06-05 08:44
In the meanwhile, i?ll take a quick look at how we might be able to enable the previous naughty behaviour to avoid you needing to run proxies

phall
2019-06-05 13:11
Thanks!

phall
2019-06-05 13:12
But this is not a crazy way to be setting up states? Is there an alternative approach making sure specific IDs exist?

vitaliy.grigoruk
2019-06-05 14:04
well, the only option with spec v2 is to encode it to a string. I?m specifying state in my tests via array of objects (the value has the same format as spec v3, so it is easier to migrate to v3 in the future ``` state: [ { name: 'first state', params: { param1: 'val1', param2: 'val2' } }, { name: 'second state', params: { someParam: 'someval' } } ] ``` Then, I have a wrapper for ?addInteraction?, which does `interaction.state = JSON.stringify(originalInteraction.state)`, so it is a string. On the provider side I have my custom state handler endpoint where I deserialize `state` from string to JSON array and then I invoke state handlers based on `state.name` (passing `state.params` as args to state handler function). The logic is almost the same as what you can find inside pact-js codebase.

phall
2019-06-05 14:35
Nice approach! Thanks for sharing.

matt.fellows
2019-06-06 00:21
I certainly think there is room to add a generic typed matching interface

matt.fellows
2019-06-06 00:23
Another option, which would probably still require this under the hood anyway, would be to create decorators that could be added to typed objects. Then these objects could just be thrown around the DSL without extra functions (such as `extractPayload`)

matt.fellows
2019-06-06 00:41
e.g. a @Pact annotation that lets you specify how it maps to the contract (https://www.typescriptlang.org/docs/handbook/decorators.html)


matt.fellows
2019-06-06 00:41
I haven?t put a lot of thought into it in the TS/JS case, but it would seem a natural fit and keep the tests much cleaner and easier to understand

antonello
2019-06-06 06:37
Thanks a lot, @matt.fellows! I am not by far a typescript expert, hence I may not be the best person to even attempt this, but should I convince someone at my client to look into it before you get a chance, would you anticipate it being relatively straightforward?

matt.fellows
2019-06-06 07:16
The Decorators or your suggestion?

matt.fellows
2019-06-06 07:16
It?s a long weekend coming up here so I might get a chance :smile:

matt.fellows
2019-06-06 07:17
your suggestion is fairly straightforward, so at least as an interim, you could create a package that does it for you and after some experience/time contribute it back in.

matt.fellows
2019-06-06 07:17
As for the decorators, might be a few weeks before it?s rolled into mainstream, but perhaps possible to get an alpha release out fairly quickly

antonello
2019-06-06 09:38
Decorators are still experimental though. We?d have to specifically enable them for the pact tests.

matt.fellows
2019-06-07 03:23
Yes, true. It?s pretty common though. A lot of frameworks (e.g. Angular) use them heavily, so I don?t see them not coming in

matt.fellows
2019-06-07 03:28
But i?ll look to create a standard non-decorated interface first, and then use decorators as DSL sugar

matt.fellows
2019-06-07 03:28
this should mean we?re not tied to a path that will be unsupported later on

yousafn
2019-06-08 00:56
Hey all, hoping you can help me. I have a pact that will accept `http://localhost:8084/request/path/1` and will return ``` { "id": "1", "status": "LOOSE_MATCH" } ``` It is setup with a term matcher on the request path ``` path: term({ generate: requestPath, matcher: "/request/path/(?![2]$)\\d+" }) ``` so that it will match anything that isn?t `http://localhost:8084/request/path/2` I want to set it up so that when I perform the request `http://localhost:8084/request/path/123`, the response body will return the ID in the url that was matched ``` { "id": "123", "status": "LOOSE_MATCH" } ``` My pact test is here https://github.com/YOU54F/jest-pact-typescript/blob/requestPathExample/src/pact/client/requestPathMatching.pacttest.ts and my generated pact is here https://github.com/YOU54F/jest-pact-typescript/blob/requestPathExample/docker/pact-stub-service/pacts/test-consumer-request-path-provider.json Full example in a PR :- https://github.com/YOU54F/jest-pact-typescript/pull/101 Instructions to run example ``` 1. `git clone git@github.com:YOU54F/jest-pact-typescript.git` 2. `git checkout requestPathExample` 3. `yarn install` 4. `yarn run pact-test` 5. `cd docker/pact-stub-service` 6. `make copy-pacts` 7. `cd ../docker` 8. `docker-compose up` ```

matt.fellows
2019-06-08 11:55
Thanks @yousafn. I?ve taken a look.

matt.fellows
2019-06-08 11:55
If I understand correctly, it?s not the Pact test that is the issue - it?s using it in the stub service after? If so, this is a known limitation of the stub service at the moment

matt.fellows
2019-06-08 11:57
The stub server will respond to the matched criteria, but the actual response will be what?s specified in the example for the Pact test (in this case `1` for any request, except for the `2` case)

matt.fellows
2019-06-08 12:03
btw love what you?re doing in that repo

matt.fellows
2019-06-08 12:13
> but should I convince someone at my client to look into it before you get a chance, would you anticipate it being relatively straightforward? I may have mis read that. If your client is willing to submit a PR that would be great. I don?t imagine it being super difficult

antonello
2019-06-08 12:14
I just don?t see it happening any time soon, especially now that they have a workaround

matt.fellows
2019-06-08 12:17
ah fair enough

matt.fellows
2019-06-08 12:17
Just taking a little squiz now

matt.fellows
2019-06-08 12:17
I think you can just call `getValue()` on the matcher, rather than wrap the `extractPayload` around it

antonello
2019-06-08 12:18
But it?s annoying if you have many marchers

matt.fellows
2019-06-08 12:19
mm

antonello
2019-06-08 12:19
Most of their responses have many arrays

matt.fellows
2019-06-08 12:19
Sure.

matt.fellows
2019-06-08 12:20
Just to check that you?re not _actually_ doing this sort of test assertion: `expect(response.data[0]).to.deep.eq(dogExample)`

matt.fellows
2019-06-08 12:20
because that wouldn?t be very useful

matt.fellows
2019-06-08 12:21
I might update the TypeScript example with a more realistic scenario (where an intermediate data access layer does the API call and returns a domain model). i.e. you shouldn?t be just firing the HTTP request and asserting you got back what you expected

antonello
2019-06-08 12:25
``` function getData(state: RequestData, ruid: string = generateRuid()): Promise<PageData> { const path = '/api/v1/page/account'; const { requestHeaders } = state; const account = await httpGetJson<AccountPageOutput>(path, { ruid, requestHeaders, data: {} }); return { account }; } export const accountSpec = () => { describe('Account Page', () => { it('returns the account page data', async () => { await provider.addInteraction(accountPageExpectation); const accountPageResponse = await getData({ requestHeaders: { 'x-language-code': 'en-GB', } }, 'adedb5d9-7d9f-4110-982c-55043fc18b27'); expect(accountPageResponse).toEqual({ account: extractPayload(accountPage) }); await provider.verify(); }); }); }; ```

antonello
2019-06-08 12:26
where ``` const accountPage: AccountPageOutput = like({ pageData: eachLike( { type: 'account', data: {}, } ), context: { environment: 'prod', }, indexingForbidden: true, alternateLocaleUris: eachLike( { locale: 'de-AT', uri: '...', } ), }); ```

antonello
2019-06-08 12:27
we?re using an intermediate data access layer

antonello
2019-06-08 12:29
to setup the expected response we?re using the same type of that the domain model uses

antonello
2019-06-08 12:34
Or should we be doing something else instead?

matt.fellows
2019-06-08 12:36
no that makes sense, was just making sure. It sounds like you know what you?re doing, so that?s good!

matt.fellows
2019-06-08 12:37
Your option 2 from above certainly reads a lot better in the tests (i.e. no `extractPayload`)

matt.fellows
2019-06-08 12:37
It feels clumsy, so I can see why it would be preferable to have this in the DSL itself

antonello
2019-06-08 12:38
By the way, the `eachLike` in the snippet above is not the original one.

matt.fellows
2019-06-08 12:39
this one? ``` export function eachLike<T>(value: T): T[] { return pactEachLike(value) as unknown as T[]; } ```

antonello
2019-06-08 12:39
as I showed in the forked github example, it is: ``` import { like as pactLike, eachLike as pactEachLike } from '@pact-foundation/pact/dsl/matchers'; export function like<T>(value: T): T { return pactLike(value) as unknown as T; } export function eachLike<T>(value: T): T[] { return pactEachLike(value) as unknown as T[]; } ```

antonello
2019-06-08 12:39
yep

matt.fellows
2019-06-08 12:41
So basically, you?re having to coerce the matcher into the original type to make the tests readable/fluent, then use `extractPayload` to get the value in the assertion

antonello
2019-06-08 12:42
Exactly

matt.fellows
2019-06-08 12:42
:ok_hand:

yousafn
2019-06-08 13:07
Hey Matt, correct, the functionally I am after is in the stub service, the pact test is working spot on, however in our integration tests at work, the consumer sends an ID and and expects that ID back in the response. As we always get back ID 1, our integration tests fail. I?ve got the query param matching feature request to look at in the stub service, so I will look at both when we get some time. It?s a feature that?s available in wiremock and is really useful for upstream integration and e2e tests which I think was one of Beth?s wants for the stub service. I?ll see what we can rustle up as this and the query param matchers would really help us utilise pact throughout, and not have to revert to wiremock for some use cases. Cheers for the appreciation, the repo initially started as a way to demonstrate an issue we were having at work, without having to expose that codebase and is now growing nicely as we delve further into pact. Thanks for taking the time on a Saturday my friend!!!

matt.fellows
2019-06-08 13:11
> Thanks for taking the time on a Saturday my friend!!! Sleeping baby = Parenting = best you can get on a Saturday night :slightly_smiling_face:

matt.fellows
2019-06-08 13:11
Yes, I would love to see us do better in that space.

matt.fellows
2019-06-08 13:12
I?ve used Mountebank a lot and love the ability to use predicates. Similarly in Wiremock

matt.fellows
2019-06-08 13:14
I?ve not really had the headspace to think through how this could be done well without making the Pact DSL more complicated or confused.

matt.fellows
2019-06-08 13:17
Possibly, generators might be able to be ?upgraded? for this purpose (see https://github.com/pact-foundation/pact-specification/tree/version-3#introduce-example-generators)

matt.fellows
2019-06-08 13:18
But I think as soon as people start using it as a general DSL to do stubbing, then the contracts being produced will be overly broad. So it might need to be a separate plugin if we need to go down the multiple predicates for single interaction path.

yousafn
2019-06-08 13:29
Hahaha, I?ve not got the joy of babies yet, sleeping or otherwise! Just insomnia. I?ll have a think too mate, agree that it?s a fine line between providing additional functionality and not allowing the contracts to be too broad. I wonder if, similar to the verifier where you can override the response body, if we do a similar thing within the stub service, without having to mess with the contracts themselves. Pact spec v3 sounds like it has lots of juicy features. I might have to take pact-jvm for a spin ( as I believe it supports v3 matchers/generators ) just to have a gander at what v3 can and can?t do. I?ve also seen some tooling that can generate pacts from wiremock contracts so that?s probably worth a look in too. From memory spring-cloud-contract has some cool pact features that I did come across with some googling https://github.com/spring-cloud/spring-cloud-contract/issues/96

matt.fellows
2019-06-08 13:36
> I wonder if, similar to the verifier where you can override the response body, if we do a similar thing within the stub service, without having to mess with the contracts themselves. That?s probably the approach that would be taken, or at the very least, it would be authored separately to the test itself and appended to the conttract. Could even be a separate file that contained predicates/stub logic

matt.fellows
2019-06-08 13:36
Thanks for the link, will have to check out tomorrow, but I know Marcin did some cool stuff in that space in SCC.

matt.fellows
2019-06-08 13:37
And yes, the Atlassian team have also done some cool stuff there (although the contract conversion is all Java only :disappointed: )

matt.fellows
2019-06-08 13:37
Anywho, my wife has returned from her night out - so I better go. Feel free to keep chatting here and i?ll respond.. when I can :slightly_smiling_face:

ian.mcwilliams
2019-06-10 09:20
morning guys, i'm trying to set up the api contract tests for our project but the interactions aren't matching. we're using axios and i wonder if some of the generated parts of the request might be an issue? i've copied the headers from the actual request but the other items contains functions so not sure what to do with those, but i thought it would match on the headers alone anyway...

ian.mcwilliams
2019-06-10 09:22
and the actual request, logged by adding a request interceptor to axios:

ian.mcwilliams
2019-06-10 09:22
``` { adapter: [Function: httpAdapter], transformRequest: { '0': [Function: transformRequest] }, transformResponse: { '0': [Function: transformResponse] }, timeout: 10000, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: [Function: validateStatus], headers: { common: { Accept: 'application/json, text/plain, */*' }, delete: {}, get: {}, head: {}, post: { 'Content-Type': 'application/x-www-form-urlencoded' }, put: { 'Content-Type': 'application/x-www-form-urlencoded' }, patch: { 'Content-Type': 'application/x-www-form-urlencoded' }, Authorization: 'apiKey ' }, method: 'get', baseURL: 'https://valid.url.base.co.uk', proxy: false, url: '/api/v2/products/sub-categories/user/abc' } ```

bethskurrie
2019-06-10 09:23
Those headers are weird

bethskurrie
2019-06-10 09:23
It looks like it's sent through the axios header configuration, not the actual values.

bethskurrie
2019-06-10 09:24
Or rather, you've set up an expectation with a configuration object.

ian.mcwilliams
2019-06-10 09:24
i see what you mean, it probably uses common and adds whatever is specified for the request type, so nothing for this get

bethskurrie
2019-06-10 09:25
Settting up the expected request is code you control though, not axios.

ian.mcwilliams
2019-06-10 09:26
i've changed the specified interaction to:

ian.mcwilliams
2019-06-10 09:26
``` "headers": { "Accept": "application/json, text/plain, */*", "Authorization": "apiKey " }```

ian.mcwilliams
2019-06-10 09:26
everything else the same - mockserver log still shows no match though

bethskurrie
2019-06-10 09:27
What's it not matching on?

bethskurrie
2019-06-10 09:29
OK, when you see that pattern of logs, it usually means your tests is executing on the wrong order.

bethskurrie
2019-06-10 09:30
From those logs, no actual request came through at all.

ian.mcwilliams
2019-06-10 09:30
i've got one test running:

ian.mcwilliams
2019-06-10 09:30
```const { targetFunction } = require('../../.....'); const { Matchers } = require('@pact-foundation/pact'); const { term } = Matchers; const guid = 'abc'; describe('something', () => { it('does something', done => { provider.addInteraction({ uponReceiving: 'some request', withRequest: { method: 'GET', path: '/api/v2/products/sub-categories/user/abc', headers: { Accept: 'application/json, text/plain, */*', Authorization: 'apiKey ' } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: { status: 200 } } }); targetFunction(guid) .then(response => { console.log(response); // expect(response).toEqual({ status: 202 }); }) .then(done) // .catch(err => { // console.log('THISERR', err, 'ERREND') // }); }); }); ```

bethskurrie
2019-06-10 09:31
Now, you'll need an actual JavaScript developer to help you.

bethskurrie
2019-06-10 09:32
It'll be something to do with the order of execution and the way your callbacks or promises are set up.

bethskurrie
2019-06-10 09:32
I'm no js expert in afraid. Matt or Michel should be able to advise.

ian.mcwilliams
2019-06-10 09:34
cool - thanks for your help! i'll see if i can play about with a few things with that in mind, in the meantime :slightly_smiling_face:

matt.fellows
2019-06-10 09:52
addInteraction is a promise, you'll need to wait for that to complete before calling targetFunction

matt.fellows
2019-06-10 09:52
I'm just finishing tea so on a mobile, but that could be the cause of the interactions coming in out of order.

matt.fellows
2019-06-10 09:54
Ah those logs don't seem to indicate that a verification is happening before the interaction is registered

ian.mcwilliams
2019-06-10 10:29
i added an await just to try, no change in outcome

bethskurrie
2019-06-10 10:33
All requests to the mock service are logged.

bethskurrie
2019-06-10 10:34
So, if you don't see any request logged between registering the interaction, and verifying, it's because there were no actual requests made to the mock service.

bethskurrie
2019-06-10 10:34
So either your timing is out, your request is being made to the wrong address, or it just isn't being made at all.

matt.fellows
2019-06-10 12:46
@ian.mcwilliams you mentioned in your actual request that axios logged that the base url was `'https://valid.url.base.co.uk` - is that just a placeholder, or is it actually hitting an external URL? Just confirming that it has actually been configured to point to the mock server provided by Pact?

ian.mcwilliams
2019-06-10 14:21
it's not hitting localhost:port - and that would appear to be the issue, because although jest runs the test config (and is doing so) by default, at the point that the axios.create call is made the default config for the host value is being used

ian.mcwilliams
2019-06-10 14:21
i'll sort something out to get the test host value picked up and see if that takes care of it

matt.fellows
2019-06-10 21:27
:+1:

matt.fellows
2019-06-10 21:28
Sounds like that'd be it

sgleadow
2019-06-10 23:09
@sgleadow has left the channel

ian.mcwilliams
2019-06-13 09:57
@matt.fellows @bethskurrie have completed this after being away for a couple of days - yes the issue above was required, it also needed the config to specify the port as part of the url, because axios doesn't allow you to set the port separately and if you don't add it to the baseUrl then it will default to 80 - so config was `{ url: localhost:8989, port: 8989 }`

ian.mcwilliams
2019-06-13 09:57
then i just copied the missing headers from the actual call (still logged with an axios interceptor) into the pact interaction, and we have a passing test :slightly_smiling_face:

ian.mcwilliams
2019-06-13 09:58
thanks again for your help!

bethskurrie
2019-06-13 09:58
Glad you worked it out!

matt.fellows
2019-06-13 11:24
you?re welcome, and thanks for circling back!

vitaliy.grigoruk
2019-06-14 09:05
Hi everybody. I have a question about matchers when doing provider verification. In mockserver interaction definition I have the following response body (matching by type): ``` "diff": { "value": decimal(0) } ``` However, actual provider may also return `"value": 0.1`, which is also a valid result. The issue is when I run provider verification, it fails: ``` "diff": { - "value": Fixnum + "value": Float } ``` How should I define a matcher to allow both `0` and float numbers?

matt.fellows
2019-06-14 09:15
Ah, this is tough case. I think there is an outstanding issue somewhere that covers it. At the moment that's not possible across languages in a portable way I'm afraid

vitaliy.grigoruk
2019-06-14 09:58
I guess we need a `number` matcher in JS, which matches both integers and floats

matt.fellows
2019-06-14 10:12
The example should be an actual decimal (instead of zero, because js will lose that resolution)

matt.fellows
2019-06-14 10:12
But yes, that would be one way out of it

matt.fellows
2019-06-14 10:12
I think a decimal matcher should include an integers, but not the other way arouns

matt.fellows
2019-06-14 10:13
This would need fixing in the Ruby code. I'll see if I can chase up a bit later when back on PC

vitaliy.grigoruk
2019-06-14 10:53
> I think a decimal matcher should include an integers, but not the other way around That?s what I thought as well.

matt.fellows
2019-06-14 11:56
Is your provider also JS?

matt.fellows
2019-06-14 11:56
(also sorry for poor spelling, was on my mobile before)


vitaliy.grigoruk
2019-06-14 12:13
yes, both are in JS

matt.fellows
2019-06-14 12:46
thx

vitaliy.grigoruk
2019-06-14 12:49
I?ve commented on that ticket? not sure what to about it.

vitaliy.grigoruk
2019-06-14 13:02
wow, that was quick @matt.fellows!

matt.fellows
2019-06-14 23:05
No worries. I have an idea as to have I can support it in Pact JS fairly quickly. Need to chat with maintainers on portability

mui_ume
2019-06-17 11:34
has joined #pact-js

mui_ume
2019-06-17 11:44
Hi I like to know how to add pact test to a react-native app project. however this react-active app has it's jest test written inside it's library module. since I am writing pact test, I guess I won't be adding pact to the internal library module but do it outside where index.js resides?

mui_ume
2019-06-17 11:44
index.js code snippet: ```import { AppRegistry } from 'react-native'; import App from './App/index'; import { name as appName } from './app.json'; AppRegistry.registerComponent(appName, () => App);```

matt.fellows
2019-06-17 11:57
Your pact tests should focus on the collaborator (sometimes referred to as service delegates) that is responsible for communicating to external systems / APIs.

matt.fellows
2019-06-17 11:59
It should be pure JS that you?re testing. I?m not a react expert, but I?d say it?s unlikely that you?be testing the `index.js` file directly

matt.fellows
2019-06-17 12:00
If there is a dependency on react in the bit you?re testing, that would seem to me to be the wrong place

abubics
2019-06-18 00:55
@mui_ume Ideally, on the consumer side, you'd have an API client as its own js module, with the single responsibility of talking to an API and handling its various responses. As plain js, it should be framework independent, and relatively platform independent (with possible exceptions for `fetch`/`axios`/whatever). The Pact tests are then written as unit tests in the context of that API client, and can be run without a browser, or react, or any other heavy dependencies.

matt.fellows
2019-06-18 06:05
@vitaliy.grigoruk if you haven?t seen already, this should now be fixed in the latest Pact JS (and soon all languages that use Ruby under the hood)

ian.mcwilliams
2019-06-18 10:31
hi guys - i've got working api tests locally which fail when i run them in a container when the test attempts to call addInteraction on the provider, with the message that it cannot call addInteraction on undefined. i can log the provider (Pact) object in the previous line, i've even logged the properties of the object and they include the addInteraction method. is this something you've experienced before?

matt.fellows
2019-06-18 10:33
No haven't seen it

matt.fellows
2019-06-18 10:34
But it works outside of docker? So this probably means the container environment is insufficient somehow or incorrectly configured. Are you using Alpine and have you read up on the related Alpine setup issues?

ian.mcwilliams
2019-06-18 10:44
we'd previously had some issues with ruby in alpine and we're using the setup you recommended at that time:

ian.mcwilliams
2019-06-18 10:44
```FROM node:10-alpine RUN apk add --no-cache --virtual build-dependencies build-base git RUN apk --no-cache add ca-certificates wget bash \ && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \ && apk add glibc-2.29-r0.apk```

ian.mcwilliams
2019-06-18 10:46
yeah works outside the container - i've spent some time with our devops lead this morning and he hasn't been able to identify anything that should cause an issue

matt.fellows
2019-06-18 10:47
cool, thanks Ian.

dalsidhu99
2019-06-18 10:57
has joined #pact-js

mui_ume
2019-06-18 13:04
@abubics, I have been looking at your github repository. I still could not figure out how to add pact test to my react native app which is the frontend and making HTTP requests call to the backend. my react native has this project structure App-> Screens-> Login which has an index.js, LoginHelper.js, and this LoginHelper.js has this code snippet: const loginEndpoint = settings.getLoginEndpoint(); try { const resp = await http://api.post(loginEndpoint, reqData); where it make a post request to the endpoint and get response. ..... this is where I want to use pact to do the contract testing..

mui_ume
2019-06-18 13:06
I create a folder pact and try to add setup.js, jest-wrapper.js, publish.js, in VS, it is show as Red, not sure if I inserted at the right place though?

mui_ume
2019-06-18 13:06
it seem not so straightforward to setup pact ?

mui_ume
2019-06-18 13:15
Sorry I?m totally new to pact contract testing and need to integrate into the developer source code is a challenge I don?t seem to see how to integrate Given the example are not so relevant

mui_ume
2019-06-18 13:17
I have been using postman for API testing and I find it more straightforward than pact Which is not so clear how to setup for my project

ian.mcwilliams
2019-06-18 13:40
@matt.fellows i can add that if any item is missing that is required it gives an error message, eg if i run with:

ian.mcwilliams
2019-06-18 13:40
```provider.addInteraction({ uponReceiving: 'some request', withRequest: { method: 'GET' }, willRespondWith: { status: 200 } }); });```

ian.mcwilliams
2019-06-18 13:41
i get:

ian.mcwilliams
2019-06-18 13:41
``` You must provide a path. 10 | describe('something', () => { 11 | it('does something', async () => { > 12 | provider.addInteraction({ | ^ 13 | uponReceiving: 'some request', 14 | withRequest: { 15 | method: 'GET' ```

ian.mcwilliams
2019-06-18 13:41
if i then add a path then it's back to:

ian.mcwilliams
2019-06-18 13:41
``` TypeError: Cannot read property 'addInteraction' of undefined 10 | describe('something', () => { 11 | it('does something', async () => { > 12 | provider.addInteraction({ | ^ ```

vitaliy.grigoruk
2019-06-18 20:38
That?s great! Thank you, @matt.fellows! Will try it tomorrow

matt.fellows
2019-06-18 21:10
Hi Lay. Forgetting Pact for a moment, it?s not a tool like Postman that can be run from ?the outside? so to speak. You need to be able to write a unit test within the code base. Might I suggest you start by writing a simple Jest unit test in your code (without Pact). Once you can test your LoginHelper with Jest, you could look to introduce Pact. There really is nothing React Native specific you need to do to make Pact work for you. It is just a unit testing tool

matt.fellows
2019-06-18 21:11
Looks like you?re in the right place - we want to be testing the function that does this work.

matt.fellows
2019-06-18 21:12
Can you write a standard Jest (or whatever unit testing framework) test for this?

matt.fellows
2019-06-18 21:12
Once you?ve done that, adding Pact should be trivial.

matt.fellows
2019-06-18 21:17
That?s strange, I can?t understand how this might happen as `provider` is a variable under your control. Could something else be modifying it? How is `provider` being configured?

matt.fellows
2019-06-18 21:17
If you could whip up a little code for me to repro, I?d happily take a look

abubics
2019-06-18 23:30
btw @mui_ume, which github repo were you looking at? I don't remember linking you to any . . .

tjones
2019-06-19 02:49
@ian.mcwilliams I don't believe that `port` is a key in axios config - so you should be able to do `{ url: 'localhost:8989'} `

tjones
2019-06-19 02:51
Also, you can get it from pact js, too - for example: ``` beforeEach(() => { yourConfig.api.baseUrl = provider.mockService.baseUrl; }); ```

tjones
2019-06-19 02:51
this is nicer because it means you don't need to know what port it is running on (and you can run multiple mock servers if your tests are running concurrently)

tjones
2019-06-19 02:53
If you're using Jest, @yousafn and I have been working on a wrapper to make this whole process a bit nicer: https://github.com/YOU54F/jest-pact/#readme

tjones
2019-06-19 02:54
``` import { pactWith } from 'jest-pact'; import { Matchers } from '@pact-foundation/pact'; import api from 'yourCode'; pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, provider => { let client; beforeEach(() => { client = api(provider.mockService.baseUrl) }); describe('health endpoint', () => { // Here we set up the interaction that the Pact // mock provider will expect. // // jest-pact takes care of validating and tearing // down the provider for you. beforeEach(() => provider.addInteraction({ state: "Server is healthy", uponReceiving: 'A request for API health', willRespondWith: { status: 200, body: { status: Matchers.like('up'), }, }, withRequest: { method: 'GET', path: '/health', }, }) ); // You also test that the API returns the correct // response to the data layer. // // Although Pact will ensure that the provider // returned the expected object, you need to test that // your code recieves the right object. // // This is often the same as the object that was // in the network response, but (as illustrated // here) not always. it('returns server health', () => client.health().then(health => { expect(health).toEqual('up'); })); }); ```

tjones
2019-06-19 02:55
We really need a blog post about this

tjones
2019-06-19 02:57
@mui_ume Here is a react project with Pact tests in it (it's not react native, but the pattern should be similar): https://github.com/TimothyJones/PlusOne/blob/master/src/Game/Board/service/api/api.pact.test.js

tjones
2019-06-19 02:57
In this case, we have a service module that contains the API


matt.fellows
2019-06-19 02:59
Awesome - thanks Tim!

matt.fellows
2019-06-19 02:59
Perhaps we should add a link to this project from GitHub for others?

tjones
2019-06-19 03:00
Note that this is completely separated from React - all the calling code needs to know is the domain model (in this case, that there is a score board that the app can tell that the player reached a particular score). The caller doesn't know anything about the network requests (post/get etc).

tjones
2019-06-19 03:00
I think we should just clean up the examples :slightly_smiling_face:

tjones
2019-06-19 03:00
Probably a React example

tjones
2019-06-19 03:00
could be added

tjones
2019-06-19 03:04
Note that the Pact test linked above wraps the whole API module - ie, it tests what your code will call when you want to do actions through the API. This is important because it means that the pact test doesn't read like this:: ``` // axios.get(`${apiBase}/something`).then( () => {/* validate response */} ) ``` instead, it reads like this: ``` // This is much more valuable because it's testing the code your app will definitely be calling yourApi.getSomething().then( () => {/* validate response */} ) ```

ian.mcwilliams
2019-06-19 09:16
@tjones that's correct as per my findings, no port specifically for axios so pass as part of the host string

ian.mcwilliams
2019-06-19 09:17
the other stuff you mention sounds like it could be very good, but at the moment i have to make the test run in a container before i can start to scale, and port conflict potentially become an issue!

tjones
2019-06-19 11:00
Very reasonable

ian.mcwilliams
2019-06-19 12:57
@matt.fellows it was the timeout, increased it and the tests passed in the container :joy:

mui_ume
2019-06-20 05:45
thanks Tim Jones

mui_ume
2019-06-20 08:38
Hi Tim, do you need to setup the pact mock provider?

mui_ume
2019-06-20 08:46
I am trying to follow this step here https://reflectoring.io/pact-react-consumer/

mui_ume
2019-06-20 08:49
the steps here is well explained but I need to fit into my project in my case, it's to call the login endpoint which is in my project structure located at App/Screens/Login/LoginHelper.js

mui_ume
2019-06-20 08:49
I put my pact folder at the root directory, same level as App

mui_ume
2019-06-20 08:50
it will be good to have a simpler example to follow. I need to figure and replace the Scoreboard etc with my own project use case


mui_ume
2019-06-20 09:13
I clone the above and try to run npm i and npm t

mui_ume
2019-06-20 09:14
got some FAILED message

mui_ume
2019-06-20 09:14
```20 06 2019 17:13:06.788:INFO [pact]: Pact Mock Server running on port: 1234 20 06 2019 17:13:06.822:WARN [watcher]: Pattern "/Users/tohlaymui/Desktop/pact-js-master/dist-web/pact-web.js" does not match any file. 20 06 2019 17:13:06.830:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/ 20 06 2019 17:13:06.831:INFO [launcher]: Launching browsers PhantomJS_without_security with concurrency unlimited 20 06 2019 17:13:06.834:INFO [launcher]: Starting browser PhantomJS 20 06 2019 17:13:07.894:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket t6nvJHPDCQQhpbhrAAAA with id 50322375 PhantomJS 2.1.1 (Mac OS X 0.0.0) Client sayHello says hello FAILED ReferenceError: Can't find variable: Pact in client-spec.js (line 8) client-spec.js:8:26 loaded@http://localhost:9876/context.js:168:19 TypeError: undefined is not an object (evaluating 'provider .addInteraction') in client-spec.js (line 25) client-spec.js:25:17 loaded@http://localhost:9876/context.js:168:19 ReferenceError: Can't find variable: Promise in client.js (line 18) sayHello@client.js:18:19 client-spec.js:47:24 loaded@http://localhost:9876/context.js:168:19 PhantomJS 2.1.1 (Mac OS X 0.0.0) Client findFriendsByAgeAndChildren returns some friends FAILED```

mui_ume
2019-06-20 09:16
I got a question: where should I place my pact folder? in the root directory or at the place where I want to do the test,in my case App/Screens/Login?

mui_ume
2019-06-20 09:16
my Login folder has index.js, LoginHelper.js, styles.js

mui_ume
2019-06-20 09:17
loginHelper.js has this code snippet: ```const loginEndpoint = settings.getLoginEndpoint(); try { const resp = await http://api.post(loginEndpoint, reqData); if (resp.ok) { const loginRespBody = await resp.json(); const { authToken, clientInfo } = loginRespBody; if (authToken) { const sessionResp = await api.startSession({ clientId: clientInfo.clientId, user: { authToken, userId: data.user.userId, }, });```

mui_ume
2019-06-20 09:17
this is where I want to test the endpoint

mui_ume
2019-06-20 10:01
let me share my folder....

matt.fellows
2019-06-20 10:42
You'll probably need to do an npm install in the root directory also

matt.fellows
2019-06-20 10:55
@mui_ume that example is not a Jest example, it is one of the Karma examples. Did you mean that?


mui_ume
2019-06-20 10:56
Is it not jest ?

mui_ume
2019-06-20 10:57
I?m going to continue working on later in an hour time ...

matt.fellows
2019-06-20 10:57
no worries

matt.fellows
2019-06-20 10:58
yes that?s definitely a jest example, the output you shared however is not consistent with that test. It looks like one of the Karma examples (`findFriendsByAgeAndChildren` is only something that exists in the karma examples)

matt.fellows
2019-06-20 11:04
I?ll have a go at making the examples easier to run. I can see why it might be difficult coming to a complex ecosystem like TS/JS

mui_ume
2019-06-20 12:54
I created a pact folder at the root same level as App

mui_ume
2019-06-20 12:54
in my pact folder, I added pactSetup.js with the content: // ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.port = 8080; global.provider = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'MyConsumer', provider: 'MyProvider', host: '127.0.0.1', });

mui_ume
2019-06-20 12:55
pactTestWrapper.js with the content: global.beforeAll((done) => { global.provider.setup().then(() => done()); }); global.afterAll((done) => { global.provider.finalize().then(() => done()); });

mui_ume
2019-06-20 12:55
publish.js with the content: onst { publisher } = require('@pact-foundation/pact-node'); const { path } = require('path'); const opts = { providerBaseUrl: 'http://localhost:8080', pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], pactBroker: 'https://localhost:3000', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, consumerVersion: '2.0.0', }; publisher.publishPacts(opts).then(() => global.done());

mui_ume
2019-06-20 12:55
in my package.json, I have these in: "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "lint": "eslint App/", "react-devtools": "react-devtools", "test": "jest", "test:pact": "cross-env CI=true react-scripts test --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch \"**/*.test.pact.js\"", "publish:pact": "node ./pact/publish.js" },

mui_ume
2019-06-20 12:56
"devDependencies": { "@babel/runtime": "^7.1.2", "@pact-foundation/pact": "^8.2.6", "@pact-foundation/pact-node": "^8.6.0", "axios": "^0.19.0", "babel-eslint": "^7.1.1", "babel-jest": "23.6.0", "babel-plugin-transform-remove-console": "^6.9.4", "babel-preset-react-native": "^4.0.1", "cross-env": "^5.2.0",

mui_ume
2019-06-20 12:56
"jest": { "preset": "react-native", "testEnvironment": "node" }

mui_ume
2019-06-20 12:57
from this link https://reflectoring.io/pact-react-consumer/, I run npm run test:pact

mui_ume
2019-06-20 12:57
it give me some errors: > cross-env CI=true react-scripts test --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch "**/*.test.pact.js" events.js:174 throw er; // Unhandled 'error' event ^ Error: spawn react-scripts ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19) at onErrorNT (internal/child_process.js:415:16) at process._tickCallback (internal/process/next_tick.js:63:19) at Function.Module.runMain (internal/modules/cjs/loader.js:745:11) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3) Emitted 'error' event at: at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)

mui_ume
2019-06-20 12:58
I am not sure what to do next? did I miss out any step here?

mui_ume
2019-06-20 12:59
I just want to make sure my pact configuration is ok before I continue to Let?s implement a REST client for which we?ll later create a consumer-driven contract.....

mui_ume
2019-06-20 12:59
but the step 'npm run test:pact' didn't work for me

matt.fellows
2019-06-20 13:02
Might I suggest you publish this to Github so that anyone who wants to help you can run the same code you?re running? This will make debugging much easier

mui_ume
2019-06-20 13:02
let me try to extract out the key parts...

matt.fellows
2019-06-20 13:02
Also, I?ve made a quick start on making the exampples in pact-js standalone (so that you can just run a `npm it` and it should just work). See this branch https://github.com/pact-foundation/pact-js/tree/feat%2Fexamples-use-exported-packages

matt.fellows
2019-06-20 13:04
no worries

matt.fellows
2019-06-20 13:04
Are you running the tests from this project in that article: https://github.com/thombergs/code-examples/tree/master/pact/pact-react-consumer

matt.fellows
2019-06-20 13:04
or are you writing your own now?

matt.fellows
2019-06-20 13:05
or rather, did you first get the tests all running successfully in that project before trying it for yourself?


matt.fellows
2019-06-20 13:06
And lastly, have you written a basic jest unit test? My worry is that you?re learning too many things at once: Unit testing in React, Jest and then Pact itself. You need to be comfortable in the first two before trying Pact.

matt.fellows
2019-06-20 13:06
It?s in the article you shared (the one Tom H wrote

mui_ume
2019-06-20 13:06
I was just looking at the blog and try to follow

matt.fellows
2019-06-20 13:06
OK, I?d suggest studying and running his code first. But not until you first understand Jest and unit testing in React

matt.fellows
2019-06-20 13:06
I have to run now (it?s late) but good luck!

mui_ume
2019-06-20 13:07
sure thanks for the tips.

matt.fellows
2019-06-20 13:07
As mentioned, I fixed the jest tests in this branch https://github.com/pact-foundation/pact-js/tree/feat/examples-use-exported-packages/examples/jest. You should be able to run this without building pact itself

mui_ume
2019-06-20 13:08
I just run your example/jest, it works now

mui_ume
2019-06-20 13:08
I will look at this example and work from there.... thanks a bunch!

closenet.uk
2019-06-20 14:46
has joined #pact-js

closenet.uk
2019-06-20 14:55
Hi #pact-js, I have a question regarding the term matcher using regex, why it doesn't like the below regex format, although it's a ruby version and tried on the ruby regex tester? it's even mentioned as an example in PACT docs! "update_date": term({ generate: '02/11/2013', matcher: '\d{2}\/\d{2}\/\d{4}' })

closenet.uk
2019-06-20 14:56
found why it's not liking the above regex format, for the benefit of others, all we need to is to add another backslash in front of the actual \d backslash *\\d{2}\/\\d{2}\/\\d{4}*



viktor
2019-06-21 11:53
has joined #pact-js

viktor
2019-06-21 13:56
Hello, so i have an endpoint that i want to match that returns exactly 3 different elements in an array. how can i test that: a) they are exactly 3 b) that they are all different, if i do: ``` eachLike( term({ matcher: 'A|B|C', generate: 'C' }), { min: 3 } ) ``` the elements can be more than 3, and they can also be the same 3 times. I also tried ``` like([ term({ matcher: 'A|B|C', generate: 'A' }), term({ matcher: 'A|B|C', generate: 'B' }), term({ matcher: 'A|B|C', generate: 'C' }) ]) ``` and while that stubs my three different elements, they dont validate that they are different. Is there a way to achieve this? or im i looking at this wrong?

matt.fellows
2019-06-22 02:38
In pact js you can't specify the specific array length with an eachLike matcher

matt.fellows
2019-06-22 02:39
Just remove the eachLike wrapper and have an array that contains three elements. If the values must be different and there are only 3 possible vakues, then just specify the exact array you're expecting (i.e. don't use matchers)

dalsidhu99
2019-06-23 11:33
hi all, i was wondering if somebody could please help. I am new to pact and still a beginner with javascript but i have managed to get a test/interaction working against the mock client. However sometimes the test passes and sometimes it doesnt

dalsidhu99
2019-06-23 11:34
see the mock-server integration log here

dalsidhu99
2019-06-23 11:35
it looks like there is some time taken to actually get the response back from the server and in that time pact is already checking to see whether there has been a response that has come back

bethskurrie
2019-06-23 11:35
Looks like you've got timing issues. Sometimes your test is executing before your interactions have been set up, and sometimes it's ok.

matt.fellows
2019-06-23 11:35
Hi @dalsidhu99 it looks like requests are coming in out of order. So I suspect you aren't handling a promise correctly

dalsidhu99
2019-06-23 11:36
i have added a few asyncs and awaits but this doesnt seem to be resolving the issue

matt.fellows
2019-06-23 11:36
Show us your code and I can take a quick look

dalsidhu99
2019-06-23 11:36
(im a newbie to js)

dalsidhu99
2019-06-23 11:36
thank you

dalsidhu99
2019-06-23 11:36
describe('Consumer test example', () => { beforeEach(async () => { await service.setup() }) it('can return a response', async () => { l('add interaction') await service.addInteraction(interactions.getFirstUser); await client.getProducts() await service.verify() await service.finalize() }) })

dalsidhu99
2019-06-23 11:37
******

dalsidhu99
2019-06-23 11:37
async function getProducts () { await request.get({url: USERS_URL}, function (error, response, body) { expect(response.statusCode).to.equal(200); expect(response.body).to.contains("Dal"); }) return getProducts }

dalsidhu99
2019-06-23 11:37
(apologies for not using code snippet)

bethskurrie
2019-06-23 11:39
And this is the part where I go to bed and leave Matt to help you because I'm so not a javascript person :-P

matt.fellows
2019-06-23 11:42
Something looks wrong in getproducts. That's not a promise but a callback so by putting async and await on that won't do anything.

matt.fellows
2019-06-23 11:42
I'd look to that method as the source of the issue (or look at a promise lib like axios)

dalsidhu99
2019-06-23 11:43
thanks matt, I have heard about axios so will def give that a look!

dalsidhu99
2019-06-23 23:13
and how would we publish a test to the pact broker? i have just set up the web based view, .. http://pact.dius.com ..



matt.fellows
2019-06-23 23:21
You probably also want to read how to tag properly at https://github.com/pact-foundation/pact_broker/wiki/Using-tags

dalsidhu99
2019-06-24 00:13
and as for pactbroker username/password, i only have the UI credentials through email and api token

matt.fellows
2019-06-24 00:16
There is a mode for authenticating with a bearer token

dalsidhu99
2019-06-24 00:32
does/will the UI at some point allow us to view the interactions that have been ran against a service?

matt.fellows
2019-06-24 00:39
What does that mean, sorry?

mui_ume
2019-06-24 03:27
Hi, When I add "@pact-foundation/pact": "^8.2.6", "@pact-foundation/pact-node": "^8.6.0", "axios": "^0.19.0", to the package.json, I will got a error when building the react-native app in xcode. this is the error I got : error: bundling failed: TypeError: Cannot read property 'bindings' of null at Scope.moveBindingTo (/Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@babel/traverse/lib/scope/index.js:864:13) at BlockScoping.updateScopeInfo (

mui_ume
2019-06-24 03:27
any one encounter such error?

mui_ume
2019-06-24 03:33
suspect babel pact has some problem with transpiling is it has any specific version that it need for babel

mui_ume
2019-06-24 04:17
I got to remove the "react-native" from the preset at babelrc in order to build the app in xcode. now the babelrc looks like this: "presets": ["module:metro-react-native-babel-preset"],

mui_ume
2019-06-24 04:22
but when I run npm run test:pact, it will give an error ```npm run test:pact > tlstellaclientapp@0.0.1 test:pact /Users/tohlaymui/Desktop/tl_stella-client_app > jest __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch "**/*.test.pact.js" FAIL App/Screens/Login/__tests__/login.service.test.pact.js ? Test suite failed to run Couldn't find preset "module:metro-react-native-babel-preset" relative to directory "/Users/tohlaymui/Desktop/tl_stella-client_app" at node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19 at Array.map (<anonymous>) at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20) ```


mui_ume
2019-06-24 04:28
this fixed the issue

mui_ume
2019-06-24 04:29
I added this line to package.json ```"jest": { "preset": "react-native", "testEnvironment": "node", "transform": { "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js" } }```

tjones
2019-06-24 04:31
Thanks @mui_ume. It looks like the issue you're experiencing is unrelated to pact?

mui_ume
2019-06-24 04:34
yes but if you are using react-native app with babelrc, and then run the pact test, it will have this issue Couldn't find preset 'module: metro-react-native-babel-preset'...

tjones
2019-06-24 04:47
Unless I'm missing something, isn't this a problem with react-native and Jest, rather than react-native and pact?

tjones
2019-06-24 04:47
(yes, you'll hit it if you're using Jest as your test runner for react-native, but that's true for all your Jest tests, not just pact)

tjones
2019-06-24 04:54
Apologies if I missed something

matt.fellows
2019-06-24 05:02
Yep, I think this is true. Lay has taken on the burden of learning JS, React, React Native, Jest and Pact all in one go - so rather impressive to get a green Pact consumer build in one weekend :stuck_out_tongue:

dalsidhu99
2019-06-24 09:30
Apologies, i had just got the pact published to the broker, wanted to see if the consumer mock tests against the provider could be seen via the ui (not sure if it would make sense if we did, just thinking out aloud)

mui_ume
2019-06-25 03:03
Hi, when I run npm run publish:pact, I got this error > node ./pact/publish.js /Users/tohlaymui/Desktop/tl_stella-client_app/pact/publish.js:6 pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], ^ TypeError: Cannot read property 'resolve' of undefined at Object.<anonymous> (/Users/tohlaymui/Desktop/tl_stella-client_app/pact/publish.js:6:26)

mui_ume
2019-06-25 03:03
my pact/publisher.js: ```const { publisher } = require('@pact-foundation/pact-node'); const { path } = require('path'); const opts = { providerBaseUrl: 'http://localhost:8080', pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], pactBroker: 'https://tl.pact.dius.com.au/', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, consumerVersion: '2.0.0', }; publisher.publishPacts(opts).then(() => console.log('Pacts successfully published')); ```

mui_ume
2019-06-25 03:03
node --version v10.15.1

abubics
2019-06-25 03:44
this bit: ``` pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], ^ TypeError: Cannot read property 'resolve' of undefined ```

abubics
2019-06-25 03:45
means that the local variable `path` is undefined.

abubics
2019-06-25 03:45
you're importing it through a destructure (as `{ path }`)

abubics
2019-06-25 03:45
so that line is probably not doing what you want

abubics
2019-06-25 03:46
in a project I have lying around (recent-ish), I have it without the destructure: ``` const path = require('path'); ```

mui_ume
2019-06-25 03:46
got it thanks Boris

mui_ume
2019-06-25 03:46
it passed, now it is the issue publisher.publishPacts(opts).then(() => console.log('Pacts successfully published')); ^ TypeError: Cannot read property 'publishPacts' of undefined at Object.<anonymous> (/Users/tohlaymui/Desktop/tl_stella-client_app/pact/publish.js:13:11) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)

mui_ume
2019-06-25 03:47
same issue as you mentioned :slightly_smiling_face:

abubics
2019-06-25 03:48
yep, looks like exactly the same symptom

mui_ume
2019-06-25 03:48
now I got this message out ```> node ./pact/publish.js [2019-06-25T03:47:20.723Z] INFO: pact-node@8.6.0/7286 on LayMui.local: Publishing Pacts to Broker [2019-06-25T03:47:20.726Z] INFO: pact-node@8.6.0/7286 on LayMui.local: Publishing pacts to broker at: https://tl.pact.dius.com.au/ [2019-06-25T03:47:20.732Z] INFO: pact-node@8.6.0/7286 on LayMui.local: Created './standalone/darwin-1.68.0/bin/pact-broker publish '/Users/tohlaymui/Desktop/tl_stella-client_app/pacts' --broker-base-url 'https://tl.pact.dius.com.au/' --consumer-app-version '2.0.0'' process with PID: 7287 [2019-06-25T03:47:33.513Z] WARN: pact-node@8.6.0/7286 on LayMui.local: Pact exited with code 1. [2019-06-25T03:47:33.513Z] ERROR: pact-node@8.6.0/7286 on LayMui.local: Could not publish pact: Error making request - SocketError getaddrinfo: nodename nor servname provided, or not known /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.68.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 1 of 3 Error making request - SocketError getaddrinfo: nodename nor servname provided, or not known /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.68.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 2 of 3 Error making request - SocketError getaddrinfo: nodename nor servname provided, or not known /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.68.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.18.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 3 of 3 Failed to publish MyConsumer/MyProvider pact due to error: SocketError - getaddrinfo: nodename nor servname provided, or not known```

mui_ume
2019-06-25 03:50
I need to source my .env which defined the authentication PACT_USERNAME, PACT_PASSWORD

abubics
2019-06-25 03:52
that's right, if you don't have the vars in your env before running `publish.js`, they'll be undefined :ok_hand:

mui_ume
2019-06-25 03:53
```[2019-06-25T03:50:04.435Z] INFO: pact-node@8.6.0/7334 on LayMui.local: Publishing Pacts to Broker [2019-06-25T03:50:04.437Z] INFO: pact-node@8.6.0/7334 on LayMui.local: Publishing pacts to broker at: https://tl.pact.dius.com.au/ [2019-06-25T03:50:04.444Z] INFO: pact-node@8.6.0/7334 on LayMui.local: Created './standalone/darwin-1.68.0/bin/pact-broker publish '/Users/tohlaymui/Desktop/tl_stella-client_app/pacts' --broker-base-url 'https://tl.pact.dius.com.au/' --consumer-app-version '2.0.0'' process with PID: 7335 [2019-06-25T03:50:06.597Z] WARN: pact-node@8.6.0/7334 on LayMui.local: Pact exited with code 1. [2019-06-25T03:50:06.597Z] ERROR: pact-node@8.6.0/7334 on LayMui.local: Could not publish pact: Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ ```

mui_ume
2019-06-25 03:53
I need to login to the pact-broker

mui_ume
2019-06-25 03:56
I still not sure how to use the pact broker to see the publish pact file?

mui_ume
2019-06-25 03:57
If the publishing succeed, I should see something at the pact broker host? https://tl.pact.dius.com.au/

matt.fellows
2019-06-25 03:58
As mentioned, you need to get an API token from the broker settings page, and use the `pactBrokerToken` option (see https://github.com/pact-foundation/pact-js/#publishing-options)

matt.fellows
2019-06-25 03:59
> If the publishing succeed, I should see something at the pact broker host? https://tl.pact.dius.com.au/ Yes

mui_ume
2019-06-25 04:57
I have set the pactBrokerToken ```const publisher = require('@pact-foundation/pact-node'); const path = require('path'); const opts = { providerBaseUrl: 'http://localhost:8080', pactFilesOrDirs: [path.resolve(process.cwd(), 'pacts')], pactBroker: 'https://tl.pact.dius.com.au/', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, pactBrokerToken: 'EgtLgimSQeaImlMZ4ToqAQ', consumerVersion: '2.0.0', }; publisher.publishPacts(opts).then(() => console.log('Pacts successfully published')); ```

mui_ume
2019-06-25 04:57
but still fail ```[2019-06-25T04:56:08.842Z] WARN: pact-node@8.6.0/4924 on LayMui.local: Pact exited with code 1. [2019-06-25T04:56:08.842Z] ERROR: pact-node@8.6.0/4924 on LayMui.local: Could not publish pact: Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ ```


tjones
2019-06-25 05:05
*it's generally better to use the cli to publish pacts if you can

tjones
2019-06-25 05:09
``` pact-broker publish ./pacts -a 2.0.0 -p "$PACT_PASSWORD" -u "$PACT_USERNAME" -b https://tl.pact.dius.com.au/ ```

tjones
2019-06-25 05:09
^ This line does the same as your example

tjones
2019-06-25 05:12
Do we have a way of taking a JS object and seeing if it matches the result from matchers? For example: ``` const pactResponseBody = { filenames: eachLike('foo.jpg'), }; const mockResponseBody = { filenames: [ "a.gif", "bar.jpg" ], }; const otherResponseBody = { some: { other: { structure:[ "a.gif", "bar.jpg" ], }, }, }; if (/* mockResponseBody matches pactResponseBody */) {} // true if (/* otherResponseBody matches pactResponseBody */) {} // false ``` is there anything I can put in the `if` to achieve this?

mui_ume
2019-06-25 05:13
I Need to install pact-broker?

tjones
2019-06-25 05:15
no, the cli tools come with `@pact-foundation/pact-node` as binstubs. You can put the command above in a script in `package.json`

tjones
2019-06-25 05:15
Note that your script actually publishes the same version every time

tjones
2019-06-25 05:15
you need some way to locally determine the version

mui_ume
2019-06-25 05:18
like this : "publish:pact": "pact-broker publish ./pacts -a 2.0.0 -p "$PACT_PASSWORD" -u "$PACT_USERNAME" -b https://tl.pact.dius.com.au/"

tjones
2019-06-25 05:18
And, if we don't have this, should we?

mui_ume
2019-06-25 05:21
didn't work as well, I got this error ```> pact-broker publish ./pacts -a 2.0.0 -p $PACT_PASSWORD -u $PACT_USERNAME -b https://tl.pact.dius.com.au/ Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! tlstellaclientapp@0.0.1 publish:pact: `pact-broker publish ./pacts -a 2.0.0 -p $PACT_PASSWORD -u $PACT_USERNAME -b https://tl.pact.dius.com.au/` npm ERR! Exit status 1 ```

mui_ume
2019-06-25 05:21
maybe I try to use my own local pact broker? without any authentication?

tjones
2019-06-25 05:21
The use case is for mocking the response from the API layer outside pact tests (but keeping them in sync with pact tests). to avoid this: ``` const someApiCall() = {/* .... */}; describe("pact test", () => { /* asserts that someApiCall() calls the provider in some way, and returns some object foo to the caller */ }) describe("unit test for caller", ()=> { /* mocks someApiCall() as returning some object bar, and asserts that the rest of the code behaves */ }) ``` In this situation, all tests could be green, even if there's actually a failure (since the `someApiCall()` actually returns a different object to the one tested in the unit tests for the call site)


mui_ume
2019-06-25 05:24
I copy the token at Read only token (developer)?

tjones
2019-06-25 05:24
You need the read/write token to publish

tjones
2019-06-25 05:25
Also, in the output that you sent above, you're not using the API token ,you're using the username and password

tjones
2019-06-25 05:25
see the second link above for the options for `pact-broker publish`

mui_ume
2019-06-25 05:30
```> tlstellaclientapp@0.0.1 publish:pact /Users/tohlaymui/Desktop/tl_stella-client_app > pact-broker publish ./pacts -k 'aF5qJ0rVTGlYQNe280IAAQ' -a 2.0.0 -p $PACT_PASSWORD -u $PACT_USERNAME -b https://tl.pact.dius.com.au/ Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ Failed to publish MyConsumer/MyProvider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published```

mui_ume
2019-06-25 05:30
I copied the token from the Read/Write token (CI), still have the Authentication Failed Error

tjones
2019-06-25 05:30
you probably need to not specify the username and password

tjones
2019-06-25 05:30
we should make that clear in the documentation

mui_ume
2019-06-25 05:31
got it

mui_ume
2019-06-25 05:31
```> tlstellaclientapp@0.0.1 publish:pact /Users/tohlaymui/Desktop/tl_stella-client_app > pact-broker publish ./pacts -k 'aF5qJ0rVTGlYQNe280IAAQ' -a 2.0.0 -b https://tl.pact.dius.com.au/ Publishing MyConsumer/MyProvider pact to pact broker at https://tl.pact.dius.com.au/ The latest version of this pact can be accessed at the following URL (use this to configure the provider verification): https://tl.pact.dius.com.au/pacts/provider/MyProvider/consumer/MyConsumer/latest LayMui:tl_stella-client_app tohlaymui$ ```

mui_ume
2019-06-25 05:46
I can't seem to run pact-broker in the command line

mui_ume
2019-06-25 05:46
pact-broker describe-version -b https://tl.pact.dius.com.au/ -a MyConsumer,MyProvider

mui_ume
2019-06-25 05:46
trying to use this command line to get the version?

tjones
2019-06-25 05:47
That's because it's included as a binary through npm, it's not on the path

tjones
2019-06-25 05:48
you can find it in `node_modules/.bin`

tjones
2019-06-25 05:49
That command will get the version that the broker knows about

tjones
2019-06-25 05:49
My comment above was that your script would have published the same application version every time

tjones
2019-06-25 05:50
I/we can't tell you how to determine what your application version is, because it's up to you and your team

tjones
2019-06-25 05:50
see https://docs.pact.io/getting_started/versioning_in_the_pact_broker for some guidelines on how versioning works in Pact

matt.fellows
2019-06-25 05:58
I think you can call `getValue()` on them to get the value _sans_ matcher guff, but from memory that?s not recursive for deeply nested matchers

matt.fellows
2019-06-25 05:58
`extractPayload(pactResponseBody)` will do the same, but recursive

matt.fellows
2019-06-25 05:59
I think what you?re asking is not currently possible (because you won?t be able to do an equality check), but is intriguing

tjones
2019-06-25 07:57
I think `extractPayload` gives me the raw json (useful to achieve the goal, but not what I'm asking for). Is that right?

tjones
2019-06-25 07:58
I'd like to have a few different ways of doing this, so that Pact's opinions don't bleed into the unit test suite

matt.fellows
2019-06-25 10:39
Yep, extract payload would turn: ``` eachLike({ foo: term({generate: "bar", matcher: "[?regex?]"}), baz: [ "bats" ] }) ``` into: ``` [{ foo: "bar", baz: [ "bats" ] }] ```

matt.fellows
2019-06-25 10:46
So basically what you want is the ability to apply a pact matcher in unit test?

dalsidhu99
2019-06-25 12:08
hi all, my test is failing add this level - service.addInteraction(interaction);

dalsidhu99
2019-06-25 12:08
could this be something to do with the mock server?

matt.fellows
2019-06-25 12:09
What's the actual error. Have you enabled debug logs and followed the troubleshooting section of the readme?

dalsidhu99
2019-06-25 12:17
this is what i get - "You must provide a description for the interaction."

matt.fellows
2019-06-25 12:36
There's your answer. You're missing a required field on the interaction object

alessandrobuggin
2019-06-25 14:13
has joined #pact-js

dalsidhu99
2019-06-26 22:00
hi there, when we have published tests to the broker, how do we get tests replayed on the provider side? thanks

matt.fellows
2019-06-26 22:01
What have you tried?

matt.fellows
2019-06-26 22:01
Are the examples in the repo not clear?

whitehorse5353
2019-06-27 16:57
has joined #pact-js

whitehorse5353
2019-06-27 16:58
Hi All, i am having a weird issue my query param is around 2588 char length of base65 encoded string some home pact breaks the url query param into two portions and fails my test any idea anyone ?

whitehorse5353
2019-06-27 17:00
versions of my package @pact-foundation/pact: 5.9.1 @pact-foundation/pact-node: 6.19.7

matt.fellows
2019-06-28 00:06
Hi Lokesh. Firstly, have you tried upgrading to a latter version of Pact? (yours is quite old)

matt.fellows
2019-06-28 00:06
secondly, please provide a reproducable example so we can help, or at the very least a stack trace / error log

tjones
2019-06-28 01:27
Yes. Often the response you expect from the API layer is the same as the json on the wire. So, you could write: ``` const pactBody = eachLike({ foo: term({generate: "bar", matcher: "[?regex?]"}), baz: [ "bats" ] }); /* ... */ expect(someApiCall()).toEqual(extractPayload(pactBody)); ```

tjones
2019-06-28 01:28
or perhaps even nicer: ``` expect(someApiCall()).toMatchPactResponse(pactBody); ```

doxuantien
2019-06-28 03:34
has joined #pact-js

vitaliy.grigoruk
2019-06-28 07:14
pact plugin for `chai`? :slightly_smiling_face:

rafael.anachoreta
2019-06-28 09:15
Was looking into this just now! I second that there is some demand for v3 in pact-js :slightly_smiling_face: And thanks for sharing the approach above

whitehorse5353
2019-06-28 23:55
Hi @matt.fellows, sorry that was my mistake and it's resolved now thanks :slightly_smiling_face:

tjones
2019-06-30 23:20
@yousafn and I have been working on a Jest wrapper

tjones
2019-06-30 23:20
but we haven't done anything for expect yet

tjones
2019-06-30 23:21
it would be easy to extend / modify what we currently have for other test frameworks (I think it currently works with anything Jasmine based)

mui_ume
2019-07-01 03:23
I like to check if my provider is more than 1, how do I specify in my pactSetup file, current pactSetup.js file ```// ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.port = 8080; global.provider = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Platform Services', host: '127.0.0.1', }); ```

mui_ume
2019-07-01 03:23
my consumer is the UI app, it will talk to a few backend services. how do I specify that in the pactsetup file? thanks

bethskurrie
2019-07-01 03:24
you make one configuration for each provider

bethskurrie
2019-07-01 03:24
global.provider1 = ... global.provider2 = ...

bethskurrie
2019-07-01 03:25
But use the real name of your provider instead of `provider1`. eg `global.platformServices`

mui_ume
2019-07-01 03:29
let me redo my pact/setup.js ...

mui_ume
2019-07-01 03:31
```// ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.port = 8080; global.platformServices = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', PlatformServices: 'Platform Services', host: '127.0.0.1', }); global.LENS = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', LENS: 'LENS', host: '127.0.0.1', }); ```

mui_ume
2019-07-01 03:31
is it like this?

mui_ume
2019-07-01 03:32
or it's in the same file or separate setup files?

bethskurrie
2019-07-01 03:33
whatever works for you.

bethskurrie
2019-07-01 03:33
just make sure it's required before you run the test that uses it

bethskurrie
2019-07-01 03:33
you'll need to put them on different ports.

mui_ume
2019-07-01 03:34
I see what you mean now thanks

mui_ume
2019-07-01 04:00
do I need to specify different global.port for different provider?

bethskurrie
2019-07-01 04:00
yes

bethskurrie
2019-07-01 04:00
you can't run two processes on the same port

mui_ume
2019-07-01 05:25
can I check? what is the spec:2 means?

matt.fellows
2019-07-01 05:28
It says what specification of the Pact framework to use. The specification is what defines what features are compatible across language implementations. Most support v2, Pact JVM has some advanced features (e.g. mulitple provider states, ability to pass parameters with the states) that are only available in v3+. So if you need a pact file to interop across languages, you need to make sure you only use features the other languages support. It actually defaults to 2 anyway

mui_ume
2019-07-01 05:34
thanks. my pact framework will need to have mulitple language support. my consumer is in JS, my provider can be in Java, C# or C++, so I need to set to 3?

matt.fellows
2019-07-01 05:38
no, JS and .NET only supports 2. I?d stick with 2

mui_ume
2019-07-01 05:39
okay, I change my pactSetup.js to configure for multiple provider like this: ```global.portIM = 8080; global.portSM = 8082; global.portCM = 8083; global.hostIM = '127.0.0.1'; global.hostSM = '127.0.0.2'; global.hostCM = '127.0.0.3'; global.IdentityManager = new Pact({ cors: true, port: global.portIM, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Identity Manager', host: global.hostIM, }); global.SessionManager = new Pact({ cors: true, port: global.portSM, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Session Manager', host: global.hostSM, }); ```

mui_ume
2019-07-01 05:40
in my consumer test, I change this baseURL like this ```// add expectations it('returns a successfully body', done => axios.request({ method: 'POST', baseURL: `${global.portIM} + ':' + ${global.hostIM}`, url: '/api/identity-manager/v2/login', headers: { Accept: '*/*', 'content-type': 'application/json', }, data: BODY, })```

mui_ume
2019-07-01 05:40
when I run npm run test:pact

mui_ume
2019-07-01 05:41
I got the error: ``` Setting up Pact with Consumer "UI Client" and Provider "Identity Manager" using mock service on Port: "8080" console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: POST /api/identity-manager/v2/login See /Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact.log for details. FAIL App/Screens/Login/__tests__/login.service.test.pact.js (21.948s) LoginService API login request ? returns a successfully body (20073ms) ```

matt.fellows
2019-07-01 05:42
what does the log file say

mui_ume
2019-07-01 05:44
```W, [2019-07-01T13:43:37.282865 #8497] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /api/identity-manager/v2/login W, [2019-07-01T13:43:37.282959 #8497] WARN -- : Missing requests: POST /api/identity-manager/v2/login ```

mui_ume
2019-07-01 05:45
wait, I miss out the http...

mui_ume
2019-07-01 05:47
baseURL: `'http' + ${global.portIM} + ':' + ${global.hostIM}`,

mui_ume
2019-07-01 05:47
I need to fix this line...

tjones
2019-07-01 05:49
You have also got `port` and `host` the wrong way around - it should be: ``` baseUrl: `http://${global.hostIM}:${global.portIM}` ```

tjones
2019-07-01 05:49
host goes before port

mui_ume
2019-07-01 05:52
thanks, it works now :slightly_smiling_face:

mui_ume
2019-07-03 13:55
when I run npm run test to run my jest (react-native), it got into the pact test and fail

mui_ume
2019-07-03 13:55
```npm run test > tlstellaclientapp@0.0.1 test /Users/tohlaymui/Desktop/tl_stella-client_app > jest PASS App/Utils/DataBindings/__tests__/valueRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/appVariableRegexProcessor.js PASS App/Utils/DataBindings/__tests__/appendRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/removeRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/containsInProcessor.test.js PASS App/Utils/DataBindings/__tests__/formSubmitWithTypeRegexProcessor.test.js PASS App/Utils/DataBindings/__tests__/sourceRegexProcessor.test.js FAIL App/Screens/Login/__tests__/login.service.test.pact.js (7.212s) ? LoginService API ? login request ? returns a successfully body TypeError: Cannot read property 'addInteraction' of undefined 42 | }, 43 | }; > 44 | return global.IdentityManager.addInteraction(interaction); | ^ 45 | }); 46 | 47 | // add expectations at Object.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:44:37) ? LoginService API ? login request ? returns a successfully body Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout. 46 | 47 | // add expectations > 48 | it('returns a successfully body', done => axios.request({ | ^ 49 | method: 'POST', 50 | baseURL: `http://${global.hostIM}:${global.portIM}`, 51 | url: '/api/identity-manager/v2/login', at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:85:20) at Suite.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:48:5) at Suite.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:23:3) at Object.<anonymous> (App/Screens/Login/__tests__/login.service.test.pact.js:7:1) Test Suites: 1 failed, 7 passed, 8 total Tests: 1 failed, 10 passed, 11 total Snapshots: 0 total```

mui_ume
2019-07-03 13:55
here is my package.json: ``` "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "lint": "eslint App/", "react-devtools": "react-devtools", "test": "jest", "test:pact": "jest cross-env CI=true __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch \"**/*.test.pact.js\"", "publish:pact": "pact-broker publish ./pacts -a 2.0.0 -b https://pact.shared.frigg.li/" },```

mui_ume
2019-07-03 13:57
but if I do npm run test:pact it passed: ``` > tlstellaclientapp@0.0.1 test:pact /Users/tohlaymui/Desktop/tl_stella-client_app > jest cross-env CI=true __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile ./pact/pactTestWrapper.js --testMatch "**/*.test.pact.js" [2019-07-03T13:56:50.701Z] INFO: pact-node@8.6.0/9754 on LayMui.local: Creating Pact Server with options: consumer = UI Client, cors = true, dir = /Users/tohlaymui/Desktop/tl_stella-client_app/pacts, host = 127.0.0.1, log = /Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact.log, pactFileWriteMode = update, port = 8080, provider = Identity Manager, spec = 2, ssl = false, sslcert = , sslkey = [2019-07-03T13:56:50.703Z] INFO: pact-node@8.6.0/9754 on LayMui.local: Creating Pact Server with options: consumer = UI Client, cors = true, dir = /Users/tohlaymui/Desktop/tl_stella-client_app/pacts, host = 127.0.0.2, log = /Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact.log, pactFileWriteMode = update, port = 8082, provider = Session Manager, spec = 2, ssl = false, sslcert = , sslkey = [2019-07-03T13:56:50.703Z] INFO: pact-node@8.6.0/9754 on LayMui.local: Creating Pact Server with options: consumer = UI Client, cors = true, dir = /Users/tohlaymui/Desktop/tl_stella-client_app/pacts, ```

matt.fellows
2019-07-03 22:06
Why is IdentityManager undefined? ` TypeError: Cannot read property 'addInteraction' of undefined`.

matt.fellows
2019-07-03 22:07
oh I see

matt.fellows
2019-07-03 22:07
what is your question? Something you?re doing with `npm run test:pact` is setting IdentityManager (presumably a file that does some setup e.g. `pactSetup.js `)

matt.fellows
2019-07-03 22:08
And when you run `npm run test` it?s not configuring it

mui_ume
2019-07-04 10:46
this is fixed by using a different folder name for pact test. so I used __pact-tests__ instead of __tests__

thamu.gurung
2019-07-08 20:01
has joined #pact-js

fraser.crichton.devel
2019-07-09 00:29
has joined #pact-js

craig.pothier
2019-07-09 15:17
has joined #pact-js

yousafn
2019-07-09 16:50
Ola all, When performing pact-verification, if we are using `pactUrls` to read from a local file, how can we publish the verification results to the pact broker? If I specify a `pactBrokerUrl`, then the local pacts are read, and also the pacts read from the pact-broker. I only want to read from the local pacts, and publish the verification results up to the broker. Basically I am 1. Downloading a pact for a given consumer/provider pair by tag, via axios into a local file 2. I then parse the local json file, and pull out the path/request/body and use aws4 to sign the request 3. I then inject the modified headers back into the pact file 4. I run my provider verification, using `pactUrls` to point to my local version of the file 5. to close the loop, I want to publish the verification results back up to the broker. It follows on my from my issue raised here https://github.com/pact-foundation/pact-js/issues/304 and my workaround is similar to that proposed by @bernardo.guerreiro in his medium article here https://medium.com/dazn-tech/pact-contract-testing-dealing-with-authentication-on-the-provider-51fd46fdaa78

yousafn
2019-07-09 16:53
ahhh looking at this https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-results it seem?s that it is not possible ``` Note that you can only publish verification results for pacts that were retrieved from a pact broker. You cannot publish results for local pact files. ``` :disappointed:

matt.fellows
2019-07-09 21:15
If you?re pulling from the broker in the first place, it should have the HAL links in them containing paths to the broker

matt.fellows
2019-07-09 21:16
that?s all the verifier needs to be able to publish the results

matt.fellows
2019-07-09 21:17
i.e. if you run `curl -v https://test.pact.dius.com.au/pacts/provider/Van-test_bobby/consumer/Van-test_billy/latest --user dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1 | jq .` you can see the `pb:publish-verification-results` link. If you retain those you should be golden

yousafn
2019-07-10 07:42
Fab!! Cheers homie, I shall give that a go when I am in work shortly! Nice one!!!

yousafn
2019-07-10 09:46
That works perfectly matey, nice one for that :ok_hand:

matt.fellows
2019-07-10 10:47
SWEET!

matt.fellows
2019-07-10 10:47
you?re welcome

yousafn
2019-07-10 10:57
I?ll get an example up in my public repo at some point, so I can share back my solution with the community! Holding a pact-party with my client soon, in order to get them fully on board with pact, they can see the value in theory, but just need to show them it working in practise now on their end. Will probably write up some more slides, so will share them out too in another blog post

matt.fellows
2019-07-10 11:20
Thanks man

matt.fellows
2019-07-10 11:21
We?ve been discussing internally how the removal of the ?completely? free open-source hosted tier of http://Pactflow.io (i.e. what was previously the beta) might effect adoption etc. If in those discussions you run into issues, please let us know. We?re still figuring out what the best approach is from a commercial and community perspective, and real-life feedback is the best!

yousafn
2019-07-10 11:24
no worries mate, I?ve got an open source version of pactflow but not currently pumping any contracts into it, just haven?t taken the time to do so. If you want me to do so, so I can let you know if it goes up/down, then I can switch over my OS CI jobs to point at the pact-flow version today

matt.fellows
2019-07-10 11:25
ha, well hopefully we can do better than have our customers tell us when its down :stuck_out_tongue:

matt.fellows
2019-07-10 11:26
This is more of the adoption question - we work for a consultancy too and often we get asked to, or implement Pact during the course of delivery. It was really nice to just sign up for another free hosted broker for clients and just get cracking, rather than having to run a broker internally, manage it etc.

matt.fellows
2019-07-10 11:27
We?ve removed the ?free for all? plan, which changes that conversation a bit

matt.fellows
2019-07-10 11:27
all good, just know we?re here

yousafn
2019-07-10 11:44
Hmmm, I think in order to drive paid for adoption, providing a 2/4 week trial, similar to most other paid for tools would be preferable, It would allow companies to get time to implement a workflow and see how it pans out, and then as they will have the infra in place, it should be easier to get the beancounters to open their wallets and pay you money! It?s so trivial to spin up pact broker via docker, and postgres. pretty much all of our clients use AWS so sticking PB on an ecs cluster, and postgres is RDS means it?s pretty self managed anyway, and I imagine most of these teams have devops. A 4 week trial would probably give a team enough time to get the consumers and providers on board for at least a couple of services and start seeing enough of a benefit.

matt.fellows
2019-07-10 11:45
Thanks, sorry I probably wasn?t clear. I?m _not_ asking for you to help sell Pactflow (but, that would be great if that?s something that naturally comes up because it somehow helps you). I just mean Pact adoption here - the less things that need to be done to get started playing with Pact == higher chance of adoption

matt.fellows
2019-07-10 11:46
but your points taken

yousafn
2019-07-10 15:02
`I'm _not_ asking for you to help sell Pactflow` - I didn?t get that from your message, sorry if my reply sounded like I took that from your comment, I have just always been (sometimes wrongly) overly opinionated

matt.fellows
2019-07-10 21:42
You mean you're a _consultant_ :yum:

mui_ume
2019-07-11 03:49
I got a question on pact. in my consumer's pact test, I specify my expected body's content example: ``` const EXPECTED_BODY = { authToken: 'eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyMTVhMGVhZS00ZjkwLTRlODItOWY4Zi1lNzhlOTdkMzcyODAiLCJldmVudF9pZCI6IjQxMjA3MjQwLWI2NGEtNDYxNi1iOGFiLTJkYzNiZjY4YWEwNCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE1NjEwOTUwMDYsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0yX2EzbE5SRU5QMSIsImV4cCI6MTU2MTA5ODYwNiwiaWF0IjoxNTYxMDk1MDA2LCJqdGkiOiJlNGFiNTI0Ny1hZjgwLTQ1MmUtOTcwMS01YjQ4OTY1ZTcwZDgiLCJjbGllbnRfaWQiOiI2Z2xwbmRxb2s2YWhua3M2dGFnNXQ5cGMwZyIsInVzZXJuYW1lIjoicWFAdGVsZXBhdGh5LmFpIn0.icFT50MVM-xhAPIu76H9XwIeNHhbe6_d3LcAv1qDQcRp1xabxpgzntgaEvyUnaTwFFJzkU2flfIrT_Y8TCeeFFqMFrMkpS9GadVtraxpOtNhMwxrwUz6bbz8iMHFxSxcIi0Ar3y06RLoRkp3C4gXf7eL8JXsTI9IB56TK7idvUmUcbN_322UPsAU98l3XFjdQEkMo3Fnqyrr41ftWBH876E2KB4g79Q73AL_s0j7mRmXjGswu8-pFiyPcIrDZKz35RSEpdWYLoRyW8rDnYU6YqWM-ncXEczBKlBKk6ggxMOK_qcTc7HYBty9c16zOn-33hxLCxG6pOtg5vLD3L0Tqw', clientInfo: { clientId: '0662923d-b187-4879-866a-3f053178426a', }, };```

mui_ume
2019-07-11 03:50
what happen if this expected body's value is dynamic? the provider may return different value. how do I check this in my code?

matt.fellows
2019-07-11 03:53
look into matchers

mui_ume
2019-07-11 05:18
thanks will ask my developer to check that out

mui_ume
2019-07-12 08:06
Hi, I am adding the pact test at the consumer and talk to a few services -Identity Manager, Session Manager, etc. do I have only 1 pact file for all the tests?

matt.fellows
2019-07-12 08:06
no, 1 pact per consumer-provider pair

mui_ume
2019-07-12 08:13
is my pactTestWrapper.js correctly specified: ```jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; beforeAll((done) => { global.IdentityManager.setup().then(() => done()); global.SessionManager.setup().then(() => done()); }); afterEach((done) => { global.IdentityManager.verify().then(() => done()); global.SessionManager.setup().then(() => done()); }); afterAll((done) => { global.IdentityManager.finalize().then(() => done()); global.SessionManager.setup().then(() => done()); }); ```

mui_ume
2019-07-12 08:14
oh I just spot my mistakes, :slightly_smiling_face:

matt.fellows
2019-07-12 08:14
no

matt.fellows
2019-07-12 08:14
ha

matt.fellows
2019-07-12 08:14
:slightly_smiling_face:

matt.fellows
2019-07-12 08:15
aside from the `setup` being in the wrong place, the other issue is that you have two promises that call the same `done()`

matt.fellows
2019-07-12 08:16
this will potentially lead to issues where one promise finishes earlier than the other and ?cuts off? the other promise from doing it?s job

matt.fellows
2019-07-12 08:16
you need to wait for all promises and _then_ call done

matt.fellows
2019-07-12 08:17
``` beforeAll((done) => { Promise.all([ global.IdentityManager.setup(), global.SessionManager.setup() ]) .then(done) }); ```

matt.fellows
2019-07-12 08:17
something like that would be better, because if one of the promises fail you?ll get the error.

mui_ume
2019-07-12 08:31
I got this error ```App/Screens/Login/__pact-tests__/IdentifyManager.login.test.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 22 | afterAll((done) => { 23 | Promise.all([ > 24 | global.IdentityManager.finalize(), | ^ 25 | global.SessionManager.finalize(), 26 | global.ConversationManager.finalize(), 27 | ]) ```

mui_ume
2019-07-12 08:46
```W, [2019-07-12T16:45:15.388695 #29299] WARN -- : Could not load existing consumer contract from /Users/tohlaymui/Desktop/tl_stella-client_app/pacts/ui_client-identity_manager.json due to 757: unexpected token at 'null'. Creating a new file. I, [2019-07-12T16:45:15.389986 #29299] INFO -- : Verifying - interactions matched E, [2019-07-12T16:45:15.390018 #29299] ERROR -- : 757: unexpected token at 'null' (JSON::ParserError) /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.69.0/lib/vendor/ruby/2.2.0/gems/json-2.2.0/lib/json/common.rb:156:in `parse' /Users/tohlaymui/Desktop/tl_stella-client_app/node_modules/@pact-foundation/pact-node/standalone/darwin-1.69.0/lib/vendor/ruby/2.2.0/gems/json-2.2.0/lib/json/common.rb:156:in `parse' ```

mui_ume
2019-07-12 08:48
do I need to have different pacts folder for each consumer-provider ?

mui_ume
2019-07-12 08:52
I set up my pactSetup.js: ```// ./pact/setup.js // To configure the Pact mock provider const path = require('path'); const { Pact } = require('@pact-foundation/pact'); global.portIM = 8080; global.portSM = 8082; global.portCM = 8083; global.hostIM = '127.0.0.1'; global.hostSM = '127.0.0.2'; global.hostCM = '127.0.0.3'; global.IdentityManager = new Pact({ cors: true, port: global.portIM, log: path.resolve(process.cwd(), 'logs', 'pact-IM.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts/IM'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Identity Manager', host: global.hostIM, }); global.SessionManager = new Pact({ cors: true, port: global.portSM, log: path.resolve(process.cwd(), 'logs', 'pact-SM.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts/SM'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Session Manager', host: global.hostSM, }); global.ConversationManager = new Pact({ cors: true, port: global.portCM, log: path.resolve(process.cwd(), 'logs', 'pact-CM.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts/CM'), spec: 2, pactfileWriteMode: 'update', consumer: 'UI Client', provider: 'Conversation Manager', host: global.hostCM, }); ```

mui_ume
2019-07-12 08:52
when I run my pact test, I got this error ```[2019-07-12T08:49:50.295Z] INFO: pact-node@8.6.2/29634 on LayMui.local: Created './standalone/darwin-1.69.0/bin/pact-mock-service service --consumer 'UI Client' --cors 'true' --pact_dir '/Users/tohlaymui/Desktop/tl_stella-client_app/pacts/IM' --host '127.0.0.1' --log '/Users/tohlaymui/Desktop/tl_stella-client_app/logs/pact-IM.log' --pact-file-write-mode 'update' --port '8080' --provider 'Identity Manager' --pact_specification_version '2'' process with PID: 29640 [2019-07-12T08:49:51.336Z] INFO: pact@8.2.6/29634 on LayMui.local: Setting up Pact with Consumer "UI Client" and Provider "Identity Manager" using mock service on Port: "8080" FAIL App/Utils/Api/__pact-tests__/SessionManager.start.test.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 23 | Promise.all([ 24 | global.IdentityManager.finalize(), > 25 | global.SessionManager.finalize(), | ^ 26 | global.ConversationManager.finalize(), 27 | ]) 28 | .then(done); at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.<anonymous> (pact/pactTestWrapper.js:25:25)```

mui_ume
2019-07-12 08:53
why is this pointing to Setting up Pact with Consumer "UI Client" and Provider "Identity Manager" for the provider ConversationManager?

mui_ume
2019-07-12 09:50
I just realise I need to setup for 1 provider. ignore my questions

dalsidhu99
2019-07-14 17:30
hi all, can anyone tell me what I, D and E standfor in the mock server integration log? im guessing I is 'Interaction' and D is 'Differ', no idea about E

dalsidhu99
2019-07-14 17:31
'Error' ?

dalsidhu99
2019-07-14 19:53
Also, i have an installation of pact -foundation/pact 8.2.6 but Matchers dont appear to exist within the pact.d.ts file within the node modules, I can however see this in the pact-foundation/node 5.2.1 installation

dalsidhu99
2019-07-14 19:53
any reason why we dont see it in the 1st?

matt.fellows
2019-07-14 21:17
Log levels - info, debug, error

matt.fellows
2019-07-14 21:18
Can you please show me what you're doing? The examples in the repo use the matchers from the exported library so they definitely work (typescript included)

dalsidhu99
2019-07-14 21:35
all i want to do is add a 'like' Matcher to my interaction

dalsidhu99
2019-07-14 21:36
i thinki have found the solution, 2 min

dalsidhu99
2019-07-14 21:43
thank you, i was having issues earlier being able to require pact matchers in my file, but i have managed to get it working with my interactions :+1:

dalsidhu99
2019-07-16 10:28
Hi there, are there any reporting tools that work well with pact js?

dalsidhu99
2019-07-16 10:31
it would be nice to get feedback from reports other than looking in the pact broker

tjones
2019-07-16 11:03
What sort of reports are you interested in?

dalsidhu99
2019-07-16 12:49
Hi Tim, im thinking a report along the lines of how many tests have been executed and how many have passed/failed

dalsidhu99
2019-07-16 12:49
so we can alert people as soon as there is a failure

dalsidhu99
2019-07-16 12:50
will be useful to display on our monitors

matt.fellows
2019-07-16 20:43
What unit testing framework are you using?

matt.fellows
2019-07-16 20:44
You can just use the standard unit test output format from them

dalsidhu99
2019-07-17 08:36
jest, ah good point, i will have look a bit more deeply into that, thanks!

matt.fellows
2019-07-17 08:36
:+1:

shalygai.a
2019-07-18 13:12
Hi all :slightly_smiling_face: I have a test, which Consumer - js Provider - .Net I use Regex to test my body body: Pact.Matchers.term({ matcher: "(?:true)", generate: "true" }) when starting the test provider I have failures what could be the problem?

matt.fellows
2019-07-18 13:14
Are you matching a boolean?

matt.fellows
2019-07-18 13:14
or a string?

shalygai.a
2019-07-18 13:42
string

matt.fellows
2019-07-18 14:19
What are the valid values?

matt.fellows
2019-07-18 14:21
In any case, check your regexes against http://Rubular.com. they must be in that format

kevin.monteiro
2019-07-18 22:12
has joined #pact-js

mui_ume
2019-07-22 07:48
Hi, is there any example of pact test code on the provider. my provider is in java but I don't quite understand the junit, I like to take a look at provider in JS to understand the concept thanks

mui_ume
2019-07-22 07:49
in junit, here is the link given https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit but I do not understand the @Before, @State, @TestTarget concept

tjones
2019-07-22 07:50
I would ask in #pact-jvm

mui_ume
2019-07-22 07:55
I am asking but like to check out JS provider to get some idea on concept becos I am not familiar with junit nor spring

matt.fellows
2019-07-22 08:05
What?s wrong with the examples on the Pact JS repository?



antonello
2019-07-22 08:24
Then (if you want to understand conceptually the provider verification side in a language you?re more familiar with, I would refer to the docs here: https://github.com/pact-foundation/pact-js )

mui_ume
2019-07-22 08:27
Thanks, can I understand that this state concept, is let's say I login with a valid userID, it will have a response. the provider will verify that response. then I got another state where I login with an empty userID, it will have a negative response. the provider will verify that negative response (this is another state)?

igordezky
2019-07-22 17:56
has joined #pact-js

mui_ume
2019-07-23 05:16
do I add state in this way or use given?

mui_ume
2019-07-23 05:17
```beforeEach(() => { const interaction = { state: 'Start Chat with valid session', uponReceiving: 'id, clientId, session, agentDialog, tenantId, userId, callback, sessionData, conversationId and startTime', withRequest: { method: 'POST', path: urlpath_startChat, headers: { Accept: '*/*', 'Content-Type': 'application/json', }, body: like(BODY), }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: like(EXPECTED_BODY), },````

matt.fellows
2019-07-23 21:21
That works fine. There are two interfaces - the builder pattern and this object pattern

tjones
2019-07-24 01:27
@mui_ume A style comment - the intent of `uponReceiving` is to describe the request. I usually write something like: ``` state: 'The session is valid', uponReceiving: 'A request to start the chat', ```

matt.fellows
2019-07-24 01:27
thanks Tim, I meant to add that but was on mobile and forgot

matt.fellows
2019-07-24 01:27
(I have on a TODO list to write an article that help people think about how to write and structure their BDD-style Pact tests)

tjones
2019-07-24 01:28
That would be awesome!

getsreerag22
2019-07-26 02:32
has joined #pact-js


uglyog
2019-07-28 07:30
When next I have some free time, I'll see about getting some of the V3 matchers and generators working with that test

matt.fellows
2019-07-28 12:55
Awesome! I'll see if I can look this Wednesday when I'm back up to Sydney. That's probably the earliest, otherwise maybe next week

matt.fellows
2019-07-28 12:55
I'll try and put together a Delta so we know what we're aiming for in terms of migration

elineopsommer
2019-07-29 13:56
has joined #pact-js

elineopsommer
2019-07-29 14:21
Hi, I have a pact test like this: ```describe('getRecoloredImage', () => { const imageId = '1'; const expectedResponseBody = new Blob([''], {type: 'image/jpeg'}); beforeAll(() => { return provider.addInteraction({ state: 'provider gets the recolored image', uponReceiving: 'a request to get the recolored image for the given image id', withRequest: createGetRequestOptions( `/drawings/images/${imageId}/recolored/image` ), willRespondWith: { status: 200, headers: { 'Content-Type': 'image/jpeg' }, body: Matchers.like(expectedResponseBody) } }); }); it('should return the recolored version of a given image according to the given parameters', async(() => { service.getRecoloredImage(imageId, machineQualityId, colorSetId, dimensionsInPx).subscribe((blob) => { expect(blob).toEqual(expectedResponseBody); }); })); });``` But it gives me ``` HttpErrorResponse{headers: HttpHeaders{normalizedNames: Map{}, lazyUpdate: null, lazyInit: () => { ... }}, status: 500, statusText: 'Internal Server Error', url: 'http://localhost:9876/drawings/images/1/recolored/image', ok: false, name: 'HttpErrorResponse', message: 'Http failure response for http://localhost:9876/drawings/images/1/recolored/image: 500 Internal Server Error', error: Blob{}}``` I just want to test that I get a blob back from the server to display in my page. Does anyone has an idea why it fails?

tjones
2019-07-30 04:46
500 internal server error from the mock probably means that the request didn't match what you said it would

tjones
2019-07-30 04:52
have a look in the logs to see what the problem was

matt.fellows
2019-07-30 06:43
What's the blob? I'm assuming binary, and you definitely can't apply a matcher to a binary object

elineopsommer
2019-07-30 06:49
The content does not matter, I just want to test that I get a blob back. also without the Matchers.like, so only expectedResponseBody as body gives the same error

elineopsommer
2019-07-30 06:49
I also get nothing in the pact logs

matt.fellows
2019-07-30 07:19
If you remove the `body` in the response, does it start to pass?

matt.fellows
2019-07-30 07:22
How would/does that blob serialise over the wire?

matt.fellows
2019-07-30 07:22
Also, are you using a node package or is this in a Jasmine/browser-based environment?

elineopsommer
2019-07-30 07:42
if I remove the body, the error keeps the same, I use this in an Angular webapp

elineopsommer
2019-07-30 07:43
I can see that the angular http client parses it to a blob, that?s probably the error, but if it is a blob it should not be a problem imo..

matt.fellows
2019-07-30 07:44
Ok blob aside if you've removed it, the error is somewhere else in your code

matt.fellows
2019-07-30 07:44
What does the create get request options thing do?

matt.fellows
2019-07-30 07:44
My suggestion is to strip back your test to something small and working, and then iterate from there

mui_ume
2019-07-30 13:25
Hi,I got this error Missing requests: POST /api/identity-manager/v2/invitation/check?method=undefined Unexpected requests: POST /api/identity-manager/v2/invitation/check?method=undefined when my urlpath is '/api/identity-manager/v2/invitation/check?method=undefined'

mui_ume
2019-07-30 13:25
is it need some escape character for ? and =

matt.fellows
2019-07-30 21:13
That looks perfectly legal to me (from a Pact/API standpoint), but also looks to be a mistake. The `undefined` means you?re not correctly referencing a variable and is simply being sent as a string

abubics
2019-07-30 23:10
While the `undefined` is concerning, the missing and unexpected URLs look the same, so it might be failing to match on other parameters, such as headers

matt.fellows
2019-07-30 23:13
:point_up: that also

tjones
2019-07-31 03:58
We've got doubled up synk warnings from my account and from @mboudreau. Synk seems useful - I think we should create a pact-foundation synk organisation that all maintainers can access.

tjones
2019-07-31 03:58
Thoughts?

matt.fellows
2019-07-31 04:01
:+1:

matt.fellows
2019-07-31 04:01
Do you have access to do that?

tjones
2019-07-31 04:02
not sure

pkuang
2019-08-05 19:34
has joined #pact-js

christophe.leray
2019-08-07 15:44
has joined #pact-js

mui_ume
2019-08-08 10:04
I get this error ```? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 10 | 11 | afterAll((done) => { > 12 | global.Platform.finalize().then(() => done()); | ^ 13 | }); 14 | ```

mui_ume
2019-08-08 10:04
what is likely the cause?

mui_ume
2019-08-08 11:01
found the cause, it's due the port number 8080 I set, changed to another port solved it

dalsidhu99
2019-08-12 15:51
Hi All, Looking for some advice. We have been developing a new API within our team, and because its still new and early on we dont yet have any consumers using the API. I have however created a POC and now integrated Pact to prove its benefits within our framework for contract testing. No one has used Pact in the company before, so its a learning curve for everyone. It also means as a Provider i have written tests that test against the mock, creates and Publishes a Pact file and then runs the interactions against the endpoint set up within our test envt

dalsidhu99
2019-08-12 15:51
The problem is this is not the e2e lifecycle of the Pact testing, as we have omitted the consumer.

dalsidhu99
2019-08-12 15:52
Is it the case where we might have to setup an endpoint to consume the API just to get an e2e up and running?

dalsidhu99
2019-08-12 15:53
I will be grateful of any thoughts/suggestions :slightly_smiling_face:

dalsidhu99
2019-08-12 15:58
i have seen the notes on this https://github.com/pact-foundation/pact_broker but as mentioned we havent yet any consumers of the api

matt.fellows
2019-08-12 22:30
No, you don?t _need_ to create an consumer just for the tests, but you might _like_ to. Sometimes it?s helpful to build a client as an example that you can share with teams when they want to integrate.

matt.fellows
2019-08-12 22:31
You can and probably should continue to publish / retrieve from a broker, because when clients do come on board they can start publishing and you can start validating as soon as they come on board. There is definitely some value in doing that

paras.vora
2019-08-16 12:17
@uglyog This is with regard to https://github.com/pact-foundation/pact-js/issues/278 According to your last comment ` don't call .getBody() on your request and response bodies` what should I expect in request/response otherwise?

matt.fellows
2019-08-16 12:29
I think he meant: ``` .body(this.getRequestBody().asBody()) ``` should just be ``` .body(this.getResponseBody()) // <-- ```

matt.fellows
2019-08-16 12:29
Hence the arrows he provided. I?m just guessing though

paras.vora
2019-08-16 12:33
@matt.fellows Tried doing it, no luck.

paras.vora
2019-08-16 12:34
Re-iterating, consumer here is the `java code` & provider is a `js code`.

paras.vora
2019-08-16 12:35
The same code works fine when both the consumer & provider are `java`.

paras.vora
2019-08-16 12:35
@matt.fellows Can we please re-open the issue?

matt.fellows
2019-08-17 02:40
@paras.vora happy to re-open if you can prove the issue relates to JS. At the moment, you have a Pact file that _doesn?t have any matchers_ in it. So it?s doing a string equality match. The main issue is that something is not correct with your JVM tests, so they aren?t producing a pact file with matchers in it

matt.fellows
2019-08-17 02:40
Until we fix that, the issue is not with the JS library.

matt.fellows
2019-08-17 02:41
after you tried making the above adjustment, did the generated Pact file start to contain matchers? This will help us further diagnose

matt.fellows
2019-08-17 02:41
I understand it?s frustrating, we want to help

uglyog
2019-08-17 05:07
When you use `.body(this.getRequestBody().asBody())` it converts the builder into a plain object for serialization into the body. You loose all the matchers.

paras.vora
2019-08-18 10:01
@matt.fellows This is the generated pact file. I see the below section in it: ``` "matchingRules": { "body": { "$.header": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.footer": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.body": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.page.format": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.page.height": { "matchers": [ { "match": "type" } ], "combine": "AND" }, "$.page.width": { "matchers": [ { "match": "type" } ], "combine": "AND" } } } ```

matt.fellows
2019-08-18 10:53
Ah! Ok at least we're getting matchers now. So, The JS library doesn't support v3 matchers. Please try using v2 on Pact JVM and generating a new contract, and see if that works

chuck
2019-08-19 01:00
has joined #pact-js

paras.vora
2019-08-19 04:39
@matt.fellows Thanks for the response, below are the too libraries I am using in JVM: ``` testCompile('au.com.dius:pact-jvm-provider-spring_2.12:3.5.14',) { exclude group: "org.codehaus.groovy", module: "groovy-all" } ``` ``` compile("au.com.dius:pact-jvm-consumer-junit_2.12:3.5.14",) { exclude group: "org.codehaus.groovy", module: "groovy-all" } ``` Below is what is used in the JS: ``` "@pact-foundation/pact": "^9.0.1", ```

paras.vora
2019-08-19 04:40
Could you please help with the correct compatible versions?

uglyog
2019-08-19 04:50
@paras.vora in your consumer pact test in Java, you would have created an instance of PactProviderRuleMk2. One of the parameters you can provide to the constructor is PactSpecVersion. Setting it to PactSpecVersion.V2 will make the generated pact file compatible with Pact-JS

paras.vora
2019-08-19 06:21
@matt.fellows / @uglyog thanks for the help, that worked. :+1:

matt.fellows
2019-08-19 06:41
:ok_hand::the_horns:

philusd
2019-08-20 11:48
has joined #pact-js

philusd
2019-08-20 11:49
I have a question or rather something I have found with: YOU54F/jest-pact. You can setup cors with your pactoptions although it is not defined in the type and gives an error, but it works. Is that intended?

yousafn
2019-08-20 14:05
Hey, Wasn?t done by design. The pactOptions jest-pact exposes are ``` export interface PactOptions { provider: string; consumer: string; port?: number; logLevel?: LogLevel; pactfileWriteMode?: PactFileWriteMode; dir?: string; } ``` which is a subset of the pactOptions exposed in pact-js This is why you will probably see a compiler error from TypeScript, but it will be passed through to pact-js and work as intended. Feel free to open a PR against jest-pact to allow the cors options in the pactoptions object https://github.com/YOU54F/jest-pact/blob/f542cfca89e9675dd47bbbc5071ce279a5a0760e/src/index.ts#L4

bernardo.guerreiro
2019-08-20 17:19
Hey guys, I am trying to implement Pact between a consumer and provider that communicate through a WebSocket connection. I have read the examples provided, but still have some questions, and there isn?t a lot of writings on this online (might be something I?ll tackle once I?m done). Maybe these questions come from the fact that they apply more to a messaging queue than my exact case. Questions: - The handler function that is given in the example is the already existing handler logic in your consumer? Or is it a handler function that you write that wraps around some logic on the consumer? - Assuming it?s the existing handler function, does that means it needs to necessarily be doing validation of the incoming message? And that?s the part we care about, and mock everything else, if possible? - Where exactly do you test the consumer?s business logic on top of that message? Is that something you simply don?t care about?

matt.fellows
2019-08-21 09:57
Hello, and no, they?re all good questions!

matt.fellows
2019-08-21 10:05
At the moment (at least) we don?t properly support WebSockets as a first class thing.

matt.fellows
2019-08-21 10:05
we support it like other _message like_ interactions as you?ve noted

matt.fellows
2019-08-21 10:06
the standard pattern here is to abstract your protocol handler (i.e. the thing that can talk websockets) from your code that sends or receives a message

matt.fellows
2019-08-21 10:07
I like the ports and adapters metaphor (Alastair Cockburn) to describe this. See slide 20 of a talk I did recently that might help visualise this for you: https://www.slideshare.net/DiUSComputing/serverless-microservices-test-smarter-not-harder/20?src=clipshare

matt.fellows
2019-08-21 10:15
In that terminology, I?d be creating a ?port? that knows what to do with the message, but doesn?t know about the websockets protocol and a separate ?adapter? that performs the conversion. The adapter doesn?t perform business validation, but obviously will need to do basic protocol validation (is it a valid WS interaction / JSON object etc.) This has multiple benefits, but in our case it makes our code more testable. You might be able to use this ?port? (function) directly as the handlers to the message testing framework, or you may need to create a small adapter for the test framework.

matt.fellows
2019-08-21 10:15
> And that?s the part we care about, and mock everything else, if possible? I?d mock out any external dependencies, yes. But that?s a general Pact guideline

matt.fellows
2019-08-21 10:18
> Where exactly do you test the consumer?s business logic on top of that message? Is that something you simply don?t care about? It depends on how much you want the pact test to cover. I?m assuming you probably have other tests that do all of the key business/functional logic. So really all you want to test here is what is relevant for the _contract_, specific to this collaboration.

matt.fellows
2019-08-21 10:21
Generally, for this sort of thing, is that it will take an input (the message), correctly understand it, and perform some action. That might be to write to a DB or to call out to another thing. I?d mock those other things out, and ensure the key things happened. Because for every functional test you do, you need another Pact test, that is a way to find a smell. You only want one Pact test for each message shape - so if you?re finding yourself with multiple identical messages to test what you?re doing, step back

dglaubman600
2019-08-22 02:26
has joined #pact-js

bernardo.guerreiro
2019-08-22 07:06
Hey Matt. Thank you so much for the quick an detailed response (as usual)! I?ll try and see if this can be applied to our current setup, then. I think I was on the right track already, but it sounds like I will indeed need to create my own adapter for the test.

dglaubman600
2019-08-23 04:55
We use PACT in building our microservice-based app (Vue.js front end hitting Kotlin/JVM services) Was very interested to read: https://blog.pactflow.io/injecting-values-from-provider-states/ Is this feature (generators) supported in current versions of Pact-js and pact-jvm?

uglyog
2019-08-23 04:57
Only in Pact-JVM and in the Rust implementation

matt.fellows
2019-08-23 04:58
The best way for us to know how popular/wanted a feature is for it to appear and be requested on GitHub. So if you'd be so kind as to raise it on GH that would help us prioritise our efforts

bethskurrie
2019-08-23 04:59
We already have many issues requesting v3.

matt.fellows
2019-08-24 03:03
true, albeit not this specific feature (in fact looking through the PactJS issues it?s not there at all. I might raise an Epic to start tracking all of the sub features so we can prioritise and commit against it

joao
2019-08-29 13:35
has joined #pact-js

enrique
2019-08-29 15:17
has joined #pact-js

jing.song
2019-08-29 23:59
has joined #pact-js

robin
2019-09-09 15:05
Hello ! I?ve been working on our test suite for a few weeks and discovered recently Pact and decided to implement it on most of our services. I?ve started by testing our public API which has one provider, our backend. I?ve split the tests among 5 different files, one for each endpoint, and each with their own mock server. The tests are executed sequentially. Following the documentation, I?ve made sure to delete the `pacts` folder before running tests and set the `pactFileWriteMode` to `merge`. However, it appears that only the interactions contained in the last test file are written in the pact file. It seems like it?s overwriting itself. I?ve also seen on the documentation that each mock server should run on its own port however I?m not sure how to do that since I?m testing different endpoints with or without interactions with the same provider (hence, same port). I could change the environment variables after each mock server setup to match the mock server?s port but that seems ugly. Is there something I?m missing here? I?ve also started to think about merging all test files together to have a single provider but that?ll be definitely messy (and I?ve got different versions for each endpoints to test?)

matt.fellows
2019-09-10 02:59
Does the ava example in the pact js repository work for you?

matt.fellows
2019-09-10 02:59
it sounds like there is a setup issue somewhere

matt.fellows
2019-09-10 02:59
> I?ve also seen on the documentation that each mock server should run on its own port Only if they need to run in parallel (because obviously you can?t have conflicting ports). If run serially as you say, it should be fine

matt.fellows
2019-09-10 03:00
Just also make sure that each tests makes the call to `finalize` so that the pact is written

robin
2019-09-10 08:27
Hi Matt, thanks for your answers. I?ve checked all the examples, including the ava example. My setup is very similar to the example with the difference that my tests run sequentially and not parallel

robin
2019-09-10 08:32
Right now I?ve got 6 files, testing 5 endpoints, all following the same logic. ``` describe('endpoint /xyz tests') { before => init server, add any external mocks needed, setup provider describe('testing v... for specific endpoint') { before => add needed interactions Then test endpoints & interactions after => verify interactions } after => finalize }```

robin
2019-09-10 08:34
I?ve also did several checked, removing one test of the sequence or just testing it indvidually. Pacts are written but when running sequentially, they seem to be overwritten

tjones
2019-09-11 05:02
``` before => init server, add any external mocks needed, setup provider ``` Can you share the code that does this, please? Ideally from each test file

tjones
2019-09-11 05:03
Also, which test framework are you using?

robin
2019-09-11 08:06
Hi Tim, I?m using lab from the Hapi js suite. I?ll create a repo to share on github

robin
2019-09-11 08:34
Hey Tim. I?ve created a repo with my tests folder. It contains my entire test setup and some context (package.json, server file, etc.). I cannot add all the context obviously but I hope this helps!


matt.fellows
2019-09-11 13:04
Thanks Robin, this is really great. I'll take a look tomorrow (apologies was running a meetup tonight). I suspect the pact log will be illuminating in further understanding. My suspicion is that write pact might only need to be called once at end end of it all. But I'm looking on a mobile and may have missed something

matt.fellows
2019-09-11 13:05
Beautiful code, btw

robin
2019-09-11 13:12
Thanks Matt and thanks for your help. I?m still testing different options, I?ll keep you posted if I find anything :slightly_smiling_face:

robin
2019-09-11 13:27
I?ve also added the latest pact.log, which is a reflection of the pact json file and only logs the latests interactions

matt.fellows
2019-09-12 00:17
Thanks for that Robin. I?ve just pulled it down now, unfortunately a bunch of dependencies don?t seem to be downloadable and I can?t run it.

matt.fellows
2019-09-12 00:18
e.g. `npm ERR! 404 Not Found: @citizenplane/pygmalion@^1.0.3`

robin
2019-09-12 09:27
Ah, indeed, those are our internal modules

robin
2019-09-12 09:27
let me see what I can do

robin
2019-09-12 09:35
Okay I?ve changed the npm settings from private to public you should be able to pull it. However you won?t be able to run the tests without the codebase and I unfortunately can?t really share that with you

matt.fellows
2019-09-12 09:50
All good. I'll try to reproduce another way

robin
2019-09-12 14:14
Thanks, let me know if I can help

robin
2019-09-13 09:49
Morning everyone. I?m working now on my provider verification tests. Our API has a few models with null or typed field and arrays / object that can be either empty or filled with relational data. I?ve understood looking at the documentation that, for good reason, matchers do not allow these specific use cases and that I should rater use different states to specify my interactions. That?s not a problem and it works quite well. However, when it comes to provider verification, I?m a bit stuck. If I want to make sure that the data saved in the interactions will, in fact, match the data returned by the provider, I have to mock my database queries. If I?m running a seeded database I have no control over the data inside the database as it is randomized and thus I could have failed verification because a field is a string and not null, or an array is not empty, etc. I already mock database queries for my integration tests but I know exactly which query I need to mock and which data needs to be returned. When I?m running all the verifications, That?s a bit more complicated because I have potentially a lot of queries to mock. I also need to know the order if I want to do it right. And if there?s several consumer depending on my consumer, which interaction will get verified first? How do you usually make sure your provider database data will match the interactions saved if there are some optional fields and / or fields that can be either null / typed, etc.?

matt.fellows
2019-09-13 11:15
Morning!

matt.fellows
2019-09-13 11:15
(or in our case, evening!)

matt.fellows
2019-09-13 11:25
So basically, because consumers depend on these states, and provider builds can fail because of them, I usually do the following as the initiative progresses (if doing pure consumer-driven, for obvious reasons you won?t be able to do all of this): ? Advertise specific entities / scenarios that exist in advance for anyone to use (e.g. Users, Orders, whatever - useful for the `200` type scenarios) ? Create and agree on a standard convention for describing the ?states?. There is no one way of doing this, and it?s ideal there are fewer of them for the provider to have to worry about. This can be in a Wiki page, the providers? repository or some place that everyone has shared and immediate access to. I usually implement this via data fixtures and running a real database (e.g. in Docker), so I can control most things like IDs

robin
2019-09-13 12:11
Hum okay so, if I understand correctly: - You?re running a real database with a known set of data that you use during your provider tests - In order to do that, you share some specific entities with corresponding IDs for everyone to use when testing consumers and writing interactions - Which means that the data you?re using when writing your interaction has to match an entity in the database which will also match the state described in the interaction Is that right?

matt.fellows
2019-09-13 12:21
Yep. There are many ways to achieve that - the standard is probably that a consumer drafts a contract, with a state that makes sense for their use case, and before it becomes ?real? (e.g. tagged with ?master? or ?prod?) it might get reviewed and updated based on the provider teams? feedback

matt.fellows
2019-09-13 12:22
@uglyog thoughts / additions? I feel like we could probably publish more about our thinking on this, including how to describe the tests (BDD vs API description vs ..)

robin
2019-09-13 12:37
I see, thanks for the explanation, that?s an interesting process. In our current organization, I feel this is actually a bit overkill. We?re only 5 engineers with 10 - 15 microservices. We?ve only recently started thinking about our whole framework and that?s how I started working with Pact. Ideally I wanted to implement something along the line of: *For the consumer* - All external services are mocked with different state / scenarios to test API responses - Database queries are mocked as well - Internal services are mocked with Pact & interactions are registered using Joi schemas from the consumer to dynamically generate the payload & Joi schemas from the provider to dynamically generate the response (I?ve developed an internal module that generates a random data set based on a joi schema and another module holds all our validation schemas) *For the provider* - Same logic for integration tests - As for the pact verification tests, mocking database queries seem impossible for the reason I?ve written above. Therein lies the rub The reasoning behind this was to avoid hardcoding data inside the tests. I also didn?t want to have to manually type my payloads or update them every time I made a change to the validation schema. However, randomizing payloads means I?ve got to mock my database queries and that wouldn?t work on the provider side

abubics
2019-09-15 23:55
I use the same approach, in principle, but stub out the API way closer to the HTTP layer . . . usually cutting off around the use-case layer. It does mean I have to build fixtures up in every language/platform that needs them, though.

abubics
2019-09-15 23:56
Which potentially could be solved with a library of JSON fixtures, for example . . .

matt.fellows
2019-09-16 00:59
> However, randomizing payloads means I?ve got to mock my database queries and that wouldn?t work on the provider side Yes, the randomness is what will make this problematic. Pact JVM actually provides the facility to inject values through states (https://blog.pactflow.io/injecting-values-from-provider-states/: which would / could help with this) but I?d recommend against this for other reasons.

matt.fellows
2019-09-16 01:00
The main reason is that if you go down the manage your contracts and workflow through the Pact Broker path, you won?t be pre-verified (value changes in a contract that is otherwise structurally equivalent will be seen, at least for now, as a contract change, so you won?t get some of the benefits of the can-i-deploy tool https://docs.pact.io/pact_broker/can_i_deploy)

robin
2019-09-16 13:12
Hum missing pre-verification would indeed be a shame. And I?m not even sure how provider states could work vs a fully randomized interaction. Well, I?ll reevaluate my current setup, either keep with what I have and remove pact for now or change how I generate test data & mock the db and set up pact now. Thanks for your time and answer :slightly_smiling_face:

lauri.vaeaenaenen
2019-09-16 16:09
has joined #pact-js

kiranpatel11
2019-09-16 21:11
has joined #pact-js

matt.fellows
2019-09-16 21:29
You seem to be thinking about it right, so keep going and if you have more questions let us know

matt.fellows
2019-09-16 21:29
Btw, do you use OAS at all?

matt.fellows
2019-09-16 21:33
Also, we may eventually improve the prr verification checks to be content independent

robin
2019-09-17 08:00
No I don?t use OAS, I used to but I migrated to a self-hosted, markdown-based api documentation. It?s purely for documentation purposes though

dianaszaharia
2019-09-19 10:46
has joined #pact-js

lwillmeth
2019-09-19 19:07
has joined #pact-js

lwillmeth
2019-09-19 19:27
Hi @here, I'm new to pact-js and have a general question, let me know if there's a better channel? Should I be making many assertions in my consumer contract tests? I've seen this pattern in most of the pact example projects, but I'm not sure why. I realize setting up the provider mocks and calls are necessary to generate the contract, but AFAIK the real provider responses won't be compared against the consumer assertions. All that matters is if the data in the consumer contract matches the provider's responses, right? I could see comparing the provider mocks against my unit test mocks, but copying my unit test assertions into my contract tests seems like it's just adding maintenance overhead. I'd rather just replace some of my unit test mocks with provider mocks. Any thoughts or comments are welcome.

lwillmeth
2019-09-19 19:36
Maybe I should be adding pact interactions during my unit tests, instead of separating them as so many examples do.

matt.fellows
2019-09-20 02:15
> All that matters is if the data in the consumer contract matches the provider?s responses, right? Yes, or more specifically in most cases, just the shape of the data.

matt.fellows
2019-09-20 02:16
> Should I be making many assertions in my consumer contract tests? I?ve seen this pattern in most of the pact example projects Can you share an example as to what you think is the anti-pattern here? If we have bad examples we ought to fix them



matt.fellows
2019-09-20 02:18
but the short answer is that you want to be testing your collaborator companent, which may involve multiple assertions. If they overlap with unit tests, reduce the overlap to the smallest amount until you still catch any potential integration issue

tjones
2019-09-20 04:49
Are you asking why we need to assert on the response in the test?

tjones
2019-09-20 04:51
Oh, yeah, we have some anti-patterns in the examples

tjones
2019-09-20 04:51
in the jest examples, it says:

tjones
2019-09-20 04:51
``` it("returns a sucessful body", done => { return getMeDogs({ url, port, }) .then(response => { expect(response.headers["content-type"]).toEqual("application/json") expect(response.data).toEqual(EXPECTED_BODY) expect(response.status).toEqual(200) done() }) .then(() => provider.verify()) }) ```

tjones
2019-09-20 04:52
So, pact does the assertion of the response codes / headers etc for you

tjones
2019-09-20 04:52
However, in a clean design you'd expect the response from your API layer to be a domain object, rather than an http response object


tjones
2019-09-20 04:54
``` it('returns the number of times this score has been reached', done => { scoreBoard .reachedScore(12) .then(({ reachedBy, globalHighScore }) => { expect(reachedBy).toEqual(EXPECTED_BODY.timesReached); expect(globalHighScore).toEqual(EXPECTED_BODY.globalHighScore); }) .then(done); }); ```

tjones
2019-09-20 04:55
In javascript, it is often the case that your API layer just returns the body, so yes, your test often looks like:

tjones
2019-09-20 04:56
``` it('returns the body', () => callApi(someConfig).then(data => expect(data).toEqual(EXPECTED_BODY)); ) ```

tjones
2019-09-20 04:57
Pact ensures that the mock provider will return what you asked for (if the request is what you said it would be) Then your unit test needs to assert that your API call returned the domain object that you are expecting

tjones
2019-09-20 04:58
it's an anti-pattern to put the http call, or the http response in the pact test

tjones
2019-09-20 04:58
The best practice is to call the api wrapper (which will do the call)

tjones
2019-09-20 04:58
essentially, you're testing everything that you wouldn't unit test

tjones
2019-09-20 05:00
>Maybe I should be adding pact interactions during my unit tests, instead of separating them as so many examples do. This is more a practical point - pact tests take much longer to run than the rest of your unit tests. If you don't mind longer test runs, you can run pact as part of the rest of your test suite. I have done both, it depends on the project

tjones
2019-09-20 05:04
In english, a single pact test says: ? If I send this request (`withRequest`) ? I'll get this response from the server (`willRespondWith`) ? This happens when I call this function (whatever your function call is, inside a `test` or `it`, or whatever your test framework has - and `provider.verify()` confirms this) ? The calling code returns this object to the caller (this is the assertion)

tjones
2019-09-20 05:04
let me know if the explanation isn't clear

tjones
2019-09-20 05:06
Put simply: > All that matters is if the data in the consumer contract matches the provider's responses, right? No. It also matters that the calling code gets the right object returned. Otherwise an implementation like: ``` const apiCall = (someParams) => { axios.get(/* .... */); return 'something irrelevant'; } ``` might pass the tests.

lwillmeth
2019-09-20 17:12
Thanks for the detailed responses! I'll read up and continue learning from your links. I'm too new to Pact and contract testing to have an informed opinion on anti patterns yet. I see that broker validation may take quite awhile, which is a great argument for separating contract from unit tests. Thanks again for the responses, and your hard work on this project. I'm really looking forward to working with Pact.

tjones
2019-09-24 00:49
On this day one year ago, pact-js had around 6,000 weekly downloads on npm. Today it is 36,000

tjones
2019-09-24 00:50
You're welcome! Please let us know if you have any further questions.

matt.fellows
2019-09-24 01:40
According to our analytics, which I trust more than npm, it?s actually more like 80k

bernardo.guerreiro
2019-09-24 07:09
6 digits incoming !

uglyog
2019-09-25 23:15
@matt.fellows I have some capacity this weekend to work on the V3 beta. You did push up all the changes you did?

matt.fellows
2019-09-25 23:27
shit, no. It?s on the other laptop. Setting reminder in my phone now

angela.gloyna
2019-09-26 06:01
has joined #pact-js

vk.regs
2019-09-26 08:49
has joined #pact-js


bethskurrie
2019-09-28 07:59
FFS

matt.fellows
2019-09-28 11:19
That?s awesome news Ron. I?ll try to take a look tomorrow

catrionamcgarvey
2019-09-29 00:21
has joined #pact-js

reachbharathan
2019-10-03 13:09
has joined #pact-js

vitaliy.grigoruk
2019-10-08 14:56
Hi everybody. We would like to make provider verification job less verbose. Currently, for each request in pact contract (both passed and failed) we get something like this in STDOUT (I guess this is RSpec reporter used in pact-ruby): ``` Given [{"name":"token does not exist","params":{"token":"invalid"}}] invalid response token auth request with POST /v1/auth/token returns a response which has status code 422 has a matching body includes headers "Content-Type" which equals "application/json; charset=utf-8" ``` This is too verbose for my team... Developers complain that they?re lost in this huge output and they want to get an output for failed tests only. Any suggestions where I should look?

tjones
2019-10-08 22:00
I think you're correct about the reporter

tjones
2019-10-08 22:01
pact-js uses https://github.com/pact-foundation/pact-provider-verifier for the verification, which supports either custom formatting or redirecting the output

tjones
2019-10-08 22:04
However, specifying the format isn't exposed in the js wrapper


tjones
2019-10-08 22:05
How are you kicking off the verification?

bethskurrie
2019-10-08 22:08
It'll need to be added to the wrapper then.

tjones
2019-10-08 22:09
Oh hi! I just asked about this in #pact-ruby-standalone - I'm not sure what the option should be set to for this case

bethskurrie
2019-10-08 22:09
I'm not sure if the progress formatter is supported (that's the low noise one) but it easily can be.

tjones
2019-10-08 22:09
``` --format=FORMATTER # RSpec formatter. Defaults to custom Pact formatter. Other options are json and RspecJunitFormatter (which outputs xml). ```

bethskurrie
2019-10-08 22:10
Yeah, looks like the low noise one isn't supported yet. I think it's "progress".

bethskurrie
2019-10-08 22:10
@vitaliy.grigoruk you can run one interaction at a time, btw.

tjones
2019-10-08 22:10
Cool. Want me to open an issue against pact-provider-verifier?

tjones
2019-10-08 22:11
I can make a PR to expose the option in the wrapper

bethskurrie
2019-10-08 22:13
I've just tested it, and you can set --format progress and it will only show failures.

tjones
2019-10-08 22:14
sweet, I'll expose this in pact-node sometime today. Thanks!

bethskurrie
2019-10-08 22:15
np

matt.fellows
2019-10-08 22:17
Which test framework do you use, btw? E.g. Mocha, jest ...

tjones
2019-10-08 22:18
@vitaliy.grigoruk, I created https://github.com/pact-foundation/pact-node/issues/188 to track this

vitaliy.grigoruk
2019-10-09 07:28
we don?t use any frameworks at the moment. We have 1 js file which launches pact-provider-verifier via pact-js and that?s it.

matt.fellows
2019-10-09 07:42
If you were to use one, what would you use? The reason being, I'd like to be able to report each verification as a single item so you can get usual test reporter output instead of a single pass or fail for the whole thing

vitaliy.grigoruk
2019-10-09 07:46
I personally like jest, but we use mocha already in our provider codebase, so I?d love to have mocha

vitaliy.grigoruk
2019-10-09 11:47
could you please explain how I can do this with pact-js / pact-node?

bethskurrie
2019-10-10 20:28
It should be in the output of the failed test. If it's not then I'll raise an issue.

bethskurrie
2019-10-10 20:29
Set the env vars PACT_DESCRIPTION and PACT_PROVIDER_STATE to match the one you want

bethskurrie
2019-10-10 20:29
Though you're running a v3 pact with an array of states, so I'm not sure that the provider state will match.

bethskurrie
2019-10-10 20:30
Try just setting the description

vitaliy.grigoruk
2019-10-11 07:03
didn?t know about this feature. Thank you for sharing! Yes, we use v3 provider states encoded into a string (so it is v2 compatible). I?ll check if I see this in the output, if not - I?ll create a ticket

lwillmeth
2019-10-16 17:04
I see that I can pass the Verifier either filenames via `pactUrls`, or fetch pacts from a broker via `pactBrokerUrl`, but can I pass it JSON instead? I could write the JSON to disk and pass the verifier temporary filenames, but would rather avoid that.

joshwakefield45
2019-10-16 18:13
has joined #pact-js

matt.fellows
2019-10-16 20:34
It doesn't accept inline json at the moment. Can you elaborate why you might need it?

lwillmeth
2019-10-16 20:37
I'd like to use a custom pact broker to get better control over which pacts should be verified. That means I need to either fetch the pacts and write them to disk, or figure out a way to replace the default Verifier request with my own.

lwillmeth
2019-10-16 20:39
The simplest workaround seems to be having the provider fetch and write pacts to disk, then passing the filenames to the Verifier via pactUrls.

matt.fellows
2019-10-17 07:05
Yep, writing to disk is by far the easiest

matt.fellows
2019-10-17 07:05
What's missing in the broker that we should add for your use case?

thakkarjinal29
2019-10-17 11:52
Hello, I am writing consumer tests for our angular application, in which for 1 of the API we send the request body as `multipart/form-data`. The mock service is giving this error `Error ocurred in mock service: NoMethodError - undefined method 'encoding' for #<Hash:0x007f898a108d38>`. I came across a similar issue https://github.com/pact-foundation/pact-support/issues/68 which was I think fixed about a month or more ago. I have the latest `pact-node` and `pact-web` packages which use the standalone version `darwin-1.70.2`. But it does not seem to work for me. Could someone help please.

lwillmeth
2019-10-17 16:24
We have some legacy providers that are not versioned, so I'm tapping into our CI/CD pipeline to archive old contracts when those providers update. (I'm also pushing to add versions, but that's been surprisingly controversial.) I'm storing the contract objects in the same format, and would use the default Verifier request to fetch them, but my broker is implemented in graphql, so it would mean modifying the request. I appreciate all of your work on this project, we're pretty excited to add contract testing via Pact.

thakkarjinal29
2019-10-18 05:48
Hey @bethskurrie @matt.fellows, could you guys take a look please?

bethskurrie
2019-10-18 06:16
@thakkarjinal29 can you see the instructions I gave that user to recreate the issue? Can you please do the same?

bethskurrie
2019-10-18 06:16
Also, check that you're setting your content type and accept headers correctly.

thakkarjinal29
2019-10-18 06:17
Yes, will do it thanks!

travis.anderson
2019-10-18 18:02
has joined #pact-js

stevi.deter
2019-10-21 20:27
has joined #pact-js

travis.anderson
2019-10-21 22:18
Screenshot of a discussion I was having on the pactteshelp channel. I didn't realize there was nobody from Pact on the channel. Can anyone provide some insight on this to help me understand how Provider verification actually works?

matt.fellows
2019-10-21 22:33
Sorry, I didn?t know what the channel was or why it existed. We all tend to hang out in the language specific channels

matt.fellows
2019-10-21 22:34
I?ve answered the first bit

travis.anderson
2019-10-21 22:46
No worries, I have found it. Working on processing all of the answers :slightly_smiling_face:

lwillmeth
2019-10-21 23:16
Is anyone here familiar with Pact's `GraphQLInteraction`? I'm having an issue where my consumer query does not match the expected query, because regex sees unexpected newlines and `__typename`. I'm using the same gql string for both queries, and I tried formatting it on one line, but apparently `apollo-boost` reformats it onto multiple lines.

matt.fellows
2019-10-21 23:17
hmmm

matt.fellows
2019-10-21 23:17
I think there is an open issue at the moment on the repo, maybe double check that you?re not running into that

lwillmeth
2019-10-21 23:17
Here's the diff: ``` Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "body": { - "query": /query\s*QueryContractById\(\s*\$provider:\s*String!\s*\$contractId:\s*ID!\s*\)\s*\{\s*contractById\s*\(\s*provider:\s*\$provider\s*contractId:\s*\$contractId\s*\)\s*\{\s*contractId\s*provider\s*consumer\s*\}\}/ + "query": "query QueryContractById($provider: String!, $contractId: ID!) {\n contractById(provider: $provider, contractId: $contractId) {\n contractId\n provider\n consumer\n __typename\n }\n}\n" } } ```

matt.fellows
2019-10-21 23:18
can you not add `__typename` into the expected query?

lwillmeth
2019-10-21 23:19
I'll do that and try some suggestions from the github issue here: https://github.com/pact-foundation/pact-js/issues/292

matt.fellows
2019-10-21 23:20
thx, let us know how you go

matt.fellows
2019-10-21 23:20
happy to evolve that API as I know it?s not perfect

abubics
2019-10-21 23:27
Whoa, yeah, never heard of that channel :sweat_smile:

lwillmeth
2019-10-22 00:00
It looks like apollo-boost changes the string by adding commas, which don't match the Pact regex. I finessed my `withQuery` string to match what Pact expects and got it working for now, but making commas optional would be better. Thanks for your prompt response earlier, and have a great rest of your day!

lwillmeth
2019-10-22 00:02
The newlines threw me off for a bit because they fail regex testers, but don't seem to fail the actual comparison. So there may be something fishy there.

lwillmeth
2019-10-22 17:00
Setting up some new interactions with Mocha and ApolloGraphQLInteraction. Both interactions pass separately, but when run together the second interaction fails: `No matching interaction found for POST /graphql` The docs say I should call `provider.verify()` after every test, but this seems to cause a problem. Calling it once at the end passes, and seems to exercise all of the interactions, because my responses include data from the mocks. Any thoughts or advice?

matt.fellows
2019-10-22 20:32
Can you share your test, or an outline of it?

lwillmeth
2019-10-22 20:40
Here's an example: https://gist.github.com/lwillmeth/9fb7163fd729cd22e95985bbad79c6df It passes as written, but using provider.verify after each test INSTEAD of once at the end, causes the second test to fail.

lwillmeth
2019-10-22 20:42
My understanding is that calling provider.verify deletes any outstanding interactions, so it's better to add and verify them one at a time?

lwillmeth
2019-10-22 20:43
So the suggested pattern is addInteraction, call API, verify?

matt.fellows
2019-10-22 21:02
The working pattern is how we do the examples in Pact JS repo, did you see something to the contrary?

matt.fellows
2019-10-22 21:03
But yes, you need to verify per test (`it`) block for the reasons you describe

matt.fellows
2019-10-22 21:04
If a test needs two interactions it it, that's totally fine too, as long as your test cases hits both interactions

lwillmeth
2019-10-22 21:11
ah, I found the problem. Because I was running the mocha blocks async, the first verify was running after the second addInteraction had been called. So the first verify was wiping out the second interaction before it was being used. Thanks for the quick response, have a great rest of your day!

matt.fellows
2019-10-22 21:17
ah cool, no worries

matt.fellows
2019-10-22 21:17
:thumbsup:

matt.fellows
2019-10-22 23:28
Thanks Levi. What I would have preferred to do with the library, was convert any gql query to an intermediate AST, and then serialise that to JSON which could be matched by the underlying library. There are barriers to doing that in a cross-language way, so a regex comparison was the simplest/crudest way to achieve it. I?ll think about how the above case could be done. Thanks for your feedback though

yosevuk
2019-10-24 14:16
has joined #pact-js

yosevuk
2019-10-24 14:21
Hello! Can I use the `pactUrls` verification option to list the pact urls from different brokers?

vitaliy.grigoruk
2019-10-24 14:29
why do you have 2 brokers?

yosevuk
2019-10-24 14:35
Well, we are switching to a new one, but it is gradual and there are active contracts on the old one. For example, Providers might have consumers that are using either the old or new broker and want to verify contracts from both. (I think the best answer is to just use one and have teams update, but not always straightforward or timely to coordinate)

yosevuk
2019-10-24 15:34
I think another option is to use two different publish scripts.

matt.fellows
2019-10-24 22:31
I don't think you can

matt.fellows
2019-10-24 22:32
I would just run the verification process twice with the same options, except with different broker URLs provided. It has the same net effect

yosevuk
2019-10-25 20:21
Thanks, that's what I did :smile:

bethskurrie
2019-10-25 22:18
@yosevuk you could, except that the auth credentials can only be specified once.

yosevuk
2019-10-26 00:57
Got it, makes sense Beth!

brandontylerwilliams
2019-10-27 20:34
has joined #pact-js

brandontylerwilliams
2019-10-27 20:34
~

tjones
2019-10-28 05:51
Does anyone @here use pact-node or pact-js on windows, and would be able to help me beta test a change?

tjones
2019-10-28 05:52
I've changed the way that arguments are passed to the binaries, and want to double confirm that it still works on windows before releasing (tests still pass in appveyor, but I'd like to try a real machine too before committing to a release)

yousafn
2019-10-28 14:06
happy to test out the fix @tjones we have quite a few staff at ours trying to use jest-pact on windows with a combination of either WSL, Vagrant or plain windows and coming across issues

srinivasan.anusha
2019-10-28 22:51
has joined #pact-js

archana.rachuri
2019-10-31 02:45
has joined #pact-js

sarajcarbajal
2019-10-31 16:49
has joined #pact-js

james.hattersley-dyke
2019-11-04 10:17
Hi, does anyone know of a way around this error using pact-js & jest. ``` $ cross-env && jest --testRegex "./tests/pact/.*/*(.test.pact.js)" --runInBand --setupFiles ./tests/pact/pactSetup.js --setupTestFrameworkScriptFile=./tests/pact/pactTestWrapper.js [2019-11-04T10:13:02.319Z] INFO: pact-node@10.0.1/581 on ip-10-64-52-241.eu-west-1.compute.internal: Creating Pact Server with options: {"consumer":"fe-fragment-user-insight","cors":false,"dir":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/pacts","host":"127.0.0.1","log":"/home/jenkins/workspace/0-add-pact-tests-to-user-insight/logs/mockserver-integration.log","pactFileWriteMode":"update","port":8080,"provider":"user-insight","spec":2,"ssl":false} [39mFAIL tests/pact/user-insights/mandatory-fields.test.pact.js ? Test suite failed to run TypeError: Cannot read property 'writePact' of undefined 9 | 10 | afterAll(done => { > 11 | return provider.finalize().then(() => done()) | ^ 12 | }) 13 | at Pact.Object.<anonymous>.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.finalize (tests/pact/pactTestWrapper.js:11:19) ``` it's pretty much copying the jest example verbatim in terms of pactSetup.js and pactTestWrapper.js etc etc

james.hattersley-dyke
2019-11-04 10:18
works fine on a Windows machine, for development, fails on CI. Was previously working fine.

james.hattersley-dyke
2019-11-04 10:23
I saw the github issue was closed with the solution to update the timeout, I've tried that and it's not been successful. Any other advice would be greatly received.

matt.fellows
2019-11-04 11:14
hmm that?s a worry. I haven?t had the capacity the last week but Tim has been doing a great job of going through these

matt.fellows
2019-11-04 11:15
Can you check if you can run the underlying mock service directly?

matt.fellows
2019-11-04 11:15
`./node_modules/.bin/pact-mock-service`

matt.fellows
2019-11-04 11:16
`DEBUG` mode doesn?t give you anything more either?

james.hattersley-dyke
2019-11-04 11:18
trying to start the mock server manually yields: ```$ cross-env chmod +x ./debug-pact.sh && ./debug-pact.sh INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] WARN TCPServer Error: Cannot assign requested address - bind(2) for "::1" port 33249 INFO WEBrick::HTTPServer#start: pid=595 port=33249 ```

james.hattersley-dyke
2019-11-04 11:18
just gonna try with debug mode on

matt.fellows
2019-11-04 12:50
Interesting. Looks like IPv6 interface isn't available. I wonder if you're running into that issue (see open issues, we're working thru that now. Seems unlikely tho)

james.hattersley-dyke
2019-11-04 14:24
@mr.matt.r.long closest issue is this one, that i can find https://github.com/pact-foundation/pact-js/issues/383

matt.fellows
2019-11-04 21:57
That's the one

matt.fellows
2019-11-04 22:00
Same symptoms?

james.hattersley-dyke
2019-11-05 09:39
yep

james.hattersley-dyke
2019-11-05 09:39
I'm rolling back to an earlier version that worked on CI to see how I get on.

james.hattersley-dyke
2019-11-05 09:39
same test code etc

james.hattersley-dyke
2019-11-05 09:43
I rolled back to ``` pact@9.1.1 pact-node@9.0.4 ```

james.hattersley-dyke
2019-11-05 09:58
and it worked!

matt.fellows
2019-11-05 10:02
Thanks James. I hope to get to look into this tomorrow, appreciate this feedback

james.hattersley-dyke
2019-11-05 10:10
:+1:

james.hattersley-dyke
2019-11-05 14:44
As an aside, this was the last step into getting a fully fledge pact workflow set up. I've got tagging, webhooks and provider verification builds all set up!

bernardoguerr
2019-11-05 20:21
has joined #pact-js

matt.fellows
2019-11-05 22:04
WOOT!


paras.vora
2019-11-08 07:43
Cant the name of variable `provider` be any other name, say as below: ```global.myprovider = new Pact({ port: global.port, log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "pacts"), spec: 2, pactfileWriteMode: "update", consumer: "MyConsumer", provider: "MyProvider", })```

matt.fellows
2019-11-08 07:45
Yes, why couldn't it?

matt.fellows
2019-11-08 07:45
The variable name has nothing to do with Pact

paras.vora
2019-11-08 07:45
``` Creating Pact Server with options: consumer = ipa-itg, cors = true, dir = /Users/parasvora/workspace/ipa-itg/pacts, host = 0.0.0.0, log = /Users/parasvora/workspace/ipa-itg/logs/mockserver-integration-provider-itg-composition.log, pactFileWriteMode = merge, port = 8092, provider = itg-composition, spec = 2, ssl = false, sslcert = , sslkey = FAIL tests/__contract_tests__/__tests__/pact-provider-itg-composition.tests.js ? Test suite failed to run ReferenceError: provider is not defined 3 | 4 | beforeAll(() => provider.setup()); > 5 | afterAll(() => provider.finalize()); | ^ 6 | afterEach(() => provider.verify()); 7 | at Object.<anonymous> (tests/__contract_tests__/pact-test-wrapper.js:5:10) ```

paras.vora
2019-11-08 07:46
I am getting this error when I am using this: ``` global.provider_itg_composition = new Pact({ port: global.port_provider_itg_composition, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration-provider-itg-composition.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, logLevel: 'INFO', pactfileWriteMode: 'merge', consumer: 'ipa-itg', provider: 'itg-composition', host: '0.0.0.0' }); ```

matt.fellows
2019-11-08 07:46
If you rename the variable in the wrapper you need to rename it in your test also

paras.vora
2019-11-08 07:47
``` const axios = require('axios/index'); const port = global.port_provider_itg_composition; describe('ipa-itg consumer tests', () => { const URL = 'http://127.0.0.1'; describe('Preview PDF section', () => { const ENDPOINT = '/api/v1/invoices/templates/APPDIRECT_DEFAULT_TEMPLATE_EN_US/versions/APPDIRECT_DEFAULT_TEMPLATE_VERSION_EN_US/pdf'; beforeEach(() => { const interaction = { state: 'i need to preview PDF in pdf preview section', uponReceiving: 'a request to preview pdf', withRequest: { method: 'GET', path: ENDPOINT, query: 'dataSource=PLACEHOLDER&clientId=APPDIRECT&scope=PARTNER', headers: { 'Content-Type': 'application/json', 'AD-Tenant': 'APPDIRECT' } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/pdf' } } }; return provider_itg_composition.addInteraction(interaction); }); it('Preview PDF section', done => { axios({ method: 'get', url: `${URL}:${port}${ENDPOINT}?dataSource=PLACEHOLDER&clientId=APPDIRECT&scope=PARTNER`, headers: { 'Content-type': 'application/json', 'AD-Tenant': 'APPDIRECT', Accept: 'application/json' }, data: null }).then(response => { expect(response.headers['content-type']).toEqual('application/pdf'); expect(response.status).toEqual(200); done(); }); }); }); }); ```

paras.vora
2019-11-08 07:48
``` Ran all test suites. console.error node_modules/jest-cli/node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Error: connect ECONNREFUSED 127.0.0.1:8092 at Object.dispatchError (/Users/parasvora/workspace/ipa-itg/node_modules/jest-cli/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:65:19) at EventEmitter.<anonymous> (/Users/parasvora/workspace/ipa-itg/node_modules/jest-cli/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:676:20) at EventEmitter.emit (events.js:214:15) at Request.<anonymous> (/Users/parasvora/workspace/ipa-itg/node_modules/jest-cli/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:412:47) at Request.emit (events.js:209:13) at Request.onRequestError (/Users/parasvora/workspace/ipa-itg/node_modules/request/request.js:877:8) at ClientRequest.emit (events.js:209:13) at Socket.socketErrorListener (_http_client.js:406:9) at Socket.emit (events.js:209:13) at emitErrorNT (internal/streams/destroy.js:91:8) undefined ```

matt.fellows
2019-11-08 07:48
There must be another reference to it somewhere

matt.fellows
2019-11-08 07:48
If you borrow it from the example code I think there is a helper JavaScript file also

paras.vora
2019-11-08 07:48
``` const path = require('path') const Pact = require('@pact-foundation/pact').Pact; global.port_provider_itg = 8091; process.env.API_URL = `http://localhost:${global.port}`; global.provider_itg = new Pact({ port: global.port_provider_itg, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration-provider-itg.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, logLevel: 'INFO', pactfileWriteMode: 'merge', consumer: 'ipa-itg', provider: 'itg', host: '0.0.0.0' }); global.port_provider_itg_composition = 8092; global.provider_itg_composition = new Pact({ port: global.port_provider_itg_composition, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration-provider-itg-composition.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, cors: true, logLevel: 'INFO', pactfileWriteMode: 'merge', consumer: 'ipa-itg', provider: 'itg-composition', host: '0.0.0.0' }); ```

paras.vora
2019-11-08 07:48
My pact setup :point_up_2:

matt.fellows
2019-11-08 07:50
The error you showed is related to the code that is called in the before all and after all blocks. find those

matt.fellows
2019-11-08 07:50
There is still a dangling reference to provider somewhere

paras.vora
2019-11-08 07:50
:thinking_face: let me check

paras.vora
2019-11-08 07:55
@matt.fellows Got it, thanks.

paras.vora
2019-11-08 07:55
` Pact Binary Error: Could not load existing consumer contract from /Users/parasvora/workspace/ipa-itg/pacts/ipa-itg-itg-composition.json due to 757: unexpected token at 'null'. Creating a new file.`

paras.vora
2019-11-08 07:55
any idea on this :point_up_2:

matt.fellows
2019-11-08 08:54
It sounds like the json file is corrupt or invalid?

matt.fellows
2019-11-08 08:54
Was it manually modified?

iammrrhodes
2019-11-08 11:31
has joined #pact-js

iammrrhodes
2019-11-08 19:26
Hey everyone, I'm trying to use that `providerVersionTag` property that was just added and i get this error.. ``` Error reading file from --provider-version-tag No such file or directory @ rb_sysopen - --provider-version-tag /builds/............/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.70.2/lib/vendor/ruby/2.2.0/gems/pact-support-1.11.0/lib/pact/consumer_contract/pact_file.rb:51:in `read' ```

matt.fellows
2019-11-08 22:14
OK I?m on it

matt.fellows
2019-11-08 22:19
looks like that flag isn?t available in the current pact-node

matt.fellows
2019-11-11 00:14
we have a new feature available to Pact JS to remove the pain point of consumers breaking a provider build with new / changed contracts. If you?d like to opt-in to a beta of this, please DM me.

paras.vora
2019-11-11 04:14
No, it wasn't.

matt.fellows
2019-11-11 04:16
Are you able to share that file? Something must be wrong if it can?t be read

matt.fellows
2019-11-11 04:17
OK, googling that error seems that there might be an array matcher with `null` in it


matt.fellows
2019-11-11 04:17
Anything you can share will help



matt.fellows
2019-11-11 09:50
Thanks. Wondering if it?s even an issue? Maybe the file doesn?t exist in the first place so it creates it?

matt.fellows
2019-11-11 09:50
What does the JSON look like before running the tests?

matt.fellows
2019-11-11 09:50
Oh - just double check that you?re not running tests in parallel - that could mean multiple processes writing to the same file at once

kv
2019-11-11 13:48
has joined #pact-js

roman.g.rodriguez
2019-11-12 12:38
has joined #pact-js

roman.g.rodriguez
2019-11-12 12:48
Hello All! I?d like to know what do you think about two approaches about pact files naming. Context: React app + graphql. Some components folders could contain more than one gql query file inside *Approach 1:* To have only one pact test file with the name `test.pact.js`, just one file with all interactions on it *Approach 2:* To have one pact test file per query file following the name of the query it checks wich do you think is better and why? I?d choose the second one because if you need to move the query to another component folder it would be easier by moving files together, but I see some projects using the first one

ncritah
2019-11-19 20:44
has joined #pact-js

ncritah
2019-11-19 20:45
Trying to use pact with Karma and Mocha but without much success. I have updated my karma conf to match the example shown and the rest of my code is as shown below ```*====client.js====* const validate = (host) => { const { url, port } = host; return axios .request({ method: 'GET', baseURL: `${url}:${port}`, url: `/test/111`, headers: { Accept: 'application/json' }, }); }; *====test.js====* describe('Pacting away', () => { let provider; const port = 1331; before(done => { provider = new PactWeb({ consumer: 'KarmaMochaConsumer', provider: 'KarmaMochaProvider', port: port, host: 'http://localhost', }); setTimeout(done, 1000); provider.removeInteractions(); }); after(done => provider.finalize().then(() => done())); describe('', () => { before(done => { provider .addInteraction({ state: 'provider can validate entries', uponReceiving: 'a request to validate 111', withRequest: { method: 'GET', path: '/test/111', headers: { 'Content-Type': 'application/json', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: { message:"Success" }, }, }) .then(() => { done(); }); }); it('should return 200 for 111', done => { validate({url: 'http://localhost', port: port}).then(response => { expect(response.status).to.equal(200); done(); }, done); }); }); });``` When I run the tests, it hangs after this log > `INFO [pact]: Pact Mock Server running on port: 1331` and when I manually try to access the endpoint in my terminal using curl, I get `{"message":"No interaction found for GET /test/111","interaction_diffs":[]}`

ncritah
2019-11-19 20:47
This is a repost of the earlier message I'd posted in general. Didn't realize we needed to post in the language-specific channels :see_no_evil:

sankalan13
2019-11-20 07:06
@ncritah Try removing the host from provider = new PactWeb. Let pact pick up the mock server url on its own.

sankalan13
2019-11-20 07:50
Hey @matt.fellows I am using Pact with Jest and Jasmine. Here is my pact test file: ```const accountService = require('../../repository/services/account-service'); const container = require('../../di'); const Pact = require('@pact-foundation/pact').Pact; const path = require('path'); jest.mock('../../drivers/spanner', () => require('../mocks/spanner.mock')); jest.mock('request'); jest.setTimeout(30000); // global.port = 1234; const provider = new Pact({ consumer: 'UserService', provider: 'AccountService', port: 1234, log: path.resolve(__dirname, '../logs', 'expectation-integration.log'), logLevel: 'TRACE', dir: path.resolve(__dirname, '../pacts'), pactfileWriteMode: "update", // host: '127.0.0.1', spec: 2, }); describe('User Service interaction with Account Service', () => { const ONE_ACCOUNT_BODY = { "userId": "6796fc82-ebac-4afd-8498-a963e7cf8fdf" }; const ONE_ACCOUNT_DETAILS = { "phoneNo": 919455334525, "countryAreaCode": 91 }; let temp = new accountService(container); // let config = container.resolve('config'); beforeAll((done) => { provider.setup().then(function () { console.log('Inside afterall'); done(); }, function (err) { done.fail(err); }); }); afterAll((done) => { provider.finalize() .then(function () { console.log('Inside afterall'); done(); }, function (err) { done.fail(err); }); }); afterEach((done) => { provider.verify().then(done, e => done.fail(e)); console.log('Inside aftereach'); }); describe('GET Interaction for getAccountData', () => { beforeAll((done) => { provider.addInteraction({ state: 'it has one user', uponReceiving: 'a request to retrieve user account data', withRequest: { method: 'GET', path: '/v1.0.0/getAccountInfo', headers: { 'Content-Type': 'application/json', 'cache-control': 'no-cache' }, body: ONE_ACCOUNT_BODY }, willRespondWith: { status: 200, body: ONE_ACCOUNT_DETAILS } }).then(() => { console.log('Inside 1 then'); done(); }, (err) => { console.log('Inside 1 error'); done.fail(err); }); }); it('should return a successful body.', () => { temp.getAccountData('6796fc82-ebac-4afd-8498-a963e7cf8fdf').then((response) => { expect(response.headers["content-type"]).toEqual("application/json"); expect(response.status).toEqual(200); expect(response.data).toEqual(ONE_ACCOUNT_BODY); }); }); }); });``` This is the function I am testing: ```getAccountData(userId) { return new Promise((resolve, reject) => { if (!userId) { return reject(`Invalid param ${userId}`); } const options = { url: `${this.config.services["xxxxxxxx"]}/v1.0.0/getAccountInfo`, method: 'GET', json: { userId: userId } }; console.log(options); request(options, (err, resp, body) => { if (err) { return reject(err); } if (resp.statusCode !== 200) { return reject({ code: resp.statusCode, msg: body }); } console.log(body); return resolve(body); }); }); }``` and here is my config services:

sankalan13
2019-11-20 07:50
```{ "services": { "bharat11-gaming-service": "http://localhost:3002/gaming-service", "bharat11-account-service": "http://localhost:3000/account-service", "bharat11-payment-service": "http://localhost:3003/payment-service" }, "db": { "instance": "bharat11-staging", "database": "bharat11-staging" }, "projectId": "bharat11-staging", "retailer": { "type": "retail" } }``` I am getting the following error: ``` FAIL test/services/account.service.test.js ? Console console.log test/services/account.service.test.js:41 Inside afterall console.log test/services/account.service.test.js:83 Inside 1 then console.log repository/services/account-service.js:73 { url: 'http://localhost:3000/account-service/v1.0.0/getAccountInfo', method: 'GET', json: { userId: '6796fc82-ebac-4afd-8498-a963e7cf8fdf' } } console.log test/services/account.service.test.js:60 Inside aftereach console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /v1.0.0/getAccountInfo See /Users/SankalanParajuli/repos/bharat11-user-service/test/logs/expectation-integration.log for details. console.log test/services/account.service.test.js:51 Inside afterall ? User Service interaction with Account Service ? GET Interaction for getAccountData ? should return a successful body. connect ECONNREFUSED 127.0.0.1:3000``` You can see in the console that the url reaching account service is the url defined in my config services. I am changing that url to where my pact mock server is running and still I am getting the same error that says missing requests. I am stuck in this from two days. Please help!

sankalan13
2019-11-20 07:53
If I use jest.mock('requests'), the connection refused error goes away. But I still can't get my getAccountData function to hit the pact mock server. I had done the same implementation using Karma and there I had used proxies to define where my URLs should be pointing. Can't find anything similar in jest.

sankalan13
2019-11-20 08:25
Is there a way I can map proxies in requests which I am mocking?

ncritah
2019-11-20 08:39
Still facing the same problem. I don't know whether I'm handling the promises wrong some how

bethskurrie
2019-11-20 09:25
@sankalan13 you'll get better help if you turn this into an executable example in a gut repository to share.

bethskurrie
2019-11-20 09:25
Pasting big slabs of code doesn't make it very easy for people to help you.

matt.fellows
2019-11-20 09:27
For starters, the pact mock sever is running on port 1234 but your test seems to hit port 3000.

sankalan13
2019-11-20 09:28
Yeah I changed it to hit 1234 in my config but getting the same error

sankalan13
2019-11-20 09:28
@bethskurrie thank you, I understand. I will push this to a git repository and share the link.

sankalan13
2019-11-20 09:28
Sorry for spamming the channel guys

sankalan13
2019-11-20 09:30
@matt.fellows is there a way I can proxy my requests like how we can do it in karma-pact using jest. I am mocking the request package but it still does not hit my mock server

matt.fellows
2019-11-20 11:42
I think for the `host` property simply `localhost` should suffice (the protocol isn?t needed). There are also a few minor JS things you could tidy up (e.g. remove the use of `done` in favour of returning Promises, and inlining certain things). This would simplify your test code

matt.fellows
2019-11-20 11:46
I?m not sure what you?re asking sorry, it sounds very much specific to your application

matt.fellows
2019-11-20 11:47
if you mock the requests library, that would make sense why the connection refused goes away - I?m assuming that would prevent it from making an HTTP call in the first place

matt.fellows
2019-11-20 11:47
It seems like something in your test setup is not rewiring your config to `http://ocalhost:1234`

ncritah
2019-11-20 20:50
Finally got it work :slightly_smiling_face:

ncritah
2019-11-20 20:53
Hi, So I am new to pact so pardon my kinda amateur questions. Just seen here that I can add multiple interactions to a provider here. > https://github.com/pact-foundation/pact-js. How do I do that? Do I have to do `provider.addInteraction` for each?

matt.fellows
2019-11-20 21:08
Do you need multiple interactions for a given test case (e.g. a scenario), or multiple interactions generally speaking? In both cases you need to call that method, and then you call the `verify` method after each test case to ensure your code did indeed make the call to the mock provider

matt.fellows
2019-11-20 21:09
What did it in the end?

ncritah
2019-11-20 21:31
multiple interactions when a particular endpoint is accessed with a certain id eg a 200 status for valid values, 404 for unknown ones etc

ncritah
2019-11-20 21:32
And from the documentation, the addInteraction is done in a the before method for the describe and I dont want to have each of these cases in its own describe block

matt.fellows
2019-11-20 21:43
They don't need to be in their own describe block. You can organise them however you want, so long as you call `verify` after your scenario runs.

matt.fellows
2019-11-20 21:44
As a general rule, each `it` block should be for a single scenario e.g. GET /product/:id You can do the `addInteraction` call in the same block if it makes sense and is cleaner, and then call `verify` after that

ncritah
2019-11-20 21:53
Looks much cleaner in the it block. Thanks for your help

matt.fellows
2019-11-20 21:55
With async/await I think there's a case for putting it all in the it block

ncritah
2019-11-20 22:19
yes, thats exactly what I have done. Works like a charm :slightly_smiling_face:

sankalan13
2019-11-21 05:55
I figured it out. I was mocking npm requests package using jest and Pact was mocking it too using the mock server so the jest mock was being called in place of the pact mock.

sankalan13
2019-11-21 07:12
Hi guys Does the npm @pact-foundation/pact have pact-node also in it now? Or do I have to independently install @pact-foundation/pact-node? Asking for using the publishPact functionality.

matt.fellows
2019-11-21 07:13
Yes

matt.fellows
2019-11-21 07:13
It should be there

matt.fellows
2019-11-21 07:13
It's an explicit dependency

sankalan13
2019-11-21 07:14
Thanks Matt!

matt.fellows
2019-11-21 07:15
:+1:

sankalan13
2019-11-21 10:49
I haven't been able to make it work with async await, is there a sample code anywhere with async await implementation?

matt.fellows
2019-11-21 11:09
There's nothing pact specific with async/await. Just replace any use of a promise with the new way instead

ncritah
2019-11-25 13:57
It was timing out. Needed to add the mocha property to my pact.json. Also took into consideration the tips you shared earlier. I will repost a working version here soon.

ncritah
2019-11-25 13:58
Used it for a client's project and haven't had a time to rewrite it to a working example


akiro
2019-11-25 14:49
has joined #pact-js

ambergkim
2019-11-26 05:27
has joined #pact-js

ncritah
2019-11-26 08:30
Hey, Just curious, is there any way to use pact with ES6 modules without using babel?

me1352
2019-11-26 13:02
has joined #pact-js

ben.quinteros
2019-11-26 22:37
has joined #pact-js

matt.fellows
2019-11-26 23:18
I think the question is really ?can I use ES6 modules without using babel?

matt.fellows
2019-11-26 23:22
Using Pact doesn?t require Babel or any transpiler, but if you want to use modern ES6 syntax you?re going to need something like that

matt.fellows
2019-11-26 23:25
There is experimental support in node v12, though, if that?s all you need

me1352
2019-11-27 07:36
I am working on the same issue: trying to use PactWeb without Babel in an ES6 only project. The setup is using Karma and at the moment it seems like PactWeb is not declared as a `module` and is not compatible with ES6 modules. At least this is how far I got. I am using `node v12.13.1` and `pact-web v8.2.6`.

matt.fellows
2019-11-27 09:56
I see what you mean. Can you please raise an issue and we can ensure the module package flag is added (and anything else it needs)?

me1352
2019-11-27 11:06
Sure Matt, thanks for your reply :slightly_smiling_face:

matt.fellows
2019-11-27 11:14
:+1:

paul.simms
2019-12-04 16:12
has joined #pact-js

matt.fellows
2019-12-09 01:27
@sankalan13 :point_up: want to take a look?

gordo
2019-12-09 22:27
has joined #pact-js

theriaultnicolas
2019-12-12 03:26
has joined #pact-js



mmonson
2019-12-18 23:18
Does pact-js have support for react hooks? Has anyone created a contract with react hooks?

matt.fellows
2019-12-18 23:19
I think if hooks are involved you?re probably doing something wrong. What?s the use case?

bethskurrie
2019-12-18 23:19
You took the words out of my mouth Matt!

matt.fellows
2019-12-18 23:19
_we?ve been working together for too long_

bethskurrie
2019-12-18 23:20
It's time we automated our responses :stuck_out_tongue:

bethskurrie
2019-12-18 23:20
Sorry Mark!

mmonson
2019-12-18 23:21
we have an axios call that's embedded in the useEffect of a react hook.

abubics
2019-12-18 23:26
My usual pattern (and recommendation) is to centralise calls like that into an API client :slightly_smiling_face: helpful for separation of concerns, and testability :ok_hand:

matt.fellows
2019-12-18 23:27
:point_up:

matt.fellows
2019-12-18 23:27
do this


matt.fellows
2019-12-18 23:27
or something like it. At least, refactor so that you can?t test things independently

zoeabryant
2019-12-19 10:47
has joined #pact-js

zoeabryant
2019-12-19 10:49
I'm having a problem where pact is not sending the body for a POST query when verifying the provider. The body is described in the pact contract, so I'm not sure what's going on

zoeabryant
2019-12-19 10:49
does anyone have a working graphql (as a provider) example I can look at? or tips for debugging?

matt.fellows
2019-12-19 11:36
Can you share the contract / test with us?

zoeabryant
2019-12-19 11:41
@matt.fellows shared contract ^

zoeabryant
2019-12-19 11:45
after some digging, I think my provider has been suppressing error messages :woman-facepalming: Hopefully that's what's causing the problem instead!

zoeabryant
2019-12-19 11:57
that's definitely it. Thanks anyway @matt.fellows!

matt.fellows
2019-12-19 12:40
haha :ok_hand:

matt.fellows
2019-12-19 12:40
no problems

mui_ume
2019-12-20 01:22
I?m looking for the implementation of provider pact test Is this the example that I should be looking at ? https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/provider.spec.js

mui_ume
2019-12-20 02:31
Can I have a simple example on how to setup the pact provider ? I am confused with the example given

mui_ume
2019-12-20 02:41
This is my publisher.js let publisher = require("@pact-foundation/pact-node") let path = require("path") let opts = { providerBaseUrl: "http://localhost:8082", pactFilesOrDirs: [path.resolve(process.cwd(), "pacts")], pactBroker: "https://test.pact.dius.com.au/", pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, consumerVersion: "2.0.0", } publisher.publishPacts(opts)

mui_ume
2019-12-20 02:41
Can someone explain this line providerBaseUrl: "http://localhost:8082",???

mui_ume
2019-12-20 02:43
Can give a clear explanation of the example for the pact consumer and provider Becos I still have to figure out from the example. How can I setup the pact provider?

matt.fellows
2019-12-20 03:05
The publisher?s job is to simply push a pact file from a local file system to a broker

matt.fellows
2019-12-20 03:05
The `providerBaseUrl` is not a valid property for this command

matt.fellows
2019-12-20 03:06
Can you explain what?s confusing about it? I?m afraid if I give another example it will be equally confusing

mui_ume
2019-12-20 03:09
Yes An explanation will be useful

mui_ume
2019-12-20 03:10
Do you have a provider for the jest example ? This example seem to be for consumer side only ?

mui_ume
2019-12-20 03:13
It didn?t work for me I put this lines in my package.json It works "scripts": {   "test:pact": "jest cross-env CI=true __tests__/ --runInBand --setupFiles ./pact/pactSetup.js --setupFilesAfterEnv ./pact/pactTestWrapper.js --testMatch \"**/*.test.pact.js\"",   "publish:pact": "pact-broker publish ./pacts -a 2.0.0 --broker-token ?xxxxxxxx? -b https://test.pact.dius.com.au/",   "verify:pact": "node ./verifyPacts.js"  },

mui_ume
2019-12-20 03:13
But the provider is still not working

mui_ume
2019-12-20 03:14
My verifyPacts.js - let pact = require("@pact-foundation/pact-node") let path = require("path") let opts = {   provider: 'converse provider',   providerBaseUrl: 'http://localhost:8082',   providerStatesUrl: 'http://localhost:8082/states',   providerStatesSetupUrl: 'http://localhost:8082/setup',   pactBroker: "https://test.pact.dius.com.au/",   pactBrokerUrl: 'https://test.pact.dius.com.au/',   pactBrokerUsername: process.env.PACT_USERNAME,   pactBrokerPassword: process.env.PACT_PASSWORD,   publishVerificationResult: true,   providerVersion: '1.1.0'  } pact.verifyPacts(opts).then(() => {   console.log('success')   process.exit(0)  }).catch((error) => {   console.log('failed', error)   process.exit(1)  })

mui_ume
2019-12-20 03:15
The things is I don?t understand those providerBaseUrL What exactly are they for ?

mui_ume
2019-12-20 03:15
The pact broker is at https://test.pact.dius.com.au/ So why still need to specify the ProviderBaseURL ?

mui_ume
2019-12-20 03:16
Is it to mock the consumer ?

bethskurrie
2019-12-20 03:16
That's for verification.

bethskurrie
2019-12-20 03:17
It needs to know where to get the pacts from (the Pact Broker), and where to replay the requests against (the real provider).

mui_ume
2019-12-20 03:19
I see thanks for the clear explanation

mui_ume
2019-12-20 03:21
When I run node ./publisher.js

mui_ume
2019-12-20 03:22
I got Could not publish pact: Failed to publish converse consumer/converse provider pact due to error: PactBroker::Client::Error - Authentication failed One or more pacts failed to be published

bethskurrie
2019-12-20 03:23
Can you think of some ways to debug this?

bethskurrie
2019-12-20 03:23
How can you test that the credentials you have a right using something other than the code?

mui_ume
2019-12-20 03:36
I run this command "publish:pactBroker": "pact-broker publish ./pacts -a 2.0.0 --broker-token 'xxxx' -b https://test.pact.dius.com.au/

mui_ume
2019-12-20 03:36
It works for me

mui_ume
2019-12-20 03:37
But using the publisher.js It has Authentication failed error

mui_ume
2019-12-20 03:37
Anyway I want to verify the pact How can I do it ?

mui_ume
2019-12-20 03:57
I tried running from this example https://github.com/pact-foundation/pact-js/tree/master/examples/jest I too get pactbroker::Client::error - authentication failed

mui_ume
2019-12-20 06:11
Hi Matt This providerBaseUrl is seen in the pact-js/examples/jest/publish.js

mui_ume
2019-12-20 06:26
Can someone point me to how I can setup n config the provider to verify the pact file from the pact broker ? Thanks

mui_ume
2019-12-20 07:15
My verifyPacts.js let pact = require("@pact-foundation/pact-node") let path = require("path") let opts = { provider: 'converse provider', providerBaseUrl: 'http://localhost:8082', providerStatesUrl: 'http://localhost:8082/states', providerStatesSetupUrl: 'http://localhost:8082/setup', pactBrokerUrl: 'https://test.pact.dius.com.au/', pactBrokerUsername: process.env.PACT_USERNAME, pactBrokerPassword: process.env.PACT_PASSWORD, pactBrokerToken: process.env.PACT_TOKEN, publishVerificationResult: true, providerVersion: '1.0.0' } pact.verifyPacts(opts).then(() => { console.log('success') process.exit(0) }).catch((error) => { console.log('failed', error) process.exit(1) })

mui_ume
2019-12-20 07:15
When I run it with Node ./verifyPact.js I get this error 2019-12-20T07:02:22.232Z] WARN: pact-node@10.2.4/11352 on Lays-MacBook-Pro.local: Pact exited with code 1. failed Error: /Users/laymui/Desktop/converse-api/node_modules/@pact-foundation/pact-node/standalone/darwin-1.73.0/lib/ruby/lib/ruby/2.2.0/uri/generic.rb:400:in `check_user': bad component(expected userinfo component or user component): (URI::InvalidComponentError) from /Users/laymui/Desktop/converse-api/node_modules/@pact-foundation/pact-node/standalone/darwin-1.73.0/lib/ruby/lib/ruby/2.2.0/uri/generic.rb:377:in `check_userinfo'

mui_ume
2019-12-20 07:16
Could appreciate if anyone can give me some pointer As I?m really stuck and my colleague is waiting for me to setup this framework to test the api endpoint ?

bethskurrie
2019-12-20 10:26
So, for the test account, there is no broker token.

bethskurrie
2019-12-20 10:27
The credentials are username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1

bethskurrie
2019-12-20 10:27
Why are you using the test one and not your own one?

mui_ume
2019-12-20 10:29
Matt has replied me not to use the email extension for the username This is the one that cause the error earlier

mui_ume
2019-12-20 10:31
So my username is LayMui.toh Not This is the one that cause the error I won?t know this in the error throw out Can you add this in the doc for the benefit of future new user ?

bethskurrie
2019-12-20 10:46
Your email is only used for logging in to the UI.

bethskurrie
2019-12-20 10:47
That can't be your username for the API, because there are no usernames for the API for the broker you just signed up for.

bethskurrie
2019-12-20 10:48
That only has a token.

bethskurrie
2019-12-20 10:51
You can sign in to the UI for http://taiger.pact.dius.com.au using the username and password that were sent to you in the email when you signed up. You can authenticate to the API for http://taiger.pact.dius.com.au using the token that you will find in the settings page of your broker. You can authenticate to both the UI and API of http://test.pact.dius.com.au using the basic auth credentials that I posted above.

bethskurrie
2019-12-20 10:52
I do not know what the username LayMui.Toh could be used for.

bethskurrie
2019-12-20 10:53
There is no account with that username.

mui_ume
2019-12-20 10:54
Thanks my issue is resolved by removing the @taiger.com From the username

bethskurrie
2019-12-20 11:02
It's not throwing an error any more, but that's not a valid username.

bethskurrie
2019-12-20 11:02
It's just not raising an error because there's no @ symbol in it when it tries to create the URL with a username/password. That's what was causing the problem. You could put "abc" in there and it would do the same thing as the username you're using.

bethskurrie
2019-12-20 11:03
BTW, you don't need a username/password AND token.

bethskurrie
2019-12-20 11:03
You only ever need one or the other.

mui_ume
2019-12-20 12:19
Got it thanks Beth

mui_ume
2019-12-20 13:14
If my api is Put with a parameter Example : /api/external/bots/{bot-id} How should I specify in the path in the following code snippet? beforeEach(() => { const interaction = { state: 'Update bot', uponReceiving: 'id and BotName', withRequest: { method: 'PUT', path: urlpath, <??-

mui_ume
2019-12-21 02:22
I try the following using query - uponReceiving: 'botName and id detail', withRequest: { method: 'GET', path: urlpath, query: "bot_id=12334444" , headers: { Accept: '*/*', 'Content-Type': 'application/json',

mui_ume
2019-12-21 02:23
It didn?t work I get the error saying Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Incorrect requests: GET /api/external/bots (request query did not match) See /Users/laymui/Desktop/iconverse-api-pact-js/logs/pact.log for details.

mui_ume
2019-12-21 02:28
I have to use regular expression in the path url: urlpath + '/bot-id=/\w+/',


mui_ume
2019-12-21 02:30
Following the example given It didn?t work for me Or did I miss anything here ?

taisedias
2019-12-22 21:52
has joined #pact-js

mui_ume
2019-12-23 06:39
My publish.js file contains the token only But I still can?t publish to the pact broker

matt.fellows
2019-12-23 22:04
No I don?t have a jest provider I don?t think

matt.fellows
2019-12-23 22:05
It?s a lot of work maintaining examples for every framework, so we just accept donations from the community

matt.fellows
2019-12-23 22:05
It shouldn?t matter what framework you use, as Pact doesn?t have any framework specific things in it

bethskurrie
2019-12-24 19:33
Make sure you're using the latest version of pact-js as token support has only been added recently.

agarwalatrisha1212
2019-12-26 22:53
has joined #pact-js

mui_ume
2019-12-28 08:52
Hi, I like to check this providerBaseUrl: "http://localhost:8080", at https://github.com/pact-foundation/pact-js/blob/master/examples/jest/publish.js is referring to the port that the provider is running on? while the global.port = 8991 at https://github.com/pact-foundation/pact-js/blob/master/examples/jest/pactSetup.js is referring the mock provider service?

mui_ume
2019-12-28 08:53
I like to clarify the above as I was trying to setup the provider in the same project folder as the consumer, making it as end to end and I got some error when I run the provider to verify.

mui_ume
2019-12-28 09:02
Looking at this https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/providerService.js, server.listen(8081, () => { console.log("Animal Profile Service listening on http://localhost:8081") }),

mui_ume
2019-12-28 09:03
what is this server running at port 8081? is it the actual provider? or the mocking the consumer service?


mui_ume
2019-12-28 09:08
server.listen(8080, () => { console.log("Animal Matching Service listening on http://localhots:8080") })

mui_ume
2019-12-28 09:08
what is this server running at 8080? is it the mock provider?

mui_ume
2019-12-28 09:12
in my consumer pact test:

matt.fellows
2019-12-28 10:14
The provider base URL needs to point at your actual running provider

matt.fellows
2019-12-28 10:15
The examples you pointed out above are express JS servers. They are real servers, not the Pact mock provider

matt.fellows
2019-12-28 10:16
(this is all assuming you're doing provider side testing here)

matt.fellows
2019-12-28 10:16
No, it's a real provider

matt.fellows
2019-12-28 10:16
It's the real provider

mui_ume
2019-12-28 10:17
Okay thanks I got it

matt.fellows
2019-12-28 10:17
:+1:

mui_ume
2019-12-28 10:17
Yes I?m working on provider side now

mui_ume
2019-12-28 10:18
I like to understand what is this /setup ?

mui_ume
2019-12-28 10:18
And why do we need that ?

mui_ume
2019-12-28 10:19
Also What should I do with the state ? For my authentication api request I don?t have any database or repository like in the e2e example How should I handle that ? Is it to do assertion check on the response ?

matt.fellows
2019-12-28 10:28
Setup is an old (deprecated) way for setting up provider states. You now use the provider states property

matt.fellows
2019-12-28 10:28
There's a whole article on this in the docs.

mui_ume
2019-12-28 10:47
Oh ok will check out thanks

mui_ume
2019-12-28 22:42
When I put 2 diff states in my consumer test I got Pact verification failed - expected interactions did not match actual. I was just looking at this jest example https://github.com/pact-foundation/pact-js/blob/master/examples/jest/__tests__/index.spec.js If I could modify the example, my format will be something similar like this

mui_ume
2019-12-28 22:46
```describe("works", () => { describe("state 1", () => { beforeEach(() => { const interaction = { state: "i have a list of projects", uponReceiving: "a request for projects", withRequest: { method: "GET", path: "/dogs", headers: { Accept: "application/json", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json", }, body: EXPECTED_BODY, }, } return provider.addInteraction(interaction) }) // add expectations it("returns a sucessful body", () => { return getMeDogs({ url, port, }) .then(response => { expect(response.headers["content-type"]).toEqual("application/json") expect(response.data).toEqual(EXPECTED_BODY) expect(response.status).toEqual(200) }) .then(() => provider.verify()) }) }) describe("state 2", () => { beforeEach(() => { const interaction = { state: "i have a list of another projects ", uponReceiving: "a request for another projects", withRequest: { method: "GET", path: "/dogs", headers: { Accept: "application/json", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json", }, body: EXPECTED_BODY, }, } return provider.addInteraction(interaction) }) // add expectations it("returns a sucessful body", () => { return getMeDogs({ url, port, }) .then(response => { expect(response.headers["content-type"]).toEqual("application/json") expect(response.data).toEqual(EXPECTED_BODY) expect(response.status).toEqual(200) }) .then(() => provider.verify()) }) }) })``` ``````

mui_ume
2019-12-29 02:40
ignore the above, I got it resolved by putting the afterEach(() => provider.verify()) above and removec the .then(() => provider.verify())


mui_ume
2019-12-29 03:25
But I am still not very clear what should I do ? It mentioned The provider team sets up the relevant provider state by creating one alligator with the name Mary AND one alligator named John. Do I need to Setup a database ? Or Repository to store the expected response Maybe I used my own scenarios Let say I?m doing a authentication api I want to test 2 different state or case - valid credentials and invalid credentials? my payload is clientID, clientSecret Curl command - curl -X POST "https://iconverse-xxx.io/i-admin/api/external/authenticate" -H "accept: */*" -H "Content-Type: application/json" -d "{ \"clientId\": \"user1\", \"clientSecret\": \"password1\"}" In my consumer test I put a state ?authentication with valid client? Another state with Authentication with invalid client So in my provider side What should be the code for the state when authentication with valid client and code for the state with invalid client Becos in my case it?s a post command not a get Do I need to create a repository with user account ? What does pact actually do when running the provider to verify the pact file ? Checking the response based on the state? So how should I describe the state to pact?

franklin.huynh
2019-12-30 00:33
has joined #pact-js

marcelo.emmerich
2020-01-06 20:33
has joined #pact-js

simone.cusimano92
2020-01-15 08:13
has joined #pact-js

davchung5
2020-01-15 22:40
has joined #pact-js

sam774
2020-01-16 14:02
has joined #pact-js

sam774
2020-01-17 10:21
Dumb question, but does pact-js support pactfile spec version 3? I can see that all the docs are using the (default) v2, so naturally our pacts are written that way too. We perform provider verification using pact-jvm (we also have some pact-jvm pacts which are v3). When I set 'spec: 3', the output doesn't look like spec v3 and the provider verification then fails.


matt.fellows
2020-01-17 10:22
the caveat is that it _does_ support messages, which is a v3 feature. But not the matchers

sam774
2020-01-17 10:27
that's fair enough - not a blocker for us being on v2 of the spec :slightly_smiling_face: thanks for the quick reply

matt.fellows
2020-01-17 10:29
Hopefully we?ll be there in the next few months, but v2 gets you pretty far

sam774
2020-01-17 10:29
aye. it was more out of curiosity than an explicit need

josue.guerrero
2020-01-17 14:51
has joined #pact-js

zoeabryant
2020-01-22 11:32
I've run into a weird error setting up a provider side verification: `Error: Cannot find module 'bunyan-prettystream'` my package.json literally has one dependecy: `"@pact-foundation/pact": "^9.6.0"`

matt.fellows
2020-01-22 21:26
Hmm. Is that during install or run?

tjones
2020-01-23 03:58
`bunyan-prettystream` is a dev dependency, when it should be a dependency

tjones
2020-01-23 03:58
I?ll fix this

tjones
2020-01-23 03:59
in the meantime, `npm install bunyan-prettystream` should workaround this issue

tjones
2020-01-23 04:06
Releasing v9.6.1 with corrected dependencies

tjones
2020-01-23 04:06
Thanks for the report!

hidalgofdz
2020-01-27 20:19
has joined #pact-js

sagupta
2020-01-28 10:45
has joined #pact-js

louiseavelar
2020-01-28 18:00
has joined #pact-js

g.j.crossfield
2020-01-28 18:25
has joined #pact-js

jana.pacheco
2020-01-29 12:46
has joined #pact-js

sagupta
2020-02-04 12:23
Hi Team, I am going through the PACT JS workshop , and I have a doubt at Step 2. https://github.com/DiUS/pact-workshop-js-v1/tree/step2 ``` it('can process the JSON payload from the provider', done => { const {fetchProviderData} = require('../consumer') const response = fetchProviderData() expect(response).to.eventually.have.property('count', 1000)``` I think this test will not pass, because fetchProviderData function returns an object which is like {value: ??, date: ??} and this doesnt have any property ?count? and this test checks for the value of count property in the response. Can someone clarify please?

antonello
2020-02-04 12:24
Perhaps I can help. what?s up?

sagupta
2020-02-04 12:30
ok i checked in the github in the file pact-workshop-js-v1/consumer/client.js , ffetchProviderData function returns {count: ??, date: ??} which is indeed TRUE but the example in the Readme file has different object returned so this needs to be corrected for all branches..

shero86
2020-02-07 10:33
has joined #pact-js

sagupta
2020-02-12 14:19
Hello , is there a way to add matching to the request path . I have a request path like this /companies/:companyId/users/:usersId For now , I have setup the interaction with the actual values of the request . However I would like to setup for all requests which can have different companyId and userId

matt.fellows
2020-02-12 19:49
Yes, there are examples in the repo for that I believe. It's the same as any other matcher but only applies on the consumer side

sagupta
2020-02-13 05:55
I have checked the repo and could only find examples for headers, query Params and body but not Path .Can you provide reference ?

matt.fellows
2020-02-15 11:56
Have you tried using the `term` matcher? That should work just fine

matt.fellows
2020-02-15 11:56
I thought there was an example but perhaps there isn?t

parveenbanu
2020-02-17 11:18
has joined #pact-js

parveenbanu
2020-02-17 12:42
Hi

parveenbanu
2020-02-17 12:42
i am new joiner here. currently in API Testing.

parveenbanu
2020-02-17 12:43
my management asked me to start with Contract Testing for API

parveenbanu
2020-02-17 12:43
so i choose PACT for it.

parveenbanu
2020-02-17 12:43
can anyone please help to setup this testing prototype

parveenbanu
2020-02-17 12:44
i have Json messages


matt.fellows
2020-02-17 19:52
And completing the workshop to understand the concepts

dominik
2020-02-19 07:55
has joined #pact-js

robin.vanwijngaarden_
2020-02-19 12:07
has joined #pact-js

mui_ume
2020-02-21 11:37
I have this url path ```const urlpath = '/uaa/oauth/token?grant_type=password&password={password}&username={username}'; how can I pass in the variable username and password ```

paolaagudelo10
2020-02-21 19:00
has joined #pact-js

mui_ume
2020-02-22 05:21
I got Actual interactions do not match expected interactions for mock MockService. Incorrect requests: POST /api/uaa/oauth/token (request query did not match) my curl command look like this: ```curl --location --request POST 'https://xxxx/api/uaa/oauth/token?grant_type=password&username=kcp-admin-taiger&password=pass' \ --header 'X-Active-Organization:1234' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Authorization: Basic abc' \ --data-raw ''```

mui_ume
2020-02-22 05:21
I put the project at https://github.com/LayMui/pact-js to reproduce. thanks

mui_ume
2020-02-22 10:12
ignore, I have resolved it

mui_ume
2020-02-24 01:22
I am trying to look up the matchers API documentation...

mui_ume
2020-02-24 01:22
need to check the difference between matcher.like, eachlike, etc


mui_ume
2020-02-24 04:55
I am trying to add the provider verification state, here is my code snippets: ```describe("Pact Verification", () => { it("validates the expectations of Authentication Service", () => { let opts = { logLevel: "INFO", providerBaseUrl: "http://localhost:8082", provider: "iProvider", providerVersion: "2.0.0", pactBrokerUrl: process.env.PACT_BROKER_URL || "http://localhost:9292", stateHandlers: { "Authenticate with valid access token": () => { }, }``` `

mui_ume
2020-02-24 04:56
right now I need to know how to add the code for the stateHandlers

mui_ume
2020-02-24 04:57
my consumer side test look like this: ```beforeEach(() => { const interaction = { state: 'Authenticate with valid access token', uponReceiving: 'access_token, token_type and refresh_token', withRequest: { method: 'POST', path: urlpath, param: { "grant-type": Matchers.like("password"), "password": Matchers.like("pass"), "username": Matchers.like("admin"), }, headers: { 'Content-Type': 'application/json', 'X-Active-Organization': Matchers.like('123'), 'Authorization': Matchers.like('Basic abc'), }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', 'X-Active-Organization': Matchers.like('123'), 'Authorization': Matchers.like('Basic abc'), }, body: Matchers.like(EXPECTED_BODY) }, }; return provider.addInteraction(interaction); });```

mui_ume
2020-02-24 04:57
it's an authentication login, how should I set the state on the provider side?

mui_ume
2020-02-24 04:57
thanks!

mui_ume
2020-02-24 09:53
I got verifyPacts.js:33 describe("Pact Verification", () => { ^ ReferenceError: describe is not defined

matt.fellows
2020-02-24 10:55
Lay, that indicates you are not running your provider verification within the contexnt of a test framework (such as mocha/Jest/?)

matt.fellows
2020-02-24 10:56
```"grant-type": Matchers.like("password"),``` I don?t think you want a string matcher here, I?m guessing it should be exactly ?password? (or whatever the valid values for grant type are)

sagupta
2020-02-24 12:42
@matt.fellows I am trying this for the matching in the request path . To allow different ids in this path /companies/<companyId>/roles withRequest: { method: ?GET?, path: `/companies/${Pact.term(generate: ?7aeeef69-ca14-5b3c-9022-565ea1b16d60?, matcher: /d{36})}/roles

sagupta
2020-02-24 12:42
doesnt work for me i am getting syntax error in the path property

matt.fellows
2020-02-24 12:47
The value of `path` should be a matcher, you can?t embed a matcher in the string value

matt.fellows
2020-02-24 12:47
`path: Pact.term(?)`

paolaagudelo10
2020-02-24 13:12
hi, i am getting warning messages after execute my tests, all of the test suite looks green, however i want to make the test fails when this kind of warns appears to force a correct test implementation i was looking for information and with jest it is possible doing something like this: ```let warn = jest.spyOn(global.console, 'warn'); /// do some test expect(warn).not.toBeCalled();``` however when i tried this does not work because the pact console is not the same that the jest console and i can access that global.console value. so i can ask if there is a way to do something like this or any other idea about how to make this test fail?

mui_ume
2020-02-24 13:45
this is not an issue however I got this error ```AIL __provider-pacts__/authentication_api.verify.pact.js Pact Verification ? validates the expectations of Authentication Service (1534ms) ? Pact Verification ? validates the expectations of Authentication Service TypeError: server.close is not a function 33 | 34 | return new Verifier(opts).verifyProvider().finally(() => { > 35 | server.close(); | ^```


sagupta
2020-02-24 14:12
ok so i tried the below in a short version of path and i get this error. Example ?/companies/7aeeef69-ca14-5b3c-9022-565ea1b16d60/? does not match provided regular expression ?/companies/w{8}-w{4}-w{4}-w{4}-w{12}/? path: term({ generate : ?/companies/7aeeef69-ca14-5b3c-9022-565ea1b16d60/?, matcher : ?/companies\/\w{8}\-\w{4}\-\w{4}\-\w{4}\-\w{12}\/? })

mui_ume
2020-02-24 14:42
I replaced line 34-35 with ``` return new Verifier(opts).verifyProvider().then(output => { console.log("Pact Verification Complete!") console.log(output) })```

mui_ume
2020-02-24 14:43
I got this error: ```Verifying a pact between iConsumer and iProvider Given Authenticate with valid access token access_token, token_type and refresh_token with POST /api/uaa/oauth/token returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which equals "application/json" (FAILED - 3) "X-Active-Organization" which is an instance of String "Authorization" which is an instance of String Failures: 1) Verifying a pact between iConsumer and iProvider Given Authenticate with valid access token access_token, token_type and refresh_token with POST /api/uaa/oauth/token returns a response which has status code 200 Failure/Error: expect(response_status).to eql expected_response_status expected: 200 got: 500 (compared using eql?)```

dan.garland
2020-02-25 10:28
has joined #pact-js

ihor.dobrovolskyi
2020-02-25 12:30
has joined #pact-js

ihor.dobrovolskyi
2020-02-25 12:34
Hello! Please explane me how can I change path for quest in `stateHandlers` section? For exampe: I need to change the UUID in request path Thanks!

bheemreddy181
2020-02-25 14:46
has joined #pact-js

matt.fellows
2020-02-25 21:58
can you please elaborate?

matt.fellows
2020-02-25 21:59
What kind of warning are you getting? Failing a Pact test based on a console log seems very strange to me. Can you please elaborate on your scenario?

aaronmckaynz
2020-02-26 05:16
has joined #pact-js

ckkinay
2020-02-26 09:36
has joined #pact-js

paolaagudelo10
2020-02-26 13:04
@matt.fellows sure, i am having the "Ignoring unsupported matching rules on arrays" warning, according to pactSupport this issue it's has been solved for body parameters https://github.com/pact-foundation/pact-js/issues/205 however the error is still appearing in matching rules for query parameters. So i want to control this and make the test fails when this warning appears.

matt.fellows
2020-02-26 21:25
Is it causing actual issues though? The ?warn? for the matchers are only there to say that it may not use a matcher (and instead use an exact value). But if the tests don?t fail on either side, why would you want to still fail it on the warning? If it?s a bug in the warning code (as it may be) then failing your test would seem silly.

matt.fellows
2020-02-26 21:26
Personally I would just ignore it

matt.fellows
2020-02-26 21:26
Perhaps I?m missing something though. @bethskurrie any thoughts?

bethskurrie
2020-02-26 21:27
This query string parameters thing is a pain.

bethskurrie
2020-02-26 21:27
It's too hard to explain why it's showing that warning, but it can be safely ignored.

bethskurrie
2020-02-26 21:27
I'm sorry about it - I've tried to fix it a few times, but it's a tricky one.

bethskurrie
2020-02-26 21:28
It's to do with the way the parameters are serialised in a v2 pact. The query is a string, but the matchers say it's a hash.

bethskurrie
2020-02-26 21:28
So the library goes "you can't apply these hash matchers to a string"

matt.fellows
2020-02-26 21:37
Thanks Beth, so yes, don?t try to spy on the pact framework and use string output to fail a test.

bethskurrie
2020-02-26 21:37
Def don't fail the test.

bethskurrie
2020-02-26 21:38
The query matchers aren't even used in the provider tests.

bethskurrie
2020-02-26 21:38
It's just a deserialization warning

paolaagudelo10
2020-02-26 22:24
Hello, @matt.fellows and @bethskurrie i solved the error by sending an exact value as you suggested, however i want to forced a right implementation in test that are going to be add into my suit, from other developers that could see a warning and just ignore.

bethskurrie
2020-02-27 05:12
@paolaagudelo10 would you be able to send me a redacted copy of the pact that is causing the issue?

bethskurrie
2020-02-27 05:13
Now I think about it, I was sure I'd actually fixed this warning.

closenet.uk
2020-02-27 16:20
hey @matt.fellows we've just been getting issue with yarn audit report an issue with PACT version due to this dependency https://github.com/kevva/decompress/issues/71

davidmolinero.com
2020-03-01 19:41
has joined #pact-js

joel.whalen
2020-03-02 17:19
has joined #pact-js

simon.nizov
2020-03-03 17:17
has joined #pact-js

simon.nizov
2020-03-03 17:24
Hi! I?m trying to debug why my provider publishes verification results for only 1 of its 2 consumers but all I can see is this: ```[2020-03-03T17:15:11.505Z] INFO: pact@9.6.0/42271 on SNizov-mbk13.local: Verifying provider [2020-03-03T17:15:11.515Z] INFO: pact-node@10.2.4/42271 on SNizov-mbk13.local: Verifying Pacts. [2020-03-03T17:15:11.516Z] INFO: pact-node@10.2.4/42271 on SNizov-mbk13.local: Verifying Pact Files [2020-03-03T17:15:19.013Z] INFO: pact-node@10.2.4/42271 on SNizov-mbk13.local: Pact Verification succeeded.``` Is there a way to configure `Verifier` to print the more verbose ruby-style output when executing? Or some other way to check out the verification logs?

matt.fellows
2020-03-03 20:55
I'm assuming you've set the publishing flag to true? It should print out that it's doing it so I'm wondering if it's publishing at all

matt.fellows
2020-03-03 20:56
I don't think there is a verbose flag but will need to check

simon.nizov
2020-03-03 21:20
@matt.fellows I did, yes. It's publishing the results of one consumer but not the other.

matt.fellows
2020-03-03 21:31
mmm

matt.fellows
2020-03-03 21:31
Is there a longer log file than that you can share (privately/redacted if necessary?)

matt.fellows
2020-03-03 21:32
(there is a `--verbose` flag on the verifier actually, so you could try to invoke the verifier locally - it will probably fail, but should publish 2 sets of verification results)

matt.fellows
2020-03-03 21:32
are the pacts it?s fetching from the Pact Broker? (assuming yes but have to ask)

simon.nizov
2020-03-03 21:43
I would if I could.. that?s really all of it :man-shrugging:

simon.nizov
2020-03-03 21:44
You mean to use the standalone executable?

simon.nizov
2020-03-03 21:44
Yep

surajkeshri
2020-03-03 21:46
has joined #pact-js

simon.nizov
2020-03-03 21:54
Ok figured it out. I?m using `consumerVersionTag: ['dev']` but one of the consumers isn?t tagged at all. Thanks @matt.fellows!

matt.fellows
2020-03-03 21:55
ahhh!

matt.fellows
2020-03-03 21:55
so that means it?s only pulling down one contract. Got it

matt.fellows
2020-03-03 21:55
hmm, how can we make that clearer?

surajkeshri
2020-03-03 21:56
Hi everyone! I'm new to this group. First of all, I love pact. I've been using it for more than a month and I'm really enjoying it. However these is one error I've frequently faced. I'm facing the "Missing request" issue when using multiple tests with the same consumer provider pair in multiple files. The weird thing about this error is that I don't get it in every run of the test suite. Also, I don't get an error when the tests are in the same file. I've tried to follow the advice in https://github.com/pact-foundation/pact-js#splitting-tests-across-multiple-files. In particular, I'm using the `merge` as the `pactFileWriteMode`. Also, I 'm running the tests using `jest --runInBand` . I've tried other modes like `update` but have not been able to solve problem. Please advice!

matt.fellows
2020-03-03 21:57
BTW what testing framework do you use @simon.nizov? I?d like to create a few wrappers for provider verification. This way, I could provide granular test feedback on a per contract, per assertion basis. So you?ll get an individual failure on ?Contract between Consumer A and Provider B > some scenario > status should be 200? type thing. I think this would make it clearer if another consumer wasn?t showing up, and also of course which exact thing wasn?t working

matt.fellows
2020-03-03 21:57
(I?m just on the train and about to swap stations, so will follow this all up when I land in the office)

simon.nizov
2020-03-03 21:57
So, the ruby verifier prints this: ```INFO: Fetching pacts for X from https://.... INFO: Reading pact at https://***:*****@mybroker/pacts/provider/X/consumer/Y/version/1.0.15074.dev``` And then this for the second consumer ```INFO: Reading pact at https://***:*****@mybroker/pacts/provider/X/consumer/Z/version/1.0.3574.dev``` Which is helpful

matt.fellows
2020-03-03 21:58
Can you please share your code? Redacted if necessary. This smells of a promise not being correctly handled

surajkeshri
2020-03-03 21:58
Yes

simon.nizov
2020-03-03 21:59
Also each of those has a line like this at the end: ```INFO: Verification results published to https://...```

simon.nizov
2020-03-03 22:00
I?m using Jest. But the verification step is just a .js file that I added as a script to `package.json` and I run during our CI build.

matt.fellows
2020-03-03 22:02
Got it. I'll try and spike what I mean in the next week or so and ping this channel when I have it. I think it will help this situation

simon.nizov
2020-03-03 22:02
Cool, thanks for the help!

surajkeshri
2020-03-03 22:03
One thing to note is that I'm using pact-jest library which makes it easy to setup provider. See pactWith test block in both files.

matt.fellows
2020-03-03 22:06
Is addUser a promise? Can you also share the log file that talks about mismatches? That will help see the sequence of events from the perspective of Pact

surajkeshri
2020-03-03 22:07
No addUser is a sync function: ```export const addUser = (client: ApolloClient<any>, userId: string) => { // const graphqlClient = createClient({ graphqlURL: url || '' }); client.writeQuery({ query: CURRENT_USER, data: { authStatus: { userId: userId || null, signinError: null, signupError: null, signupSuccess: null, __typename: 'authStatus', }, }, }); };```

surajkeshri
2020-03-03 22:10
Error jest log ``` FAIL src/components/auth/initial-profile-setup.spec.tsx (5.054s) ? Console console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: POST /graphql See /Users/surajkeshri/Documents/Developer/crewhood/frontend/pact/logs/Frontend-GroupService-mockserver-integration.log for details.```

surajkeshri
2020-03-03 22:10
Note that the log file is overwritten everytime a different test file runs with the same consumer provider pair so in thisw case it didn't show any missing request in log file.

surajkeshri
2020-03-03 22:12
Here's the pact file which has all the interactions:

surajkeshri
2020-03-03 22:13
so none of thee interactions are missing in the pact file but I think when the test is run maybe the files are not written before that and there is delay so the test ends up not finding the interaction?

matt.fellows
2020-03-03 22:14
Yeah that log file looks ok. If you only run one of the tests can you ever get it to fail? Or is it only when you combine them?

matt.fellows
2020-03-03 22:15
Are you running them on a different mock server port? That matters too (sorry on mobile)

surajkeshri
2020-03-03 22:16
No one test always passes

surajkeshri
2020-03-03 22:16
yes a new port is created every time Ithink

surajkeshri
2020-03-03 22:17
I can force the same port though if you'd suggest me trying that

surajkeshri
2020-03-03 22:22
so it tried same port for the Frontend-GroupService pair and I got the same error. (One out of 7 times I think)

matt.fellows
2020-03-03 22:33
thanks

matt.fellows
2020-03-03 22:33
I?m confused about how ```addUser(apolloClient, userId);``` is not a promise - it?s making a network call right? If so, I don?t know how it can?t be one

surajkeshri
2020-03-03 22:35
this function is just adding some data to the cache. Here's the signature of the function: ```writeQuery<TData = any, TVariables = OperationVariables>(options: DataProxy.WriteQueryOptions<TData, TVariables>): void;```

matt.fellows
2020-03-03 22:35
ah ok

matt.fellows
2020-03-03 22:37
so what line is responsible for the http request that makes the graphql post?

surajkeshri
2020-03-03 22:38
That is done when I render the component using the render function. For instance, for landing.tsx here's the react component (the apollo client query makes the graphql call): ```import React from 'react'; import gql from 'graphql-tag'; import styled from 'styled-components'; import { useQuery } from '@apollo/react-hooks'; import tw from 'tailwind.macro'; import { user } from '../../generated/user'; import { Nav } from './nav'; import { useAuth } from '../../auth-api'; const Wrapper = styled.div``; export const GET_USER_PROFILE = gql` query user($id: String!) { user(id: $id) { id email name avatarUrl __typename } } `; export const Landing: React.FC<{}> = () => { const [{ userId }] = useAuth(); const result = useQuery<user>(GET_USER_PROFILE, { variables: { id: userId }, skip: !userId, }); return ( <Wrapper> {result?.data?.user && ( <span className="text-bold text-black font-lg">{`Welcome ${result.data?.user.name}`}</span> )} <Nav /> </Wrapper> ); };```

matt.fellows
2020-03-03 22:41
Ah, I see. I?m not a React expert but I follow. Ideally, I would separate the tests from the UI layer


surajkeshri
2020-03-03 22:42
Yeah I'd too but this has become the standard with this library. They want the data fetching to live inside the component and it's hard to separate them.

matt.fellows
2020-03-03 22:42
I see

matt.fellows
2020-03-03 22:42
I can understand why, it just makes your tests a little messy. But let?s work through it

surajkeshri
2020-03-03 22:43
ApolloClient has their own data fetching mocking thing but I think Pact works much better because it actaully captures the interaction which can be verified by the provider.

matt.fellows
2020-03-03 22:43
got it

matt.fellows
2020-03-03 22:44
```const result = useQuery<user>(GET_USER_PROFILE, { variables: { id: userId }, skip: !userId, });``` So, presumably _that_ is the thing that makes the call and is a Promise?

surajkeshri
2020-03-03 22:44
yeah so this call ```const result = useQuery<user>(GET_USER_PROFILE, { variables: { id: userId }, skip: !userId, });``` makes the request

surajkeshri
2020-03-03 22:45
and that's the graphql request that I'm mocking by adding this interaction: ```const getUserProfileInteraction = createGraphqlInteraction({ query: GET_USER_PROFILE, variables: { id: userId }, responseBody: { data: { user: { name: pact.Matchers.like('Some name'), avatarUrl: pact.Matchers.like(avatarUrl), id: userId, email: pact.Matchers.like(email), __typename: 'User', }, }, }, uponReceiving: 'getUserProfile', state: `user with id ${userId} exists`, requestHeaders: { 'x-auth': JSON.stringify({ userId }) }, });```

matt.fellows
2020-03-03 22:46
Is there any log file that has the failure logged in it? Unfortunately, everything so far looks like it?s working!

matt.fellows
2020-03-03 22:47
I think you can specify the log file for each `pactWith` - so perhaps set them to different files so we can see what?s happening?

surajkeshri
2020-03-03 22:47
okay let me try that

matt.fellows
2020-03-03 22:48
ta

surajkeshri
2020-03-03 23:06
okay so I separated out the log and pact file folder for both the tests. Here's the log and the interaction file for the error:

surajkeshri
2020-03-03 23:36
so as I see it in the logs: the two interactions are being registered with OperationName `InitialProfile` and `EditInitialProfile`. When a request is received for the first interaction it is matched (line 152). For the second request, it says (line 192-199) ```WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /graphql W, [2020-03-03T18:03:52.508802 #67660] WARN -- : Missing requests: POST /graphql``` In the DEBUG part though, it is calling the request with the same operation name EditInitialProfile and it does match the regex of that registered interaction. But somehow it didn't detect that. But later on on line 229 it says that it found the matching response for that request. I think the bug is that it is not finding the interaction the first time as shown above but it does find it later? How can it say that the interaction is missing the first time and then find it later for the same request?

osirisnos4a2
2020-03-03 23:51
has joined #pact-js

surajkeshri
2020-03-04 22:18
Hi Matt, does this error make sense? I have not been able to debug this yet.

matt.fellows
2020-03-05 06:51
OK, so reading that log things are clearer. This is the events as far as the Pact system is concerned: 1. You register an expectation for InitialProfile 2. You register an expectation for EditInitialProfile 3. You then make a request for InitialProfile and it finds a response 4. Something is then calling the ?verify? method because it starts to check if requests (1) and (2) have happened - but only InitialProfile has happened - so it errors saying it?s missing EditInitialProfile 5. at about the same moment, a request comes in for EditInitialProfile and the server responds to that (hence why it found it) Missing requests are not that Pact couldn?t find it, but that your code didn?t make the request before you called verify. This smells of a) promises not resolving correctly or b) two sets of tests talking to the same mock service. The mock service is stateful, you can?t have parallel tests communicating to it. I?m not sure if that?s an issue with the jest-pact library your using or in your setup. But you need to find out why those things are happening concurrently.

matt.fellows
2020-03-05 06:55
I?m wondering if the wait 0 is not long enough? ``` const button = await findByText(/looks good/i); userEvent.click(button); await wait(0);``` In any case, there is an asnchronous event there (the click) and I?m pretty sure that?s why the request is coming in too late - the test will complete, and the `afterAll` hook that runs verify will kick in creating a race condition between the call editInitialProfile and the verification process. I think this is the source of your flakiness

matt.fellows
2020-03-05 10:35
(Sorry for the delay)

tyler.rasor
2020-03-05 12:58
has joined #pact-js

surajkeshri
2020-03-05 19:22
This is helpful, thanks. I've delve deeper today.

surajkeshri
2020-03-08 01:55
Hi Matt, I think you debugged it perfectly!!! Thank you so much. I just increased the wait to 10ms and ran the test for 15 times without any error. :clap:

tjones
2020-03-09 12:28
Late to the party here - glad you got the issue fixed, but I have a question - I?ve heard about this graphql library where data fetching is part of the component rendering. I?m not a graphql user myself, but this sounds like a very unhelpful pattern (among other reasons, it couples UI testing to API testing, which causes issues like the one you?ve discovered). Is this the standard for graphql? Or just this particular pattern/library for graphql? Could you tell us a bit more about it? None of the core pact js people are heavy graphql users, so I?m interested to know how we could better support it.

tjones
2020-03-09 12:29
If this is a common pattern, do you think there?s a way we could provide wrappers that make it easier to write pact tests for fetches during renders?


matt.fellows
2020-03-09 12:39
If I understand correctly, the `useQuery` bit can be tested separately from the component itself - most documentation just shows it all together

matt.fellows
2020-03-09 12:40
I would probably want a layer between `useQuery` and my component, but then you might just be re-inventing the GraphQL library. It has the ?only doing it for testability? smell

aaron
2020-03-09 21:36
has joined #pact-js

bsigney
2020-03-13 05:11
has joined #pact-js

matt.fellows
2020-03-16 06:07
Thanks Tim for your PR/Issues rampage

tjones
2020-03-16 06:07
Raargh!

matt.fellows
2020-03-16 06:07
(TODO item removed from tomorrow :stuck_out_tongue: )

tjones
2020-03-16 06:07
I mean, um, you?re welcome

tjones
2020-03-16 06:08
releasing a new pact-js now

tjones
2020-03-16 06:10
v9.8.1 - security fixes, and CORS headers improved.

matt.fellows
2020-03-16 06:10
ah yes - I actually think there is a failing Pact test for Pactflow that needs that. I?ll confirm tomorrow

tjones
2020-03-16 06:10
party on!

uglyog
2020-03-17 06:59
:point_up: we have an initial version of Pact-JS with V3 and XML support

uglyog
2020-03-17 06:59
But only for linux and OSX and node 10 and 13

bethskurrie
2020-03-17 07:27
Amazing work @uglyog and @matt.fellows!

matt.fellows
2020-03-17 07:28
I'll take whatever credit Ron is willing to concede

tjones
2020-03-17 07:28
haha!

tjones
2020-03-17 07:28
awesome!

tjones
2020-03-17 07:29
I just want to know how he did this: > uglyog > Release - v10.0.0-beta.1

uglyog
2020-03-17 07:32
hmm, no, you probably don't want to know how I did that :smile:

tjones
2020-03-17 07:33
hahaha!

bradyzp
2020-03-17 17:59
has joined #pact-js

arho.huttunen
2020-03-18 19:02
has joined #pact-js

uglyog
2020-03-20 02:30
@matt.fellows @tjones I've added some initial docs on the V3 version :point_right: https://github.com/pact-foundation/pact-js#pact-js-v3

tjones
2020-03-20 02:38
This is exciting! Nice work

bethskurrie
2020-03-22 09:48
Pact node doesn't shorten the git sha when it publishes a pact or verification does it peeps?

matt.fellows
2020-03-22 09:48
Nope. Pass thru

bethskurrie
2020-03-22 09:50
Ta

bethskurrie
2020-03-22 09:51
And can verbose mode be switched on?

bethskurrie
2020-03-22 09:52
So it logs the requests and responses?

matt.fellows
2020-03-22 09:53
Off the top of my head I can't recall. But it literally just maps to the args for the Ruby CLI. I think debug mode should show the args sent to the CLI exec'd process

tjones
2020-03-23 01:05
If verbose mode is an option for the standalone verifier, pact-node doesn?t know about it

tjones
2020-03-23 01:05
this is an easy change, and I could get it out today if you need it

bethskurrie
2020-03-23 01:05
the related issue was fixed

bethskurrie
2020-03-23 01:05
user error

bethskurrie
2020-03-23 01:05
but yes, please do expose --verbose

bethskurrie
2020-03-23 01:05
it helps debug issues communicating with the broker

tjones
2020-03-23 01:05
cool - if you have a moment, could you open a ticket?

bethskurrie
2020-03-23 01:05
pact node or js?


tjones
2020-03-23 01:06
Thank you!

matt.fellows
2020-03-23 02:55
@tjones thanks for doing https://github.com/pact-foundation/pact-node/commit/2c681ef4d7b517229cbd5e96fc8db74d6a77713b. It?s been on my mind. FWIW I think we should do https://docs.travis-ci.com/user/build-stages. Because for e.g. if linux passes but OSX fails, or another Node Version fails, it will still release

matt.fellows
2020-03-23 02:55
using build stages would prevent that

tjones
2020-03-23 02:56
Ah yes, good point. My ?pact lunch? is almost up, so I?ll make an issue for that

matt.fellows
2020-03-23 02:58
:smile:

matt.fellows
2020-03-23 02:58
?Pact lunch?


matt.fellows
2020-03-23 03:04
thx

tjones
2020-03-23 03:04
don?t thank me yet - looks like I broke pact-js

tjones
2020-03-23 03:04
but not too seriously

matt.fellows
2020-03-23 03:07
:smile:

tjones
2020-03-23 03:09
Also: The tests seem to pass on travis, but fail locally for me: ``` 1) Net #isPortAvailable when the no local hosts are available returns a rejected promise: AssertionError: expected promise to be rejected but it was fulfilled with undefined```

tjones
2020-03-23 03:09
have you seen this before?

matt.fellows
2020-03-23 03:14
mmmm no, let me try now

uglyog
2020-03-23 03:19
I found that fails on OSX

uglyog
2020-03-23 03:19
In Travis it has: sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0

tjones
2020-03-23 03:21
Yep. I?ve removed the test. The comment about node having a particular behaviour is incorrect

tjones
2020-03-23 03:21
> In most operating systems, listening to the unspecified IPv6 address (::) may cause the net.Server to also listen on the unspecified IPv4 address (0.0.0.0). https://nodejs.org/api/net.html#net_server_listen_options_callback

tjones
2020-03-23 03:22
^ this is what the documentation says

grzegorzkrol90
2020-03-23 08:31
has joined #pact-js

vitaliy.grigoruk
2020-03-24 08:44
Hi everybody. Is there a way to tell `Verifier` to run verification with all versions of a contract tagged with a specific tag (not only `latest` versions)? Our `consumer` is an iOS app and we would like to make sure that all versions that were released to AppStore (all of them are tagged with `release`) are verified every time there is a change on provider side.

bethskurrie
2020-03-24 09:02
Yes

bethskurrie
2020-03-24 09:03
But it's in a feature that's in beta.

matt.fellows
2020-03-24 09:03
Ah, we haven't added that to pact js yet have we? Just pending pacts?

bethskurrie
2020-03-24 09:04
It's just making use of the new api

matt.fellows
2020-03-24 09:04
I should be able to get a start on that later tonight. It's not a lot of work but the type system doesn't yet support it

matt.fellows
2020-03-24 09:04
BBL I'll follow up

bethskurrie
2020-03-24 09:04
Are you using Pactflow or OSS broker @vitaliy.grigoruk?

bethskurrie
2020-03-24 09:05
Sorry, I can't remember!

vitaliy.grigoruk
2020-03-24 09:05
I?m using pactflow

bethskurrie
2020-03-24 09:06
So, if you want it asap, I can tell you how to hack it. If you're OK to wait, Matt might be able to get the official support out reasonably quickly.

bethskurrie
2020-03-24 09:06
Matt, it's just passing in the consumer version selectors.

vitaliy.grigoruk
2020-03-24 09:07
I?d appreciate if you can share some info how this could be done now

bethskurrie
2020-03-24 09:07
The underlying code is already using the new api

vitaliy.grigoruk
2020-03-24 09:08
so it is just about passing the right command line args to `pact-provider-verifier`?

bethskurrie
2020-03-24 09:09
Yes.

bethskurrie
2020-03-24 09:09
There's a new --consumer-version-selector parameter


bethskurrie
2020-03-24 09:10
There's the master issue ^^

bethskurrie
2020-03-24 09:10
It describes how to use the new API.

bethskurrie
2020-03-24 09:10
What you could do is call the API directly, to get the list of pacts to verify.

bethskurrie
2020-03-24 09:11
And then feed that into your pact js configuration.

bethskurrie
2020-03-24 09:12
Do a POST to `pacts/provider/{provider}/for-verification` with the body ```{ "consumerVersionSelectors": [ { "tag": "prod" } ] }```

bethskurrie
2020-03-24 09:13
That will return a list of pact verification objects (deduped so that if multiple pacts have the same content, it only gets verified once). You can pull the pact URLs out, and then manually configure pact-js to verify those URLs.

bethskurrie
2020-03-24 09:13
Does that make sense?

bethskurrie
2020-03-24 09:15
If you're using can-i-deploy, then you can already specify "all versions of this particular consumer". Docs are here: https://github.com/pact-foundation/pact_broker-client#alternate-usage---specifying-dependencies-explicitly

bethskurrie
2020-03-24 09:16
See the "Mobile provider use case".

vitaliy.grigoruk
2020-03-24 09:17
Thank you @bethskurrie, I?ll try this!

bethskurrie
2020-03-24 09:17
We'll make an announcement when it's out in the js code.

vitaliy.grigoruk
2020-03-24 09:23
It looks like there is no way to specify `consumer` name filter for `pacts/provider/{provider}/for-verification` .

vitaliy.grigoruk
2020-03-24 09:24
we have only 1 mobile consumer (where we need to verify all `release` contract versions) and all other consumers are web apps (where we need to verify only `latest` version

bethskurrie
2020-03-24 09:25
Fair point.

bethskurrie
2020-03-24 09:25
Easily added

bethskurrie
2020-03-24 09:26
I was expecting to do it, but nobody had asked yet.

bethskurrie
2020-03-24 09:26
I've got an OSS day tomorrow. I'll see if I can add it then.

bethskurrie
2020-03-24 09:29
If you were in a super hurry, you could do a nasty match on the urls!

vitaliy.grigoruk
2020-03-24 09:30
yeah, that?s what I was also thinking about :slightly_smiling_face:

bethskurrie
2020-03-24 09:33
Do one query to get the latest prod pacts (you'll need to put latest:true in the selector) and one to get all the prod pacts, and just keep the ones for the consumer you care about.

matt.fellows
2020-03-24 12:44
I'll look at this tomorrow @vitaliy.grigoruk

vitaliy.grigoruk
2020-03-24 12:58
great. Looking forward to that. Ping me if I can help somehow

aliihlail
2020-03-24 18:44
has joined #pact-js

audun.halland
2020-03-24 21:33
has joined #pact-js

audun.halland
2020-03-24 21:40
Hi, I?m trying `10.0.0-beta.2` with typescript, There?s a problem importing the module. In my `node_modules/@pact-foundation/pact/package.json` it says `{ ... "types": "./dist/pact.d.ts", ... }`, but the source files themselves are not in `./dist/` but at the same level as the `package.json`. I?m no JS expert, but this is how far I?ve come debugging the problem..

uglyog
2020-03-24 22:05
:point_up: @matt.fellows is that just the package file that needs to be corrected?

matt.fellows
2020-03-24 22:06
Let me take a quick look

matt.fellows
2020-03-24 22:07
yes I think so. In the `v3.0.0.` branch they point at `dist` but in master they are relative

matt.fellows
2020-03-24 22:08
Long term, I think I need to change the way the release works. There were reasons for having it in `dist` separate to compiling alongside the project (I think it was much harder to exclude certain things.

audun.halland
2020-03-24 22:31
I hacked the problem locally, and now I think I?m a bit closer:

audun.halland
2020-03-24 22:31
``` dlopen(/Volumes/uf4/pact-typescript-lib/node_modules/@pact-foundation/pact/native/index.node, 1): no suitable image found. Did find: /Volumes/uf4/pact-typescript-lib/node_modules/@pact-foundation/pact/native/index.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 /Volumes/uf4/pact-typescript-lib/node_modules/@pact-foundation/pact/native/index.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00```

audun.halland
2020-03-24 22:31
@uglyog

audun.halland
2020-03-24 22:34
This is on a mac using `yarn` (not npm) to install the package

audun.halland
2020-03-24 22:36
`file` info on this file is `ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=e0643a965bfb7ae3a0896a88b96e042af4e2833e, with debug_info, not stripped`

uglyog
2020-03-24 22:38
The NPM package has an linux image in (it should not have any)

uglyog
2020-03-24 22:39
The npm install command has a ` --update-binary` argument to get it to replace that binary with the correct one

audun.halland
2020-03-24 22:40
Yes, but I?m not using npm :stuck_out_tongue: Need to find another way then

uglyog
2020-03-24 22:41
Yeah, I'm just looking for a yarn alternative

audun.halland
2020-03-24 22:42
I searched it but cannot find anything

uglyog
2020-03-24 22:42
But you can download the binary from the releases and unpack it into the node modules

audun.halland
2020-03-24 22:42
yes, I?ll try that, thanks

uglyog
2020-03-24 22:42
That is what node-gyp does on install

uglyog
2020-03-24 22:43
The next release will not have the linux binary in the NPM package

uglyog
2020-03-24 22:52
That's going to be a problem for a lot of people!

audun.halland
2020-03-24 23:00
`sudo xattr -d com.apple.quarantine node_modules/@pact-foundation/pact/native/index.node` solved it

audun.halland
2020-03-24 23:02
`Error: Pact verification failed - expected interactions did not match actual.` :tada:


uglyog
2020-03-24 23:05
I'll update the readme with those instructions

audun.halland
2020-03-24 23:59
Hm, I actually need to use `new PactV3(..)` to use this right?

audun.halland
2020-03-24 23:59
`new Pact(..., spec: 3)` won?t work?

audun.halland
2020-03-25 00:21
Ok, given this is true, I have question about the new PactV3 API. It looks like it?s designed to have all tests against the mock server executed in a callback. The old API uses lifecycle control functions. That means upgrading won?t be painless..

audun.halland
2020-03-25 00:36
Also I have a scenario where a single test is calling several endpoints in different providers. Think GraphQL-servers fetching data from many endpoints. The _test abstraction_ is executing a graphql query, and I?ll verify that the set of correct REST endpoints are called in the other end.

audun.halland
2020-03-25 00:40
It?d been nice to still have a way to control the mock servers via lifecycle calls. Either way it?s better than spawning ruby processes, because these Rust mock servers will die along with the node process anyway.

tjones
2020-03-25 00:51
Hi @audun.halland! Thanks for the feedback, this is very useful. I haven?t had time to look at the V3 branch yet (although I?m excited about it) - I?m hoping to be able to have the upgrade as painless as possible. Your test scenario is interesting. If it were me, I?d probably want to split the test boundaries so that Pact covers each individual request/ response, and unit tests cover joining the data returned together (since the join would be done after the request was serialised into a data object). Is that possible in your case?

uglyog
2020-03-25 00:52
What are lifecycle control functions?

uglyog
2020-03-25 00:54
We decided to keep the new API separate so it won't impact existing V2 tests, but it can be merged in the future

audun.halland
2020-03-25 01:02
I mean like `async Pact.verify()`, `async Pact.finalize()`

audun.halland
2020-03-25 01:05
@tjones this is what I would normally do in a language that has proper typed deserialization of JSON responses. In a dynamic language like JavaScript there?s no ?deserialization? so I normally prefer to have fatter tests. If not, there?s almost no code changes that will be able to fail the tests. Something like ?test entropy??

uglyog
2020-03-25 01:16
Those lifecycle functions are a limitation of using the ruby mock server. We are no longer constrained by those. We could use the same format, but I don't see the benefit apart from ease of switching from V2 to V3. I would prefer to create a better DSL and than one constrained by previous implementation.

audun.halland
2020-03-25 01:24
But that also happens to fit quite nicely into several JS test frameworks. E.g. A function runs before all the tests in the suite: The mock server is started. Another function runs after the group of tests: The mock server is killed. In e.g. Jest this is `beforeAll`/`afterAll` that are both asynchronous.

uglyog
2020-03-25 01:26
We can definitely support that flow, if that is what makes sense

audun.halland
2020-03-25 01:29
There are of course other ways to do things, but I personally don?t like to use _two_ test frameworks at the same time. (test must be executed from a pact callback and that runs inside jest)

tjones
2020-03-25 01:57
I don?t think Jest constrains us to a particular way of thinking about the DSL. I do agree that there are challenges with typesafety in Pact testing with javascript, but I think those exist wherever you cut the Pact boundary (and they also exist in general unit tests too). I usually mitigate that with fixtures - I?ve been meaning to write that up in a blog post.

tjones
2020-03-25 01:58
Or do you mean you want to run pact tests without a test runner framework?

tjones
2020-03-25 02:00
Making a separate thread for discussing test frameworks / test design so as not to clutter the V3 conversation above. @audun.halland, are you aware of: https://github.com/pact-foundation/jest-pact ?

audun.halland
2020-03-25 02:09
I understand the desire to automatically shut down the mock server after the test is done. Which this type of structure _will_ solve: ```it('tests stuff', async () => { const pact = new PactV3(...); pact.executeTest(async () => { // actual test }); };``` Still I don?t think it?s flexible enough to serve all users? needs.

audun.halland
2020-03-25 02:19
I wasn?t aware of it. It looks nice for simple usage, but I?m still fond of the flexibility in being able to execute against several providers in the same test. We _do_ sometimes use pact as part of integration test, even though I?m aware it?s not considered best practice. In some cases I think it?s the lesser evil..

uglyog
2020-03-25 02:20
We can support both forms

audun.halland
2020-03-25 02:31
I think apollo server is a good example. In a consumer test I want to verify that what the REST returns actually works mapping to into a GraphQL node tree. There?s usually a very thin layer between the ?back? REST client and the ?front? graphql server. Just writing a full end2end integration test saves time and many code lines :slightly_smiling_face:

audun.halland
2020-03-25 02:34
(and sometimes that kind of test will involve calling into more than one provider)

jwortmann719
2020-03-25 10:51
has joined #pact-js

jwortmann719
2020-03-25 10:53
Hi, does anyone knows if there is already an `ng add` library to add a pact configuration to an angular app? Would love to work on something like this

matt.fellows
2020-03-25 10:55
Oh, no I?m not aware - but please do!

cesar.lopes
2020-03-25 11:13
has joined #pact-js

matt.fellows
2020-03-25 12:08
@audun.halland thanks for the feedback. I actually would like to schedule a bit of a round table before the V3 interface is fully published. Right now, it?s in a very functional but also somewhat experimental state

matt.fellows
2020-03-25 12:08
The broader ecosystem, developer ergonomics and extensibility need to be considered

matt.fellows
2020-03-25 12:09
For example, we need to be able to support code debugging, developers should be able to wrap interfaces over the system - e.g. GraphQL - and it should be extensible and publish hooks so that Pact Jest and similar wrappers can modify the ergonomics/experience as desired

matt.fellows
2020-03-25 12:10
Ultimately, we won?t be able to satisfy all of the things, and the limitations of the underlying engine (Rust) will result in tradeoffs against flexibility. But it?s an exiting development!


vitaliy.grigoruk
2020-03-25 21:09
~Maybe I?m doing something wrong, but for some reason pactflow returns me contracts with tags that do not match `consumerVersionSelectors` Here is the request I send:~ ``` curl --silent -XPOST -H "Content-Type: application/json" \ -H "Authorization: Bearer $PACT_BROKER_TOKEN" \ -d '{"consumerVersionSelectors":[{"tag": "release"}]}' \ https://$http://COMPANY.pact.dius.com.au/pacts/provider/api/for-verification```

vitaliy.grigoruk
2020-03-25 21:10
Maybe I?m doing something wrong, but for some reason pactflow returns me contracts with tags that do not match `consumerVersionSelectors` Here is the request I send: ```curl --silent -XPOST -H "Content-Type: application/json" \ -H "Authorization: Bearer $PACT_BROKER_TOKEN" \ -d '{"consumerVersionSelectors":[{"tag": "release"}]}' \ https://$http://COMPANY.pact.dius.com.au/pacts/provider/api/for-verification```

vitaliy.grigoruk
2020-03-25 21:11
I?m fetching contract URLs using jq: ```jq -r '._embedded.pacts | .[] | ._links.self.href | select(. | contains("consumer/ios-app"))'```

vitaliy.grigoruk
2020-03-25 21:13
I?ve noticed that some contract URLs refer a consumer version that doesn?t have `release` tag.

ravi.dasari
2020-03-25 21:30
has joined #pact-js

ravi.dasari
2020-03-25 21:33
@here how do I use pending pacts beta feature ? is there any documentation for this? I simply cannot find anything related to this except for the blog - http://blog.pact.io/2020/02/24/how-we-have-fixed-the-biggest-problem-with-the-pact-workflow/

matt.fellows
2020-03-25 21:47
How did you hear about it (apart from that blog)? It's not yet in JS yet (I submitted a OR to Pact Node last night that would be the key thing in doing so, however)

matt.fellows
2020-03-25 21:48
There is an environment variables you can use in the meanwhile, I'll share when back at a desk

bethskurrie
2020-03-25 22:16
You won't be seeing consumer versions in the URLs, you'll be seeing pact versions.

bethskurrie
2020-03-25 22:21
It's the "permalink" to the underlying content, not the URL that has the consumer version in it.

matt.fellows
2020-03-25 22:25
you need to a) be using http://pactflow.io and b) have exported `export PACT_BROKER_PACTS_FOR_VERIFICATION_ENABLED=true` @bethskurrie is (a) still a prerequisite?

bethskurrie
2020-03-25 22:25
no

matt.fellows
2020-03-25 22:25
:ok_hand:

bethskurrie
2020-03-25 22:25
You need to have the Pact Broker running with PACT_BROKER_FEATURES=pacts_for_verification

bethskurrie
2020-03-25 22:26
Also, you need to have an implementation that supports it, of which only the Ruby impl and standalone/dockerized pact-provider-verifier does.

bethskurrie
2020-03-25 22:28
I believe pact-js and pact-go are not far off @matt.fellows

bethskurrie
2020-03-25 22:29
pact-js just needs the `--enable-pending` flag exposed

bethskurrie
2020-03-25 22:30
If it's using the ruby stdout rather than doing any fancing parsing, it'll all just work.

bethskurrie
2020-03-25 22:34
Actually, I think pact-python does too.

matt.fellows
2020-03-25 22:34
Pact Go supports it - I should add some docs actually

matt.fellows
2020-03-25 22:34
Pact JS - sent a PR for that last night, in review

bethskurrie
2020-03-25 22:34
@ravi.dasari which language are you verifying in?

matt.fellows
2020-03-25 22:49
I?m assuming JS given we?re in this chanel

matt.fellows
2020-03-25 22:49
@bethskurrie JS is just waiting on this PR: https://github.com/pact-foundation/pact-node/pull/217

tjones
2020-03-26 00:50
Publishing that now :+1:

bethskurrie
2020-03-26 01:54
You should be able to check this by opening the matrix page and selecting "all versions with tag release" for that application.

bethskurrie
2020-03-26 01:55
The pact version sha isn't shown in the text columns unfortunately, but it is shown in the hover over text for the Pact Published column.

bethskurrie
2020-03-26 01:56
You should be able to find a row with a matching pact version sha. If you can't, then I can investigate it further for you.

ravi.dasari
2020-03-26 02:33
@bethskurrie thanks for the reply. I am using consumer with pact-js and provider for both node-js and java platforms. So I think I need this feature for both pact-js and pact-jvm.

bethskurrie
2020-03-26 03:15
It'll be a little while before pact JVM gets it, but Ron is working on it.

vitaliy.grigoruk
2020-03-26 08:28
I?m opening a first URL from the list that is returned by `curl` And it renders a page which shows pact contract for a specific version of consumer. And this versions has no tags at all?

bethskurrie
2020-03-26 08:29
That'll be the latest consumer version that has that pact content.

bethskurrie
2020-03-26 08:30
Technically, when you access a pact-version, it should show a list of all the consumer versions that have that content.

bethskurrie
2020-03-26 08:30
For better or worse, when I designed this resource, I made it select the most recent consumer version to display.

bethskurrie
2020-03-26 08:34
This API returns a list of Pact Versions, not a list of Pact Publications. I wanted to make the resources pretty much interchangeable though, so when you view a Pact Version resource, it picks the most recent Pact Publication that it belongs to.

vitaliy.grigoruk
2020-03-26 08:34
thanks for clarifications. Now it is more clear why I get these results.

bethskurrie
2020-03-26 08:36
With the benefit of hindsight, I should not have specified the consumer version resource at all, or made it a list, or made it a pb:latest-consumer-version relation.

vitaliy.grigoruk
2020-03-26 08:38
Is there any way to query API for all ?pact publications? that belong to the same ?pact-version??

bethskurrie
2020-03-26 08:39
no

bethskurrie
2020-03-26 08:39
it wouldn't be hard, but nobody has ever asked for it

bethskurrie
2020-03-26 08:39
what would you use it for?

bethskurrie
2020-03-26 08:40
btw, I'll have your "all prod pacts for this consumer" api out tomorrow.

bethskurrie
2020-03-26 08:40
and the get/post thing fixed

vitaliy.grigoruk
2020-03-26 08:40
was just curious if this is possible now to see how many pact publications belong to a particular version of the contract

vitaliy.grigoruk
2020-03-26 08:41
great, thank you very much!

bethskurrie
2020-03-26 08:41
You may be able to reverse engineer it from the matrix query.

bethskurrie
2020-03-26 08:44
ah, no. it uses the link with the consumer version.

bethskurrie
2020-03-26 08:44
If you go to the matrix page though, and hover over the pact publication cell, it will highlight all the pact publications that have the same pact version.

vitaliy.grigoruk
2020-03-26 09:00
> If you go to the matrix page though, and hover over the pact publication cell, it will highlight all the pact publications that have the same pact version. This actually works, thanks!

cesar.lopes
2020-03-26 21:31
Hey there, I?m trying to run a graphQL pact, how should I format the query: ```Matching keys and values are not shown { "body": { - "query": /\s*query\s*storeById\(\$id: + "query": "query storeById($id: String } } ```

deepakverma
2020-03-26 21:59
has joined #pact-js

matt.fellows
2020-03-26 22:12
Double check the issues online on Pact JS, I believe this may have come up before

rbenbolton
2020-03-26 22:57
has joined #pact-js


cesar.lopes
2020-03-27 09:13
any workaround for this?

cesar.lopes
2020-03-27 10:36
had to copy request body from apollo client and added __typename to the response, it works :smile:

matt.fellows
2020-03-27 12:16
Thanks. If you?re able to help work out how we can fix this in the GraphQL interaction types, I?d very much appreciate it

jwortmann719
2020-03-27 12:21
I started to work on a pact schematic. One can find the repo here https://github.com/JWO719/ngx-pact in case anyone wants to support or give feedback. I plan to release a first version just with scaffolding basic initialization beginning of next week

waquino
2020-03-29 21:24
has joined #pact-js

kaz.udesh
2020-03-30 03:39
has joined #pact-js

davidpihlaja
2020-03-30 19:09
has joined #pact-js

matt.fellows
2020-03-31 01:16
@tjones FYI I made some changes to the travis release processes last night, in order to get around the release problems. I tested a publish on a branch and it worked, but just a heads up in case there is an issue next time we release.

matt.fellows
2020-03-31 01:17
It now uses the multi-stage build to do the release step - so will _only_ release if the initial builds are all successful

tjones
2020-03-31 01:49
Nice work! Thanks for doing the legwork!

matt.fellows
2020-03-31 01:56
np

matt.fellows
2020-03-31 01:56
just had to be done

matt.fellows
2020-03-31 01:56
and it annoyed me so much that I passed the critical threshold

tjones
2020-03-31 02:00
DDD, or Derailment Driven Development

matt.fellows
2020-03-31 02:00
:smile:

ramspotla
2020-03-31 02:39
has joined #pact-js

ramspotla
2020-03-31 02:40
Hi There - I was wondering does anyone encounter below issue:

ramspotla
2020-03-31 02:40
?matchingRules?: { ?$.body.id?: { ?match?: ?regex?, ?regex?: ?^[0-9a-fA-F]+$? }

ramspotla
2020-03-31 02:40
I am using above matching rules but pact provider couldn?t match hexadecimal string

ramspotla
2020-03-31 02:41
* Expected ?5e82a81d8ffec3918330b305? but got ?5e82acc17d545aaf740e5591" at $.id

matt.fellows
2020-03-31 02:42
(FYI please format your code blocks using backticks to aid in readability)

matt.fellows
2020-03-31 02:42
Can you please share the full pact file and any logs?

ramspotla
2020-03-31 02:42
Ok sure

matt.fellows
2020-03-31 02:42
are both the consumers and providers using JS?

ramspotla
2020-03-31 02:42
`?matchingRules?: { ?$.body.id?: { ?match?: ?regex?, ?regex?: ?^[0-9a-fA-F]+$? }`

matt.fellows
2020-03-31 02:43
(triple backticks either side, or use the code block formatting option)

ramspotla
2020-03-31 02:44
```"matchingRules": { "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" }``` Yes both provider and consumer using JS

ramspotla
2020-03-31 02:50
```{ "consumer": { "name": "Client" }, "provider": { "name": "someservie" }, "interactions": [{ "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers/getengineer", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [{ "name": "Ram", "practice": "Test", "id": "5e8280694c55aa3b3263fe9a" }], "matchingRules": { "$.body[0].id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } }, { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers/addengineer", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": "5e82a81d8ffec3918330b305" }, "matchingRules": { "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } } ], "metadata": { "pactSpecification": { "version": "4.0.0" } } }```

ramspotla
2020-03-31 02:51
When running against provider I am seeing ?* Expected ?5e82a81d8ffec3918330b305? but got ?5e82af6fbc760fb6f185128d? at $.id?

matt.fellows
2020-03-31 02:52
@prabhuramchennai just as an aside, your resource model looks very non-RESTful

matt.fellows
2020-03-31 02:52
e.g. /engineers/addengineer should simply be a `POST` to `/engineers/`

matt.fellows
2020-03-31 02:53
e.g. /engineers/getengineer should simply be a `GET` to `/engineers/`

matt.fellows
2020-03-31 02:53
the resource is `engineer` and you?ve pluralised it :white_check_mark:

matt.fellows
2020-03-31 02:53
but the suffixes make it look like an RPC

matt.fellows
2020-03-31 02:53
How have you gotten pact specification `4.0.0`? That is not a valid specification for JS

ramspotla
2020-03-31 02:54
Yeah Matt . Just trying out tool

matt.fellows
2020-03-31 02:54
did you make the pact by hand?

matt.fellows
2020-03-31 02:54
bbl

ramspotla
2020-03-31 02:55
I was using pact:3.0.0 . Just changed to 4.0.0 see whether I am getting same issue

ramspotla
2020-03-31 02:55
Even with 3.0.0 I am seeing 3.0.o

matt.fellows
2020-03-31 02:56
How did you generate the pact? Is it JS on the consumer and provider?

matt.fellows
2020-03-31 02:56
Or did you write the pact by hand?

matt.fellows
2020-03-31 02:56
I think you want 2.0.0 anyway

ramspotla
2020-03-31 02:57
Tool successfully generated pact file.

ramspotla
2020-03-31 03:03
```I, [2020-03-31T14:01:36.146943 #49127] INFO -- : Registered expected interaction GET /engineers/getengineer D, [2020-03-31T14:01:36.147192 #49127] DEBUG -- : { "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers/getengineer", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": "Ram", "practice": "Test", "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] }, "metadata": null } I, [2020-03-31T14:01:36.153500 #49127] INFO -- : Received request GET /engineers/getengineer D, [2020-03-31T14:01:36.153615 #49127] DEBUG -- : { "path": "/engineers/getengineer", "query": "", "method": "get", "headers": { "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-03-31T14:01:36.153848 #49127] INFO -- : Found matching response for GET /engineers/getengineer D, [2020-03-31T14:01:36.153949 #49127] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": "Ram", "practice": "Test", "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] } I, [2020-03-31T14:01:36.160484 #49127] INFO -- : Verifying - interactions matched I, [2020-03-31T14:01:36.163947 #49127] INFO -- : Cleared interactions I, [2020-03-31T14:01:36.168877 #49127] INFO -- : Registered expected interaction POST /engineers/addengineer D, [2020-03-31T14:01:36.169028 #49127] DEBUG -- : { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers/addengineer", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } }, "metadata": null } I, [2020-03-31T14:01:36.173080 #49127] INFO -- : Received request POST /engineers/addengineer D, [2020-03-31T14:01:36.173206 #49127] DEBUG -- : { "path": "/engineers/addengineer", "query": "", "method": "post", "body": { "name": "New Engineer", "practice": "Dev" }, "headers": { "Content-Length": "40", "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-03-31T14:01:36.173392 #49127] INFO -- : Found matching response for POST /engineers/addengineer D, [2020-03-31T14:01:36.173498 #49127] DEBUG -- : { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } } I, [2020-03-31T14:01:36.177172 #49127] INFO -- : Verifying - interactions matched I, [2020-03-31T14:01:36.180264 #49127] INFO -- : Cleared interactions I, [2020-03-31T14:01:36.183980 #49127] INFO -- : Writing pact for EngineerService to /Users/ram/practice/pact-example/consumer-driven/consumer/pacts/client-engineerservice.json```

ramspotla
2020-03-31 03:04
```{ "consumer": { "name": "Client" }, "provider": { "name": "EngineerService" }, "interactions": [ { "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers/getengineer", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": "Ram", "practice": "Test", "id": "5e8280694c55aa3b3263fe9a" } ], "matchingRules": { "$.body[0].id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } }, { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers/addengineer", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": "5e82a81d8ffec3918330b305" }, "matchingRules": { "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

ramspotla
2020-03-31 03:05
as you can see pact file generated successfully by pact

matt.fellows
2020-03-31 03:12
Thanks Can you please share the actual response from the provider and also the verifier output

ramspotla
2020-03-31 03:16
After you pointed out I changed the version from spec 4.0.0 to 2.0.0.

ramspotla
2020-03-31 03:17
It worked .

ramspotla
2020-03-31 03:17
So what does that mean Matt?

ramspotla
2020-03-31 03:18
Can I find somewhere which version and which matchers should I use for JS?

matt.fellows
2020-03-31 03:56
How did you set it in the first place?

matt.fellows
2020-03-31 03:57
Just leave it as the default

matt.fellows
2020-03-31 03:59
Also, what made you think to change it? perhaps we have some misleading documentation

matt.fellows
2020-03-31 03:59
Also see feature support https://docs.pact.io/feature_support

tjones
2020-04-01 04:14
Hi @ramspotla, you can find the matcher documentation here: https://github.com/pact-foundation/pact-js#match-common-formats, with an example test below it. In your case, it looks like you?d want: ```provider.addInteraction({ state: "add a engineer", uponReceiving: "a request to post a engineer", withRequest: { method: "POST", path: "/engineers/addengineer", headers: { "Content-Type": "application/json; charset=utf-8" }, }, willRespondWith: { status: 201, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { name: "New Engineer", practice: "Dev", id: Matchers.term({matcher: "^[0-9a-fA-F]+$", generate: "5e82a81d8ffec3918330b305"}), }, }, })```

tjones
2020-04-01 04:17
I agree with matt?s comments about the API design, btw. Also, it looks like you might not be using `state` correctly - have a read of https://docs.pact.io/getting_started/provider_states

ramspotla
2020-04-01 04:17
Hi Tim - thank you . Initially I used term function . It pact was not able to match the hexa string.

ramspotla
2020-04-01 04:17
so now I am using hexadecimal function from Matchers

ramspotla
2020-04-01 04:17
it worked

matt.fellows
2020-04-01 04:18
The reason why I wanted to see your code and what the API actually was Ram, is that I see a potential issue

ramspotla
2020-04-01 04:19
Yes I am not using state. But I am using Jest hooks to get the data state

ramspotla
2020-04-01 04:19
I am directly connecting to db and getting the state what I wanted.

matt.fellows
2020-04-01 04:19
In the `a request to retrieve engineers list`interaction, your matcher is _only_ matching on the `id` of the _first_ item in the list that comes back. So this indicates you?re not using a `eachLike` matcher, and are instead will be matching on an array with exactly 1 item, where the `id` must be a hexadecimal string. Almost certainly, this is not what you want

ramspotla
2020-04-01 04:19
It?s all good now. Working

ramspotla
2020-04-01 04:20
I was trying all other matchers see how they work

ramspotla
2020-04-01 04:20
I tried term, like

matt.fellows
2020-04-01 04:21
@tjones what you do think about Pact JS warning in the situation where there is a matcher applied to an attribute that is within an object list (it would have to support nesting). Because 9 times out of 10, this is probably not what you want

ramspotla
2020-04-01 04:21
But term not working though pact created match regex properly

matt.fellows
2020-04-01 04:21
can you please share your code? That will help

ramspotla
2020-04-01 04:22
sure

ramspotla
2020-04-01 04:22
when I used term : term({matcher: ?^[0-9a-fA-F]+$?, generate: ?5e82a81d8ffec3918330b305?}

tjones
2020-04-01 04:23
Can you share the whole test, please?

ramspotla
2020-04-01 04:23
but pact not able to match hexa string.

ramspotla
2020-04-01 04:23
after that I tried to use hexadecimal then it?s ok

ramspotla
2020-04-01 04:23
I will Tim

ramspotla
2020-04-01 04:24
give me couple of minutes pls

ramspotla
2020-04-01 04:27
Other small issue I am encountering is

ramspotla
2020-04-01 04:27
my api sends status code 201 and also pact files also has the same status code

ramspotla
2020-04-01 04:29
But when I am trying with provider pact it?s complaining status code 200. I was wondering what could be that causing that issue

matt.fellows
2020-04-01 04:30
can you please share your code?

matt.fellows
2020-04-01 04:31
If the pact has `201` in it, and the provider does not return a `201` it will fail. So either a) your provider is not returning a `201` or there is a configuration issue somewhere

ramspotla
2020-04-01 04:32
what exactly you wann see. log file or pact file or both consumer test?

matt.fellows
2020-04-01 04:32
as much as you have will help us help you!

ramspotla
2020-04-01 04:32
```{ "consumer": { "name": "Client" }, "provider": { "name": "EngineerService" }, "interactions": [{ "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [{ "name": "Ram", "practice": "Test", "id": "5e8280694c55aa3b3263fe9a" }], "matchingRules": { "$.body[0].name": { "match": "type" }, "$.body[0].practice": { "match": "type" }, "$.body[0].id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } }, { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev", "id": "5e82a81d8ffec3918330b305" }, "matchingRules": { "$.body.name": { "match": "type" }, "$.body.practice": { "match": "type" }, "$.body.id": { "match": "regex", "regex": "^[0-9a-fA-F]+$" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

tjones
2020-04-01 04:32
Can you send the consumer test please?

ramspotla
2020-04-01 04:32
Yep

ramspotla
2020-04-01 04:33
```require('dotenv').config() const request = require('supertest') const provider = require('../expectation/provider') const interactions = require('../expectation/interactions') const serverAddress = `http://localhost:${process.env.CLIENT_PORT}` const baseUrl = '/engineers' const consumerClient = request(`${serverAddress}`) describe('api testing', () => { jest.setTimeout(60000) beforeAll(async () => { await provider.setup() }) afterAll(async () => { await provider.finalize() }) afterEach(async () => { await provider.verify() }) test('get all engineers', async () => { await provider.addInteraction(interactions.getEngineersList) const res = await consumerClient .get(`${baseUrl}`) .set('Content-Type', 'application/json; charset=utf-8') expect(JSON.parse(res.text)).toEqual([ { name: 'Ram', practice: 'Test', id: '5e8280694c55aa3b3263fe9a' } ]) }) test('post a engineer', async () => { await provider.addInteraction(interactions.createEngineer) const payload = { name: 'New Engineer', practice: 'Dev' } const res = await consumerClient .post(`${baseUrl}`) .set('Content-Type', 'application/json; charset=utf-8') .send(payload) .expect(201) expect(JSON.parse(res.text)).toEqual({ name: 'New Engineer', practice: 'Dev', id: '5e82a81d8ffec3918330b305' }) }) })```

matt.fellows
2020-04-01 04:35
is `process.env.CLIENT_PORT`pointing at the pact mock server port?

ramspotla
2020-04-01 04:38
Yes Matt

ramspotla
2020-04-01 04:38
```const opts = { consumer: 'Client', provider: 'EngineerService', port: parseInt(process.env.CLIENT_PORT), log: path.resolve(__dirname, '../../logs'), loglevel: 'ERROR', dir: path.resolve(__dirname, '../pacts'), spec: 2.0 }```

matt.fellows
2020-04-01 04:41
can you please also share the expectations file and the logs?

ramspotla
2020-04-01 04:43
I be back in 10 minutes . I got to go. Thank you Matt and Tim

matt.fellows
2020-04-01 04:44
np

ramspotla
2020-04-01 04:58
Hi

ramspotla
2020-04-01 05:00
```I, [2020-04-01T15:26:28.556393 #47039] INFO -- : Registered expected interaction GET /engineers D, [2020-04-01T15:26:28.556706 #47039] DEBUG -- : { "description": "a request to retrieve engineers list", "providerState": "engineers list", "request": { "method": "GET", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": { "json_class": "Pact::SomethingLike", "contents": "Ram" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Test" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] }, "metadata": null } I, [2020-04-01T15:26:28.563401 #47039] INFO -- : Received request GET /engineers D, [2020-04-01T15:26:28.563511 #47039] DEBUG -- : { "path": "/engineers", "query": "", "method": "get", "headers": { "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-04-01T15:26:28.563752 #47039] INFO -- : Found matching response for GET /engineers D, [2020-04-01T15:26:28.563872 #47039] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "name": { "json_class": "Pact::SomethingLike", "contents": "Ram" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Test" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e8280694c55aa3b3263fe9a", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } ] } I, [2020-04-01T15:26:28.570494 #47039] INFO -- : Verifying - interactions matched I, [2020-04-01T15:26:28.573592 #47039] INFO -- : Cleared interactions I, [2020-04-01T15:26:28.577693 #47039] INFO -- : Registered expected interaction POST /engineers D, [2020-04-01T15:26:28.577852 #47039] DEBUG -- : { "description": "a request to post a engineer", "providerState": "add a engineer", "request": { "method": "POST", "path": "/engineers", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": "New Engineer", "practice": "Dev" } }, "response": { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": { "json_class": "Pact::SomethingLike", "contents": "New Engineer" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Dev" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } }, "metadata": null } I, [2020-04-01T15:26:28.581590 #47039] INFO -- : Received request POST /engineers D, [2020-04-01T15:26:28.581708 #47039] DEBUG -- : { "path": "/engineers", "query": "", "method": "post", "body": { "name": "New Engineer", "practice": "Dev" }, "headers": { "Content-Length": "40", "Content-Type": "application/json; charset=utf-8", "Host": "localhost:5001", "Accept-Encoding": "gzip, deflate", "User-Agent": "node-superagent/3.8.3", "Connection": "close", "Version": "HTTP/1.1" } } I, [2020-04-01T15:26:28.581855 #47039] INFO -- : Found matching response for POST /engineers D, [2020-04-01T15:26:28.581967 #47039] DEBUG -- : { "status": 201, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "name": { "json_class": "Pact::SomethingLike", "contents": "New Engineer" }, "practice": { "json_class": "Pact::SomethingLike", "contents": "Dev" }, "id": { "json_class": "Pact::Term", "data": { "generate": "5e82a81d8ffec3918330b305", "matcher": { "json_class": "Regexp", "o": 0, "s": "^[0-9a-fA-F]+$" } } } } } I, [2020-04-01T15:26:28.585538 #47039] INFO -- : Verifying - interactions matched I, [2020-04-01T15:26:28.588517 #47039] INFO -- : Cleared interactions I, [2020-04-01T15:26:28.591790 #47039] INFO -- : Writing pact for EngineerService to /Users/ram/practice/pact-example/consumer-driven/consumer/pacts/client-engineerservice.json```

ramspotla
2020-04-01 05:00
see the proivder logs: sending 201

ramspotla
2020-04-01 05:00
POST /engineers 201 16.618 ms - 64

ramspotla
2020-04-01 05:03
```'use strict' const { Matchers } = require('@pact-foundation/pact') const { eachLike, like, term, hexadecimal } = Matchers const baseUrl = '/engineers' const ENGINEERS_GET_BODY = [ { name: like('Ram'), practice: like('Test'), id: hexadecimal('5e8280694c55aa3b3263fe9a') } ] const ENGINEER_POST_PAYLOAD = { name: 'New Engineer', practice: 'Dev' } const ENGINEER_RES_PAYLOAD = { name: like('New Engineer'), practice: like('Dev'), id: hexadecimal('5e82a81d8ffec3918330b305') } module.exports = { getEngineersList: { state: 'engineers list', uponReceiving: 'a request to retrieve engineers list', withRequest: { method: 'GET', path: `${baseUrl}`, headers: { 'Content-Type': 'application/json; charset=utf-8' } }, willRespondWith: { status: 200, body: ENGINEERS_GET_BODY, headers: { 'Content-Type': 'application/json; charset=utf-8' } } }, createEngineer: { state: 'add a engineer', uponReceiving: 'a request to post a engineer', withRequest: { method: 'POST', path: `${baseUrl}`, headers: { 'Content-Type': 'application/json; charset=utf-8' }, body: ENGINEER_POST_PAYLOAD }, willRespondWith: { status: 201, body: ENGINEER_RES_PAYLOAD, headers: { 'Content-Type': 'application/json; charset=utf-8' } } } }```

matt.fellows
2020-04-01 07:21
I don't see any provider logs. Is the problem with the consumer test or the provider test?

matt.fellows
2020-04-01 07:22
Can you show what the actual problem is?

cesar.lopes
2020-04-01 13:58
Hi, any way I can log the verifier requests? I?m trying to validate a POST method, but the body is not being passed on the request: the contract: ```{ "consumer": { "name": "EatFruits" }, "provider": { "name": "Fruits" }, "interactions": [ { "description": "a fruit", "providerState": "when I add a fruit", "request": { "method": "POST", "path": "/api/fruits", "headers": { "Accept": "application/json" }, "body": { "name": "Fruit_1", "price": 1.2, "calories": 120 } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "message": "New fruit created!", "data": { "_id": { "generate": "5e847e5c5ba97d17dcdb7a51", "matcher": "([0-9a-f]+)" }, "create_date": { "generate": "2020-04-01T11:43:24.950Z", "matcher": "(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2})\\:(\\d{2})\\:(\\d{2}).(\\d{3})Z" }, "name": "Fruit_1", "price": 1.2, "calories": 120, "__v": 0 } }, "matchingRules": { "$.body.data._id": { "match": "type" }, "$.body.data.create_date": { "match": "type" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

cesar.lopes
2020-04-01 14:10
wrong request header :disappointed:

cesar.lopes
2020-04-01 14:10
```headers: { 'Content-Type': 'application/json;charset=utf-8', },```

sacharya_pact
2020-04-02 05:38
has joined #pact-js

lbraymusso
2020-04-02 05:40
has joined #pact-js

ramspotla
2020-04-03 02:44
problem is : pact provider fails due to status code not matching

cesar.lopes
2020-04-03 08:10
yes @ramspotla, because I define wrong Content-type for request headers, and the request body was not passed.

safiyya
2020-04-03 14:07
has joined #pact-js

ramspotla
2020-04-05 00:10
Thank you I try that. Sorry my bad copy and paste

ramspotla
2020-04-05 00:11
error

cesar.lopes
2020-04-05 00:12
?

mcruzdrake
2020-04-05 16:30
has joined #pact-js

christopher.richard
2020-04-06 18:22
has joined #pact-js

christopher.richard
2020-04-06 18:38
Seeing something weird with an interaction I'm adding. In my logs I can see I've added the interaction: ```[2020-04-06T14:02:02.378142 #7624] INFO -- : Registered expected interaction GET /v1/users/402/memberships?cancelled=false``` But then it seems to fail when the request is made: ```[2020-04-06T14:02:02.384429 #7624] ERROR -- : No matching interaction found for GET /v1/users/402/memberships?cancelled=false``` It seems to not like the QS, but I've used the same structure for other requests: ```[2020-04-06T14:02:02.359280 #7624] INFO -- : Registered expected interaction GET /v1/users/401/memberships?expired=false [2020-04-06T14:02:02.364947 #7624] INFO -- : Found matching response for GET /v1/users/401/memberships?expired=false```

christopher.richard
2020-04-06 18:39
Can anyone see something I'm not seeing?

christopher.richard
2020-04-06 19:13
Found it. turns out `false != 'false'`

matt.fellows
2020-04-06 22:12
:smile:

matt.fellows
2020-04-06 22:12
Query strings are all _strings_ but it?s easy to forget

abubics
2020-04-06 23:27
sounds like something to add a warning for? If there are any non-strings in query defs :thinking_face:

matt.fellows
2020-04-06 23:36
Yep good idea. I'll raise an issue for it shortly

tjones
2020-04-07 00:58
We could also get the broker to provide hints when the log prints the same string twice (usually this is headers)

tjones
2020-04-07 00:59
it?s annoying to have situations that result in `you didn't request "GET /foo/bar"`, and `I expected "GET /foo/bar"`

abubics
2020-04-07 01:05
ah, very similar symptoms for other attributes . . .

christopher.richard
2020-04-07 13:02
Seems to me the `query` attr in a new interaction's `withRequest` object should validate against non-strings?

matt.fellows
2020-04-07 13:12
Yep, that?s the idea

matt.fellows
2020-04-07 13:12
It?s currently enforced by typescript, but that?s not sufficient. I?ll add

cesar.lopes
2020-04-07 14:04
hello, any way I can use a pact interaction and don?t create a contract for it?

matt.fellows
2020-04-07 21:35
Can you please elaborate on what you need Cesar?

cesar.lopes
2020-04-08 08:28
Hello Matt, I?m trying to replace all jest.mock from units tests in a project with PACT :heart_eyes_cat: We have some mock unit tests that are not applicable on provider, Ex: I get a wrong body response and a 200 status code

cesar.lopes
2020-04-08 08:29
I cannot test that against the provider, for now I just adding those contracts to a dummy file called tobe-discarded.json

cesar.lopes
2020-04-08 08:29
And I neve user that contracts for validations on provider

cesar.lopes
2020-04-08 08:30
my question is, Is any way I can use pact for mock, but dont generate those contracts?

anguyen0815
2020-04-08 22:15
has joined #pact-js

rbenbolton
2020-04-09 17:48
Hey everyone, I?m new to the pact-js side of things and trying to set up a simple login test that returns a jwt token. I?m trying to wrap the expected response matcher with term, but I?m getting a strange mismatch between Expected and Received. Here?s the test results and I?ll include my code:

rbenbolton
2020-04-09 17:49
I don?t know why it posted the code snippet three times ?

rbenbolton
2020-04-09 21:06
I?ve got it pinned down to the regex matcher. I know it?s not in the right place. Just can?t seem to figure out how it should look.

rbenbolton
2020-04-09 23:27
Well, I?ve made some progress, I think. I updated the matcher and regex, which I realized was wrong. I changed it to: ```body: { data: term({ matcher: /^[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+\.?[A-Za-z0-9_.+\/=-]*$/, generate: "eyJhbGciOiJSUzI1NiIsImtpZCI6ImQtMyIsInR5cCI6IkpXVCJ9.eyJBQ0xTIjp7IjY3MDNkZjcxLWJmODMtNDU1ZC05ZTg4LTVlNDI2ODE4M2Q5ZCI6WzIwLDIxLDMwLDQwMCw0MDEsNDAyLDQwMyw0MDQsNDA3LDQwOF19LCJleHAiOjE1ODY0NzkyMDQsImV4cEJ1ZmZlciI6MTU4NjUwODAwNCwiaWF0IjoxNTg2NDY0ODA0LCJqdGkiOiJhODE1NDY3Ni00Njk5LTRhMTgtOWUyOS1lZjI0YzUxY2QxZjMiLCJ0eXBlIjoicHJhY3RpY2UiLCJ1c2VyX2lkIjoiM2Y3OGJhNGQtZDg3Yy00MmJjLTkzMDItMTRkMzY2Mjc1MzQyIiwidXNlcm5hbWUiOiJkZXYtYXV0aC1tb25pdG9yLTU2MjI2ODQ1NTJAYXNkZi5jb20ifQ.6QjJAmmHv2vCP0mo7JjhAz1iwhMC-Xjdu9Ag0nxxx9-DBMCns-jK1cybRR0_2M5zwGTJkASU_a13-aRS3COiM4NLZcuphMWSBAARHpEBJFacgrGHOFnFFnJzZybERwaW1ftqft6gaITS6tQO_mP4I7oVRgyvIpdU-qgMmNICfixWjRD4LkHY2E4B4WZazbw77SQHrrnToE3p6D6WrSeFY3SmP3uJRGe1muMSJc4sioSdkUHXMeZjEU8wdvjznErQD1uxZoAB5FOnth20CvhgrNSWpb4KpX1KZEtNJeavQGEFVuvktBSdx5yDcbrEsbMFeK22f1RglfoVvIkdTz_yVg" }) }``` But, now I?m getting an error on `term` that says, `TypeError: matcher.replace is not a function`

komeershettyvinod
2020-04-10 05:26
has joined #pact-js

komeershettyvinod
2020-04-10 06:19
Hi

komeershettyvinod
2020-04-10 06:20
I am seeing popsicle error (unable to connect) and pact server is not running up, can any one of you please help


tjones
2020-04-10 06:21
There?s a subtlety here, for which we should probably improve the error message - the `matcher` needs to be a string that contains a Ruby regular expression, not a Javascript regex object

tjones
2020-04-10 06:28
In your other snippet, the problem (which you probably found) was that `expect(response.data).toEqual(loginResponse)` is passed the pact expectation, including the matchers - it needs to be passed the object that you expect to be returned from the API

tjones
2020-04-10 06:30
It?s hard to help with just the error - could you tell us more about the test setup. What happens when you try to start the server?

komeershettyvinod
2020-04-10 08:38
I was trying to run a basic test with angular 7 application. Below are my ```"@pact-foundation/karma-pact": "^2.2.0", "@pact-foundation/pact-node": "^10.2.1", "@pact-foundation/pact-web": "^9.5.0",``` Node version -12.

tjones
2020-04-10 09:44
Could you post the test, please?

komeershettyvinod
2020-04-10 10:46
My test -- ```import { TestBed } from '@angular/core/testing'; import { HttpClientModule } from '@angular/common/http'; import { Matchers, PactWeb } from '@pact-foundation/pact-web'; import { UserService } from '@app/main/forecast-runs/components/estimate-creation/user.service'; import { User } from '@app/main/forecast-runs/components/estimate-creation/user'; import { Pact } from '@pact-foundation/pact-web/httpPact'; describe('UserServicePact', () => { let provider; // Setup Pact mock server for this service beforeAll(async () => { provider = await new PactWeb({ consumer: 'ui-karma', provider: 'userservice', host: '127.0.0.1', port: 9008 }); // required for slower CI environments await new Promise(resolve => setTimeout(resolve, 1000)); // Required if run with `singleRun: false` await provider.removeInteractions(); }); // Configure Angular Testbed for this service beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpClientModule ], providers: [ UserService ] }); }); // Verify mock service afterEach(async () => { await provider.verify(); }); // Create contract afterAll(async () => { await provider.finalize(); }); describe('get()', () => { const userId = 1; let expectedUser: User = { firstName: 'Zaphod', lastName: 'Beeblebrox' }; beforeAll(async () => { await provider.addInteraction({ state: `user 1 exists`, uponReceiving: 'a request to GET a user', withRequest: { method: 'GET', path: `/api/users/${userId}` }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedUser) } }); }); it('should get a user', async () => { const userService: UserService = TestBed.get(UserService); await userService.get(userId).toPromise().then(response => { expect(response).toEqual(expectedUser); }); }); }); describe('create()', () => { const expectedUser: User = { firstName: 'Arthur', lastName: 'Dent' }; const createdUserId = 42; beforeAll(async () => { await provider.addInteraction({ state: `provider accepts a new user`, uponReceiving: 'a request to POST a user', withRequest: { method: 'POST', path: '/api/users', body: expectedUser, headers: { 'Content-Type': 'application/json' } }, willRespondWith: { status: 201, body: Matchers.somethingLike({ id: createdUserId }), headers: { 'Content-Type': 'application/json' } } }); }); it('should create a user', async () => { const userService: UserService = TestBed.get(UserService); await userService.create(expectedUser).toPromise().then(response => { expect(response).toEqual(createdUserId); }); }); }); describe('update()', () => { let expectedUser: User = { firstName: 'Zaphod', lastName: 'Beeblebrox' }; beforeAll(async () => { await provider.addInteraction({ state: `user 42 exists`, uponReceiving: 'a request to PUT a user', withRequest: { method: 'PUT', path: '/api/users/42', headers: {'Content-Type': 'application/json'}, body: Matchers.somethingLike(expectedUser) }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedUser) } }); }); it('should update a user', async () => { const userService: UserService = TestBed.get(UserService); await userService.update(expectedUser, 42).toPromise().then(response => { expect(response).toEqual(expectedUser); }); }); }); });```

komeershettyvinod
2020-04-10 10:51
// Karma configuration file, see link for more information // https://karma-runner.github.io/1.0/config/configuration-file.html path = require('path'); module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ require('karma-jasmine'), require('@pact-foundation/karma-pact'), require('karma-chrome-launcher'), require('karma-firefox-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), require('@angular-devkit/build-angular/plugins/karma'), ], client: { clearContext: false, // leave Jasmine Spec Runner output visible in browser jasmine: { timeoutInterval: 40000 } }, coverageIstanbulReporter: { // dir: require('path').join(__dirname, '../coverage'), reports: ['html', 'lcovonly', 'text-summary'], fixWebpackSourcePaths: true, }, reporters: ['progress', 'kjhtml'], port: 9886, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, pact: [ { cors: true, spec: 3, port: 9008, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), '../../pacts') } ], proxies: { '/api': 'http://localhost:9008/api' } }); };

matt.fellows
2020-04-10 11:42
Thanks for that.

matt.fellows
2020-04-10 11:42
Where did you get `spec: 3` from? Not that I think it will break anything, but it?s not a valid spec version

matt.fellows
2020-04-10 11:43
Does the mock server startup?

matt.fellows
2020-04-10 11:43
can you confirm there is nothing already running on port `9008`?

komeershettyvinod
2020-04-10 13:40
regarding spec 3: I just pasted from the internet

komeershettyvinod
2020-04-10 13:40
and karma is being started but pact did not started up

komeershettyvinod
2020-04-10 13:41
no port 9008 is free

rbenbolton
2020-04-10 14:47
Yes, I realized I had the matchers malformed and removed them from the response as well as in the mock request. However, I?ve had a hard time getting the regex correct. I wonder if there couldn?t be a better example in the https://github.com/pact-foundation/pact-js#match-by-regular-expression of what this should look like? It does say, `The underlying mock service is written in Ruby, so the regular expression must be in a Ruby format, not a Javascript format.` But the example shown is simply this: ```gender: term({ matcher: "F|M", generate: "F", }),``` For the expression I?m trying to match - `/^[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+\.?[A-Za-z0-9_.+\/=-]*$/` , which works on https://rubular.com/, even putting this in quotes still throws an error. Should I provide the leading and trailing `/` as I would in ruby or is that replaced by the quotes? From the error messages, it seems they are required, though they are missing from the README example.

rbenbolton
2020-04-10 16:43
With quotes around it, it seems I need to also provide the escape `\`. After doing that, I?m still getting this error: `Example 'eyJhbGciOiJSUzI1NiIsImtpZ ...' does not match provided regular expression '/^[A-Za-z0-9_=-]+\.[A-Za-z0-9_=-]+\.?[A-Za-z0-9_.+\/=-]*$/'`. I?ve double-checked the regex with that string on http://rubular.com as well as in ruby code locally. Both say it?s a match. I?m really at a loss here as to why this would be failing.

matt.fellows
2020-04-10 21:40
Any logs suggesting why?

matt.fellows
2020-04-10 21:41
> regarding spec 3: I just pasted from the internet where? It is incorrect and must be fixed



komeershettyvinod
2020-04-12 08:03
However even If i comment out that spec line the result is the same

matt.fellows
2020-04-12 10:13
What does the log file say? Can you please post the terminal output? The pact plugin must not be starting correctly

komeershettyvinod
2020-04-12 11:45
Hi Matt

komeershettyvinod
2020-04-12 11:45
I have attached the log file in the above snippet , can you please revie

komeershettyvinod
2020-04-12 11:45
w

matt.fellows
2020-04-13 13:48
Can you please set the log level to DEBUG in karma

matt.fellows
2020-04-13 13:48
``` // Pact Providers pact: [ { port: 1234, consumer: "KarmaJasmineConsumer", provider: "KarmaJasmineProvider", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }, ],```

matt.fellows
2020-04-13 13:48
e.g. as per above

matt.fellows
2020-04-13 13:48
and then provide the logs?

matt.fellows
2020-04-13 13:49
you should be seeing something like this in the logs

matt.fellows
2020-04-13 13:52
Does anybody here use Nock to test their HTTP clients? If so, do you still use that with Pact or did you replace them?

matt.fellows
2020-04-13 13:52
Would it be useful at all to have a Pact integration with nock?

komeershettyvinod
2020-04-13 14:30
console log

rbenbolton
2020-04-13 14:45
@tjones @matt.fellows Any ideas here?

tjones
2020-04-13 15:32
I think the problem is possibly the slashes at either end of the string- try just providing the regex, from `^` to `@`

tjones
2020-04-13 15:32
(Sorry I missed this before)

rbenbolton
2020-04-13 15:38
Ok, so I removed the slashes, and it works if the token provided in the `willRespondWith` is exactly the same as the token returned by the mock provider. However, if I set those to two different tokens, but they both match the regular expression, the test fails. I would expect to be able to provide two different values here and have the test pass as long as they both match the regular expression. Is that not the case? If not, how do I know then that the regex is working?

matt.fellows
2020-04-13 20:55
Might need some help from @bethskurrie on this one. I recall there being a few peculiarities with the regexing on Ruby.

matt.fellows
2020-04-13 20:55
Ideally, if you could repro it at https://github.com/pact-foundation/pact-ruby-standalone-e2e-example/, that would be really helpful

aaron590
2020-04-14 05:57
has joined #pact-js

aaron590
2020-04-14 06:01
Hello, I'm working on setting up pact-js in my CI Pipeline. I'm getting an error that rake cannot be found and cat Gemfile.lock is not present when I run `jest --testPathPattern .*\.pact\.spec\.js --runInBand --setupFiles ./pact/pactSetup.js --setupTestFrameworkScriptFile=./pact/pactTestWrapper.js` Everything works locally. Any help would be appreciated. It's in CircleCI. It appears that pact-js depends on pact-node, which relies on some ruby gems.

matt.fellows
2020-04-14 07:11
Hi

matt.fellows
2020-04-14 07:11
So basically, we bundle a traveling Ruby installation in Pact Node with a Ruby app that does a lot of the hard work under the hood

matt.fellows
2020-04-14 07:12
It should be all but hidden from you, however it?s revealing itself to you now - sorry!

matt.fellows
2020-04-14 07:12
I have seen this before, I think

matt.fellows
2020-04-14 07:12
It?s when it?s running in an environment where there are Ruby environment variables already present

matt.fellows
2020-04-14 07:12
e.g. `BUNDLE_APP_CONFIG` . I think if you unset them, it may help, but let me find any related issues

matt.fellows
2020-04-14 07:33
OK was just able to repro the issue locally when that env var is set

matt.fellows
2020-04-14 07:35
found this old issue too

matt.fellows
2020-04-14 07:43
Have just raised a PR to fix this in the standalone library, which would fix it for you. In the meantime, explicitly _unset_ that environment variable in your build, and you should be golden. Apologies. https://github.com/pact-foundation/pact-ruby-standalone/pull/50

aaron590
2020-04-14 14:17
Thanks for the quick reply. `unset BUNDLE_APP_CONFIG && yarn pact:test` solved it. Thank you

matt.fellows
2020-04-14 21:22
:+1:

matt.fellows
2020-04-14 21:22
It will be fixed in the library in the next day or so. Thanks for bringing it to my attention. To be honest, I'm surprised it hasn't shown up before given the popularity of circle!

aaron590
2020-04-14 21:26
I?m assuming most people would choose a node environment for their ui container. Currently my project is small enough that i have my rails back end and react front end in the same repo. That means I?m using a ruby & node container.

matt.fellows
2020-04-14 21:34
ahh, yes, makes sense then

mcruzdrake
2020-04-15 16:12
Hi all, we are using Pact-js and the pact-broker for one of our projects and I am trying to visualize what our CI pipeline would be. Can someone point me to the right direction on how I can use the Pact webhooks to trigger the provider tests when a contract has been published from the consumer? We are using CircleCI. Thanks in advance!

david.tran
2020-04-15 16:27
has joined #pact-js

christopher.richard
2020-04-15 17:25
Hi Marie! not sure if this helps but I found this example useful: https://github.com/pact-foundation/pact_broker/wiki/Webhooks#example-cicd-and-webhook-configuration

matt.fellows
2020-04-15 23:22
That?s the doc Chris, albeit they?ve now moved to https://docs.pact.io/pact_broker/advanced_topics/webhooks

matt.fellows
2020-04-15 23:22
I?ll follow up that, because the old wiki should have been deprecated

akkoubak
2020-04-16 00:33
has joined #pact-js

akkoubak
2020-04-16 00:38
Hello, I am attempting to validate a contract that contains 22 interactions. The provider is run with JEST using the standalone provider. The issue is that the provider times out during execution returning a `Timeout waiting for verification process to complete (PID: 6428)` `at Timeout._onTimeout (node_modules/q/q.js:1846:21).`

matt.fellows
2020-04-16 00:40
Have you tried increasing the test timeout in Jest?

akkoubak
2020-04-16 00:45
Hi Matt, yes I did. I increased by modifying the jest setup file (jest.setTimeout(300000)). I also verified that that JEST is respecting the timeout defined by changing the timeout. Here is my provider test `/* eslint-env jest */` `const { Verifier } = require('@pact-foundation/pact')` `const client = require('../token/getToken')` `require('../../src/index.js')` `describe('Pact Verification', () => {`   `it('validates the expectations of Matching Service', () => {`     `afterEach(() => {`       `process.exit()`     `})`     `const opts = {`       `provider: 'ApolloGateway',`       `logLevel: 'DEBUG',`       `providerBaseUrl: 'http://localhost:4000',`       `requestFilter: async (req, res, next) => {`         `console.log(`           `'Middleware invoked before provider API - injecting Authorization token'`         `)`         `// req.headers["MY_SPECIAL_HEADER"] = "my special value"`         `// e.g. ADD Bearer token`         `const generatedJWT = await client.getJWT()`         `req.headers.authorization = `Bearer ${generatedJWT}``         `next()`       `},`       `// Enables "pending pacts" feature`       `enablePending: true,`       `// Specific Remote pacts (doesn't need to be a broker)`       `pactUrls: ['https://mybroker'],`       `// If you're NOT using Pactflow, use the username/password option as per below`       `// pactBrokerUsername: "",`       `// pactBrokerPassword: "",`       `pactBrokerToken: '',`       `publishVerificationResult: true,`       `providerVersion: '1.0.0'`     `}`     `return new Verifier(opts).verifyProvider().then(output => {`       `console.log('Pact Verification Complete!')`       `console.log(output)`       `process.exit()`     `})`   `})` `})` and here is my failure on the provider side

akkoubak
2020-04-16 00:49
BTW, the provider seems to timeout at 30 seconds


matt.fellows
2020-04-16 00:59
It defaults to `30000` (30s)

akkoubak
2020-04-16 01:02
Worked like magic. Thanks Matt!!

matt.fellows
2020-04-16 01:02
:thumbsup:

matt.fellows
2020-04-16 01:02
awesome

yka
2020-04-16 07:01
has joined #pact-js

yka
2020-04-16 07:07
Hi, Is there anyone who can assist finalising PactJS implementation on Angular? I got multiple micro-service instances to write pacts for and I can't work out how to do this without passing consumer to PactWeb rather than just defining multiple pacts in my karma config. So far the way I have done this is by having multiple pact declarations in karma conf to start the mock servers each having different ports of course, then I defined proxies for my endpoints to point to the corresponding pact port, and finally declaring an empty PactWeb provider in my pact test. This worked fine for one microservice, however, when I implemented the next microservice I cannot do an empty PactWeb provider declaration in pact test. Have I gone off track of how it should be implemented?

matt.fellows
2020-04-16 07:09
:wave:

matt.fellows
2020-04-16 07:09
so my first question - can you do this without Karma/Jasmine? Because that?s the source of much pain (e.g. can you use a Node JS framework)

matt.fellows
2020-04-16 07:10
my next question - can you just specify the `port` in the different `PactWeb` instances? That should pass through to the correct back end mock

yka
2020-04-16 07:14
Offf, just be aware that I am just switching from Java so my knowledge is bit iffy... To answer your question - we probably can(?), this is a greenfield project at an early stage so got lots of flexibility - would you say ditching this karma setup would be best then? Type safety doesn't allow not defining PactOptions without consumer and provider. My concern really comes from the planned deprecation of this. It is 3 extra lines of code so not too much skin off our backs.

matt.fellows
2020-04-16 07:14
ah, fair enough

matt.fellows
2020-04-16 07:15
Look, personally, I prefer to avoid Karma because it runs in the browser - you shouldn?t be testing anything that has a dependency on a browser (except at a low level, the XMLHttpRequest that makes the actual http calls - but Ng abstracts that anyway, I think [confirm with an ng expert])

matt.fellows
2020-04-16 07:16
All you should be testing in your Pact tests, is the client/collaborators that make the HTTP calls - this is a different concern to the UI components, which probably need a browser

matt.fellows
2020-04-16 07:17
But, I understand the TS options. We?ll remove the fields in the next major release. Perhaps I should just make that change now, and avoid your pain?

yka
2020-04-16 07:21
Thanks Matt, that does clear things up. I just started looking into testing yesterday so all new to me on that front. Are you aware of any testing frameworks that I should go for - just a name drop will do to start me off on my search :) If it is not too much trouble adding those two question marks then that would be very helpful :slightly_smiling_face:

matt.fellows
2020-04-16 07:34
Common test fameworks in JS land: Jest, Mocha, Ava. I?d stick with Jest/mocha, because they are the most common. But I?ll caveat that with Angular may have different preferences, and you may want to align where possible to reduce friction for developers on the team

matt.fellows
2020-04-16 07:36
Looking at the docs (https://angular.io/guide/testing) probably sticking within Jasmine/Karma is the way to go. See PR above, i?ll get that in tomorrow (ideally) and a new release out

yka
2020-04-16 07:37
Thank you Matt, you've been most helpful and not even mentioning how quick!

matt.fellows
2020-04-16 07:40
You?re welcome

matt.fellows
2020-04-16 07:51
@tjones FYI context for #432

tjones
2020-04-16 07:57
Awesome, thanks! I used the merge button to indicate my positive review

matt.fellows
2020-04-16 07:57
this works!

matt.fellows
2020-04-16 07:58
`v9.9.4` is on the way?

tjones
2020-04-16 07:58
@yka I?ve been thinking about writing a blog post or documentation article to illustrate how pact works best with UI frameworks in JS - would this be something you would have found useful?

tjones
2020-04-16 07:58
#teamwork!

yka
2020-04-16 08:22
Hi @tjones, Yeah I think that would've been helpful. It did take me some time to wrap my head around things and collate the information I needed. Also many resources I came across were old so it obviously made me question their integrity.

mcruzdrake
2020-04-16 08:37
Thanks both. Will use this as reference

tjones
2020-04-16 08:54
Thanks, this is very helpful! If you have the time, would you mind linking me to the old docs you found questionable? Maybe we can update or move them to increase confidence

yka
2020-04-16 09:02
Hi Matt, I've started looking into this and I am being a bit dim here. I am looking at the diff now and getting a bit confused as to how to implement this. :grimacing:

yka
2020-04-16 09:05
Previously i used the constructor and that uses a PactOptions interface.

matt.fellows
2020-04-16 09:25
The net result should be the exact same interface, but those two options are now gone completely (I couldn't use the same type because it shares the types with the main pact interface)

yka
2020-04-16 13:10
I wish that would be possible, I went through various resources yesterday spent a whole day through trial and error so it is very hard to think or find in my history anything in particular. Also some of the material I was referring to were outside of the foundation's resources. Sorry I could not give you an exact answer :disappointed:

joao.salles
2020-04-17 09:37
has joined #pact-js

safiyya
2020-04-17 13:31
I?m trying to verify a async contract published on Pactflow and following the instructions here https://github.com/pact-foundation/pact-js#provider-producer. I dont seem to be able to add a `pactBrokerToken` prop to the `MessageProviderPact` and my calls to our pactflow address all come back as 401. Is there another way to use Pactflow in async testing? I couldnt find anything online related to my use case

matt.fellows
2020-04-17 13:47
Would you mind filing a bug please? May be a typing issue

safiyya
2020-04-17 14:56
Sure, will do

darshan
2020-04-20 16:34
has joined #pact-js

yka
2020-04-22 13:30
Hi, Got an angular project here using karma as test framework. Is there any way around proxying each request? If I remove proxy and use the service call to full url (+correct port for pact) my pact json generates but my test fails.

james.salamon
2020-04-22 13:40
has joined #pact-js

yka
2020-04-22 15:26
Nevermind, I was being a bit dim in how I set up my proxies :grimacing:

corey
2020-04-23 15:17
has joined #pact-js

yosevuk
2020-04-23 19:55
Hello, I'm having trouble trying to address this error in a consumer contract test and I think I have a knowledge gap. How come the second query param isn't recognized? Can anyone help? Error: `Actual interactions do not match expected interactions for mock MockService.` Interaction: ```const page = { withRequest: { method: 'GET', path: '/path/page/xx', query: 'param1=param1_Value&requestType=page', headers: { apiKey: '123', }, }, willRespondWith: { status: 200, headers: headerExpectations, body: pageExpectations, }, };``` Log: ```No matching interaction found for GET /path/page/xx?param1=param1_Value Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "query": { - "requestType": [ - "page", - ] } } Description of differences -------------------------------------- * Could not find key "requestType" (keys present are: param1) at $.query ```

yosevuk
2020-04-23 20:01
Please disregard, it was just an error due to a local environment variable when I ran the tests :blush:

shurik
2020-04-24 14:17
has joined #pact-js

shurik
2020-04-24 14:42
Do you guys know any good example of open-source React or Angular projects which are using all power of pacts to enforce API provider?

matt.fellows
2020-04-25 01:13
Are you just looking for examples or case studies? There are lots of articles out there on both topics

shurik
2020-04-27 17:15
I was looking for some examples in real life projects. Want to know who is using it.

matt.fellows
2020-04-27 21:26
I'll try to update our media links. There's so many we kind of stopped.

shurik
2020-04-28 16:42
ok I'll be waiting, thanks in advance

stephen.rhodes
2020-04-29 18:21
has joined #pact-js

leonardo.k.magalhaes
2020-04-29 21:33
has joined #pact-js

brendan.j.donegan
2020-04-29 21:40
has joined #pact-js

baquinteros
2020-04-30 01:06
has joined #pact-js

baquinteros
2020-04-30 01:13
Hi guys, I'd like to add the cors flag in PactOptions for the jest-pact project. I've raised an issue. https://github.com/pact-foundation/jest-pact/issues/187 I've added it locally and it works.

matt.fellows
2020-04-30 01:25
Thanks for raising, Ben. I?ve just responded with my thoughts

dan.h.lee329
2020-05-02 01:54
has joined #pact-js

sen.rudrappa
2020-05-02 06:52
has joined #pact-js

krishnam.misc
2020-05-04 07:40
has joined #pact-js

krishnam.misc
2020-05-04 07:42
I see below warning when the default tests are run in fresh clone version for _jest_ tests WARN: Ignoring unsupported matching rules {"min"=>1} for path $['query']['catId'][] [2020-05-04T07:36:54.060Z] ERROR: pact-node@9.0.7/22480 on LTIN114925:     Pact Binary Error:     WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['query']['catId'][][*]* [2020-05-04T07:36:54.063Z]  INFO: pact@9.2.1/22480 on LTIN114925: Pact File Written [2020-05-04T07:36:54.064Z]  INFO: pact-node@9.0.7/22480 on LTIN114925: Removing Pact with PID: 7004  PASS  __tests__/index.spec.js (5.023s) Test Suites: 3 passed, 3 total Tests:       4 passed, 4 total Snapshots:   0 total

tjones
2020-05-04 07:43
I noticed this yesterday when updating the tests - I think the warning is indicating a bug (without any negative impact) in using matchers in query strings

krishnam.misc
2020-05-04 07:43
Okay, thanks for the update


krishnam.misc
2020-05-04 07:44
ERROR: The process "23412" not found. [2020-05-04T04:55:16.578Z] ERROR: pact-node@9.0.7/12924 on LTIN114925:     Pact Binary Error: C:/ComCast/TestCafe/ContractTesting/pact-js-master/pact-js-master/examples/jest/node_modules/@pact-foundation/pact-node/standalone/win32-1.70.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.1.1/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': cannot load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError) This occurs when the end user is running his tests from a workspace that has lengthy breadcrumb

krishnam.misc
2020-05-04 07:45
When I was asked to move to shorter folder name, it works. We may also need to fix this?

tjones
2020-05-04 07:45
This is a limitation of the windows operating system.

krishnam.misc
2020-05-04 07:47
Alright. Does it call for some documentation somewhere so people know why this occurs and is not a defect


abubics
2020-05-04 07:48
We might be able to give a nicer error . . . like, if the file open fails, and we know we're in Windows, and the path is long . . .

tjones
2020-05-04 07:48
You?re right, though - it should be clearer in the pact-js docs, since those are the ones we?re hoping people read

krishnam.misc
2020-05-04 07:48
:slightly_smiling_face:

krishnam.misc
2020-05-04 07:49
I just started with pact an hour ago and I already feel that this is one of the most active and helpful forums in the recent times

tjones
2020-05-04 07:49
It?s actually an interaction between Ruby and Windows, which we hit because Javascript Pact uses the Ruby implementation under the covers

krishnam.misc
2020-05-04 07:49
the other one was Concourse CI

tjones
2020-05-04 07:50
https://bugs.ruby-lang.org/issues/12551 ^ I think this is the bug, but it?s low priority for them

abubics
2020-05-04 07:50
Ah right, so maybe hard for us to catch properly

tjones
2020-05-04 07:50
We?re planning to move to a Rust implementation, which should avoid this class of problems

tjones
2020-05-04 07:51
try pact-js at version `10.0.0-beta.3` if you?re interested to try it

krishnam.misc
2020-05-04 07:52
Sure, thanks for the info. For now, I am evaluating pact and I shall migrate once we finalize

tjones
2020-05-04 07:52
Thank you! That?s really good to hear. It?s really useful hearing feedback too - I?d really like to improve the onboarding for new users. Windows feedback is especially helpful, since none of the core devs even own windows machines

tjones
2020-05-04 07:52
Cool. If you?re evaluating pact for Jest, definitely check out the branch I listed above

tjones
2020-05-04 07:53
actually, I?ll just merge it in.


krishnam.misc
2020-05-04 07:53
I am on this right now.

krishnam.misc
2020-05-04 07:54
Sorry, Did I miss out a detail?

tjones
2020-05-04 07:55
I linked you to a pull request that cleans up the Jest example a bit

tjones
2020-05-04 07:55
but, I figured it was more helpful to merge it. If you do a pull you?ll get a much more streamlined example.

tjones
2020-05-04 07:56
I?m going to spend some time this week updating the examples so they have a common and more realistic client to test

krishnam.misc
2020-05-04 07:57
That was quick :slightly_smiling_face:

tjones
2020-05-04 07:59
I was updating it yesterday :slightly_smiling_face:

tjones
2020-05-04 08:00
I?m probably going to update the `jest-pact` DSL too, to add helpers that make it harder to use wrong. Any feedback would be welcome

tjones
2020-05-04 08:01
Specifically, at the moment, you have to do: ```beforeEach(() => provider.addInteraction({ /* your test setup */}) );```

tjones
2020-05-04 08:01
but it is easy to write that as: ```beforeEach(() => { provider.addInteraction({ /* your test setup */}) });``` (subtle - this version doesn?t return the result of `addInteraction`, which is a promise that you need to wait for)

tjones
2020-05-04 08:02
I?m thinking about adding something like: ```pactInteraction(provider, {/* your test setup */})``` which does the `beforeEach` for you

tjones
2020-05-04 08:03
Anyway, let us know how you go. Even if you end up not going with Pact, hearing about why, and what pain points you had is useful to us.

matt.fellows
2020-05-04 08:29
We have code that detects and warns about it in Pact node, but it can get missed/ignored/squashed

matt.fellows
2020-05-04 08:30
Were not far away from removing Ruby too, which will kill this bug once and for all

krishnam.misc
2020-05-04 11:51
Can someone help me with steps to debug a pact? I must admit that am a newbie here today

matt.fellows
2020-05-05 00:02
What?s the issue you?re having @krishnam.misc? Perhaps start with your problem / needs and we can help. There are some troubleshooting tips in the guide, the rest is standard JS debugging

tjones
2020-05-05 05:24
We get a lot of issues opened where people have forgotten to return the promises to their test framwork. For jest-pact, I?m considering adding a couple of helpers that enforce / assert that promises are returned correctly.

tjones
2020-05-05 05:25
At the moment, a test looks like this: ```beforeEach(() => { return provider.addInteraction({ ...etc, }) }) it("returns a sucessful body", () => { return getMeCats({ url: provider.mockService.baseUrl, }).then(cats => { expect(cats).toEqual(CATS_DATA) }) })```

tjones
2020-05-05 05:27
what do people think of: ```pactInteraction(provider, { ...etc, }) triggerInteraction(() => { return getMeCats({ url: provider.mockService.baseUrl, }).then(cats => { expect(cats).toEqual(CATS_DATA) }) })``` ? (possibly interested: @yousafn, @matt.fellows, @abubics and others)

tjones
2020-05-05 05:28
maybe `testInteraction` rather than `trigger`?

matt.fellows
2020-05-05 05:30
I say this running into a meeting, but _what if_ you overrode the `it` itself, such that the it block had to accept a promise. Then you could just call it `testInteraction` or something and the rest of the code coueld say the same? Or is that what `triggerInteraction` is doing?

abubics
2020-05-05 05:37
I like the concept, but I'm in a very different context atm, so it's hard to switch and say if I'd like to use it :)

tjones
2020-05-05 05:37
Yep, that?s essentially it :slightly_smiling_face:

tjones
2020-05-05 05:39
Or should I say, essentially `it`

tjones
2020-05-05 05:41
```export const pactInteraction = ( provider: pact.Pact, interaction: pact.Interaction | pact.InteractionObject, ) => { beforeEach(() => provider.addInteraction(interaction)); };```

tjones
2020-05-05 05:41
I wish jest had context

tjones
2020-05-05 05:41
then we wouldn?t have to pass in interaction

tjones
2020-05-05 05:42
I also considered having jest-pact override `provider.addInteraction`, but I think that would add confusion for other test frameworks

gunjan.arora
2020-05-05 22:31
has joined #pact-js

krishnam.misc
2020-05-06 12:08
@tjones Could you please help me with below error

krishnam.misc
2020-05-06 12:08
console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99      Actual interactions do not match expected interactions for mock MockService.  Missing requests:        GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea

krishnam.misc
2020-05-06 12:15
My test code is as simple as this: "use strict" const getMeEmail = require("../index").getMeEmail describe("Verify GET Email Contract", () => {   let url = "http://localhost"   const EXPECTED_BODY =      {     "firstName": "Krisham",     "lastName": "Raju",     "email": "",     "lastSent": "2020-05-06T09:43:13.097695",     "inviteId": "e1e06f41-0d48-4a50-899d-e9c5cef56bea",     "status": "EXPIRED",     "roles": [         "UNRESTRICTED_SECONDARY"     ],     "accountNumber": "8069100010141843" }      afterEach(() => {     return provider.verify()   })   describe("works", () => {     beforeEach(() => {       const interaction = {         state: "I have a list of invite emails",         uponReceiving: "a request for a primary user email details",         withRequest: {           method: "GET",           path: "/identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea",           headers: {             Accept: "application/json",           },         },         willRespondWith: {           status: 200,           headers: {             "Content-Type": "application/json",           },           body: EXPECTED_BODY,         },       }       return provider.addInteraction(interaction)     })     // add expectations     it("returns a sucessful body", () => {       return getMeEmail({         url,         port,       }).then(response => {                expect(response.headers["content-type"]).toEqual("application/json")         expect(response.data).toEqual(EXPECTED_BODY)                 expect(response.status).toEqual(200)       })     })   })    })

krishnam.misc
2020-05-06 12:18
The error message is a little ambiguous and I am confused as to what went wrong here. I verified that mockResponse == index.getMeEmail() response

krishnam.misc
2020-05-06 12:19
++ @abubics, @matt.fellows

yousafn
2020-05-06 14:49
Hey, just a friendly note, could you wrap your code in a code block? You can press backtick (`) three times and the code block will appear. You can paste your code in there. It will make it far easier for those reading your code, and make it much easier to help :thumbsup:

yousafn
2020-05-06 15:23
have you got the code for `require("../index").getMeEmail` When you call, you are only passing in a url and port. ``` return getMeEmail({ url, port,``` You?ve setup an interaction, but what is calling `/identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` is that in your getMeEmail function?

tjones
2020-05-06 17:55
@krishnam.misc Have a look in the log files generated by the test. It usually has more about what didn?t match in there.

tjones
2020-05-06 18:00
The error message is telling you that Pact didn?t receive the interaction it expected.

matt.fellows
2020-05-06 23:23
I think Yousaf is right. Your code is not hitting the correct endpoint. Also, and I can?t recall off the top of my head, but you should use the `query` property for the `invite` parameter, it is not technically part of the path (albeit it may still work).

matt.fellows
2020-05-06 23:24
As Tim points out, the log file will probably tell you it got a request that it wasn?t expecting (so that will tell you what your code is actually doing)

krishnam.misc
2020-05-07 04:10
1. Yes, I have the implementation for `require("../index").getMeEmail` `exports.getMeEmail = endpoint => {`   const url = 'https://myapp.url.com'  let token = 'bearer token"   return axios.request({     method: "GET",     baseURL: `${url}`,     url: "/identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea",     headers: { Accept: "application/json",'Authorization': 'Bearer ' + token },   }) 2. The service we are triggering does not need a port.

krishnam.misc
2020-05-07 04:11
@yousafn and @matt.fellows

matt.fellows
2020-05-07 04:11
what do the logs say?

matt.fellows
2020-05-07 04:12
Also, use the `query` property for the query strings, rather than in the path


krishnam.misc
2020-05-07 04:16
getMeEmail response looks like below - which is same as that I put in EXPECTED BODY: {     "firstName": "Krisham",     "lastName": "Raju",     "email": "",     "lastSent": "2020-05-07T04:12:31.531225",     "inviteId": "82cd6f49-b680-4e53-a5ba-4b41890cc531",     "status": "EXPIRED",     "roles": [         "UNRESTRICTED_SECONDARY"     ],     "accountNumber": "8069100010141843" } Here is the detailed log: C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\__tests__> npm run test > pact-example-jest@1.0.0 test C:\ContractTesting\pact-js-master\pact-js-master\examples\jest > jest __tests__/ --runInBand --setupFiles ./pactSetup.js --setupTestFrameworkScriptFile=./pactTestWrapper.js [2020-05-07T04:14:27.812Z] INFO: pact-node@9.0.7/20364 on LTIN114925: Creating Pact Server with options: {"consumer":"MyConsumer-EmailInvite","cors":false,"dir":"C:\\ContractTesting\\pact-js-master\\pact-js-master\\examples\\jest\\pacts","host":"127.0.0.1","log":"C:\\ContractTesting\\pact-js-master\\pact-js-master\\examples\\jest\\logs\\mockserver-integration.log","pactFileWriteMode":"update","port":8991,"provider":"MyProvider-EmailInvite","spec":2,"ssl":false} [2020-05-07T04:14:29.518Z] INFO: pact-node@9.0.7/20364 on LTIN114925: Created 'standalone\win32-1.70.2\bin\pact-mock-service.bat service --consumer 'MyConsumer-EmailInvite' --pact_dir 'C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\pacts' --host '127.0.0.1' --log 'C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\logs\mockserver-integration.log' --pact-file-write-mode 'update' --port '8991' --provider 'MyProvider-EmailInvite' --pact_specification_version '2'' process with PID: 13872 [2020-05-07T04:14:34.059Z] INFO: pact@9.2.1/20364 on LTIN114925: Setting up Pact with Consumer "MyConsumer-EmailInvite" and Provider "MyProvider-EmailInvite" using mock service on Port: "8991" console.error node_modules/@pact-foundation/pact/httpPact.js:97 console.error node_modules/@pact-foundation/pact/httpPact.js:98 Pact verification failed! console.error node_modules/@pact-foundation/pact/httpPact.js:99 Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea See C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/logs/mockserver-integration.log for details. [2020-05-07T04:14:36.259Z] ERROR: pact-node@9.0.7/20364 on LTIN114925: Pact Binary Error: Could not load existing consumer contract from C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/pacts/myconsumer-emailinvite-myprovider-emailinvite.json due to 757: unexpected token at 'null'. Creating a new file. [2020-05-07T04:14:36.259Z] ERROR: pact-node@9.0.7/20364 on LTIN114925: Pact Binary Error: [2020-05-07T04:14:36.261Z] INFO: pact@9.2.1/20364 on LTIN114925: Pact File Written [2020-05-07T04:14:36.261Z] INFO: pact-node@9.0.7/20364 on LTIN114925: Removing Pact with PID: 13872 FAIL __tests__/inviteEmaiContractTest.js (9.915s) Verify GET Email Contract works × returns a sucessful body (2182ms) ? Verify GET Email Contract ? works ? returns a sucessful body Request failed with status code 404 at createError (node_modules/axios/lib/core/createError.js:16:15) ? Verify GET Email Contract ? works ? returns a sucessful body Pact verification failed - expected interactions did not match actual. at new VerificationError (node_modules/@pact-foundation/pact/errors/verificationError.js:19:42) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total

krishnam.misc
2020-05-07 04:26
mock server response looks like below: `I, [2020-05-07T09:51:17.374485 #19584]  INFO -- : Registered expected interaction GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` `D, [2020-05-07T09:51:17.374485 #19584] DEBUG -- : {`   `"description": "a request for a primary user email details",`   `"providerState": "I have a list of invite emails",`   `"request": {`     `"method": "GET",`     `"path": "/identity/invite",`     `"query": {`       `"inviteId": [`         `"e1e06f41-0d48-4a50-899d-e9c5cef56bea"`       `]`     `},`     `"headers": {`       `"Accept": "application/json"`     `}`   `},`   `"response": {`     `"status": 200,`     `"headers": {`       `"Content-Type": "application/json"`     `},`     `"body": {`       `"firstName": "Krisham",`       `"lastName": "Raju",`       `"email": "",`       `"lastSent": "2020-05-06T09:43:13.097695",`       `"inviteId": "e1e06f41-0d48-4a50-899d-e9c5cef56bea",`       `"status": "EXPIRED",`       `"roles": [`         `"UNRESTRICTED_SECONDARY"`       `],`       `"accountNumber": "8069100010141843"`     `}`   `}` `}` `W, [2020-05-07T09:51:19.780783 #19584]  WARN -- : Verifying - actual interactions do not match expected interactions.`  `Missing requests:`   `GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` `W, [2020-05-07T09:51:19.780783 #19584]  WARN -- : Missing requests:`   `GET /identity/invite?inviteId=e1e06f41-0d48-4a50-899d-e9c5cef56bea` I, [2020-05-07T09:51:19.802723 #19584]  INFO -- : Cleared interactions W, [2020-05-07T09:51:19.832643 #19584]  WARN -- : Could not load existing consumer contract from C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/pacts/myconsumer-emailinvite-myprovider-emailinvite.json due to 757: unexpected token at 'null'. Creating a new file. E, [2020-05-07T09:51:19.832643 #19584] *ERROR* -- : 757: unexpected token at 'null' (JSON::ParserError) C:/ContractTesting/pact-js-master/pact-js-master/examples/jest/node_modules/@pact-foundation/pact-node/standalone/win32-

krishnam.misc
2020-05-07 04:27
While the sample looks simple and easy, not sure why the basic example does not get through

matt.fellows
2020-05-07 04:29
Just a reminder - please format your code with the triple backticks. Or use this feature

matt.fellows
2020-05-07 04:31
It looks like there is an existing pact contract file that has invalid json - care to share it?

matt.fellows
2020-05-07 04:32
also, I suspect your query param is still wrong. is `inviteId` expected to be an array i.e. `inviteId[]=1234` or singular `inviteId=1234` type thing? I suspect the latter

krishnam.misc
2020-05-07 04:32
you are right, its singular

matt.fellows
2020-05-07 04:32
can you please upload the full contents of the log file as an attachment?

krishnam.misc
2020-05-07 04:34
Log

matt.fellows
2020-05-07 04:37
So that log file is conclusive - you?re not sending a request to the mock service

matt.fellows
2020-05-07 04:37
you can see it registered an expectation, and when the test completed, it never received a request and so failed

matt.fellows
2020-05-07 04:38
The request needs to be configured to point at the pact mock service

matt.fellows
2020-05-07 04:38
so the `url` that is given to `getMeEmail` must be the url of the pact mock service

matt.fellows
2020-05-07 04:40
You can either a) specify the exact port pact should be running on when you create a new `Pact(?)` or b) let it dynamically choose a port and grab the values from the pact object e.g. https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js#L87-L92

matt.fellows
2020-05-07 04:41
@tjones :point_up: this problem happens a lot. I?m wondering if in JS land we should do something like what nock does, and hijack the HTTP runtime and automatically route the request to the mock service?)

matt.fellows
2020-05-07 04:41
just a thought

tjones
2020-05-07 05:14
Could be good! If we can find a nice way to do this cross platform, then yeah

tjones
2020-05-07 05:15
That was also part of the motivation for `jest-pact` - I wanted to get the url + port directly from the provider, without needing to ensure it was different in each test

tjones
2020-05-07 05:16
I think if we wrote wrappers along those lines for all the other popular test frameworks, it would be clear what parts should be directly written into the pact-js DSL

tjones
2020-05-07 05:17
For example, jest-pact has this (but I can?t remember why): https://github.com/pact-foundation/jest-pact/blob/master/src/index.ts#L33

matt.fellows
2020-05-07 07:46
> I think if we wrote wrappers along those lines for all the other popular test frameworks, it would be clear what parts should be directly written into the pact-js DSL I agree, that would be really instructive for the next generation of API design

a.smith
2020-05-07 08:18
has joined #pact-js

krishnam.misc
2020-05-07 10:49
@matt.fellows so the `url` that is given to `getMeEmail` must be the url of the pact mock service I am confused. If we are just hitting the mock server, then, where exactly would the validation happen between the actual endpoint call and mock response before a pact/contract is generated under Pacts dir

matt.fellows
2020-05-07 10:59
The pact contract is generated from the consumer side without ever talking to the real provider

matt.fellows
2020-05-07 11:00
the contract generated is then shared to a provider

matt.fellows
2020-05-07 11:00
the provider build runs separately

krishnam.misc
2020-05-07 11:00
This is my overall understanding of how pact works in steps below: 1. We will define what is the expected response from a real service call in `const EXPECTED_BODY` 2. We will build the actual interaction in `describe("works", () =>`  3. `it("returns a sucessful body", ()` - Here we are validating that the actual service endpoint response is same as what we mocked. This is how we are adding expectations. 4. All expectations/contracts created are shared with Provider who will validate against his own endpoint changes to confirm contract is not broken

matt.fellows
2020-05-07 11:00
Think of Pact on the consumer side, as a unit test of your client code.

matt.fellows
2020-05-07 11:01
> 3. it(?returns a sucessful body?, () - Here we are validating that the actual service endpoint response is same as what we mocked. This is how we are adding expectations. No, you don?t hit the _actual_ endpoint, you only talk to Pact

tjones
2020-05-07 11:02
The verification against the actual real endpoint is done later

tjones
2020-05-07 11:03
this is one of the value props of Pact: you don?t need to spin up the client and the server at the same time


tjones
2020-05-07 11:04
see here for some diagrams

krishnam.misc
2020-05-07 11:12
[2020-05-07T11:11:36.245Z] INFO: pact@9.2.1/27860 on LTIN114925: Setting up Pact with Consumer "MyConsumer-EmailInvite" and Provider "MyProvider-EmailInvite" using mock service on Port: "8991" [2020-05-07T11:11:36.589Z] INFO: pact@9.2.1/27860 on LTIN114925: Pact File Written [2020-05-07T11:11:36.591Z] INFO: pact-node@9.0.7/27860 on LTIN114925: Removing Pact with PID: 28708 PASS __tests__/inviteEmaiContractTest.js (18.671s) Verify GET Email Contract works ? returns a sucessful body (249ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 22.954s Ran all test suites matching /__tests__\\/i. [2020-05-07T11:11:38.754Z] INFO: pact-node@9.0.7/27860 on LTIN114925:

tjones
2020-05-07 11:12
Please format your code with three backticks ```

krishnam.misc
2020-05-07 11:12
```[2020-05-07T11:11:36.245Z] INFO: pact@9.2.1/27860 on LTIN114925: Setting up Pact with Consumer "MyConsumer-EmailInvite" and Provider "MyProvider-EmailInvite" using mock service on Port: "8991" [2020-05-07T11:11:36.589Z] INFO: pact@9.2.1/27860 on LTIN114925: Pact File Written [2020-05-07T11:11:36.591Z] INFO: pact-node@9.0.7/27860 on LTIN114925: Removing Pact with PID: 28708 PASS __tests__/inviteEmaiContractTest.js (18.671s) Verify GET Email Contract works ? returns a sucessful body (249ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 22.954s Ran all test suites matching /__tests__\\/i. [2020-05-07T11:11:38.754Z] INFO: pact-node@9.0.7/27860 on LTIN114925:```

krishnam.misc
2020-05-07 11:13
Apologies for lengthy comments - @tjones

yousafn
2020-05-07 11:13
Took me a little while to get my head round it, but then I was like ta-daaaaaa!

krishnam.misc
2020-05-07 11:16
I might need some time to get this concept into my lazy head :smile:

matt.fellows
2020-05-07 11:17
it does take some time

matt.fellows
2020-05-07 11:17
We?re in the process of creating an explainer video, that hopefully can do that job in < 3 minutes. Wish us luck

krishnam.misc
2020-05-07 11:17
Is there a sample provider code that I can refer and see how this contract I generated is validted?


tjones
2020-05-07 11:19
there?s a provider test in here


tjones
2020-05-08 02:06
No, that?s an example provider

krishnam.misc
2020-05-11 11:46
So,do we need to publish the pact we generated even before it can be accessed by Provider? I suppose, this would happen when we are hosting our pacts on some server

tjones
2020-05-11 11:47
It?s best to use a broker, yeah

tjones
2020-05-11 11:47
but you don?t have to - any way you can share pacts is fine

krishnam.misc
2020-05-11 11:47
and can you give me a direct link to a sample provider test. I could not find any.

krishnam.misc
2020-05-11 11:48
sharing pacts is fine in general context, but in a CI mode, its good that they are available online?


tjones
2020-05-11 11:48
Yes, your life is definitely easier with the pact broker

krishnam.misc
2020-05-11 11:50
unfortunately, this example relies on a broker to be running

krishnam.misc
2020-05-11 11:51
If I need to get this working in static mode?


tjones
2020-05-12 04:43
@krishnam.misc did you get it working?

krishnam.misc
2020-05-12 04:43
nope :disappointed:

krishnam.misc
2020-05-12 04:44
This seems to be a little tricky

tjones
2020-05-12 04:47
What was your problem? Maybe I can help

tjones
2020-05-12 04:49
If you modify the example to use `pactUrls: [ './path-to-your-pact.json']`, and remove the broker specific variables (pactBrokerUsername, pactBrokerPassword, pactBrokerUrl, publishVerificationResult, etc), it should work

krishnam.misc
2020-05-12 04:50
pact-js-master\examples\e2e\test\provider.spec.js I was looking into this example and try to write a Provider test but that gives me errors while publishing the provider. Implement Provider  Implement Consumer Install pact package from npm Install test runner like Jest Write Consumer test to generate pact json file Execute Consumer test which will generate pact json publish pact file to pact broker Write provider test with pact broker Execute provider test We are done from steps 1 to 6

tjones
2020-05-12 04:51
What error do you get?

tjones
2020-05-12 04:52
Above, you said you were looking for an example that didn?t use the pact broker

tjones
2020-05-12 04:52
so if your pact is not in the broker, you won?t be able to publish the verification result

tjones
2020-05-12 04:52
note that the flow goes: Consumer test -> writes pact publish pact -> broker

tjones
2020-05-12 04:52
then,

tjones
2020-05-12 04:53
broker -> gives pact to provider test provider test -> publishes verification success (or failure) to broker

tjones
2020-05-12 04:53
if you are manually providing the pact to the provider test, you won?t be able to publish a verification status

krishnam.misc
2020-05-12 04:56
.

tjones
2020-05-12 04:56
can you edit that to be in ``` please?

krishnam.misc
2020-05-12 04:56
```PS C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\__tests__> curl -v -XPUT -H "Content-Type: application/json" -d ..\pacts\myconsumer-emailinvite-myprovider-emailinvite.json http://localhost/pacts/provider/MyProvider-EmailInvite/consumer/MyConsumer-EmailInvite/version/1.0 Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" value of type "System.String" to type "System.Collections.IDictionary". At line:1 char:18 + curl -v -XPUT -H "Content-Type: application/json" -d ..\pacts\myconsu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand```


tjones
2020-05-12 04:59
So, that?s a curl command that doesn?t work in powershell - see here:


tjones
2020-05-12 04:59
anyway, publishing the pact manually with curl isn?t necessary

tjones
2020-05-12 04:59
you can use pact-js to do it



tjones
2020-05-12 05:01
Alternatively, you can use the binstub that `pact-node` provides

tjones
2020-05-12 05:02
```...in your package json: "pactPublish": "pact publish --pact-files-or-dirs pacts --consumer-version \"$(git describe)\" --pact-broker \"$PACT_BROKER_HOST\" --pact-broker-username \"$PACT_BROKER_USERNAME\" --pact-broker-password \"$PACT_BROKER_PASSWORD\"",```

krishnam.misc
2020-05-12 05:18
ok, let me take a look

krishnam.misc
2020-05-12 07:00
C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\publish.js:8 .trim() ^ ReferenceError: childProcess is not defined at exec (C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\publish.js:8:6) at Object.<anonymous> (C:\ContractTesting\pact-js-master\pact-js-master\examples\jest\publish.js:12:45)

krishnam.misc
2020-05-12 07:01
publish.js seems to have muliple conditions to meet

krishnam.misc
2020-05-12 07:01
if (http://process.env.CI !== "true") {   console.log("skipping Pact publish as not on CI...")   process.exit(0) }

krishnam.misc
2020-05-12 07:02
I removed this part, as I am running this in local. But we also have other conditions around TRAVIS, etc

tjones
2020-05-12 07:02
how are you invoking it? `childProcess` is part of node

krishnam.misc
2020-05-12 07:03
Not to rant, the sample example is usually simple to adapt and generate more interest to embrace the product. However, i have a diff feeling here.

tjones
2020-05-12 07:03
I agree. I?m working on improving the examples at the moment.

krishnam.misc
2020-05-12 07:03
may be I am alone finding it diff to get this working, not sure.

krishnam.misc
2020-05-12 07:05
I am just running "test" from package.json file

tjones
2020-05-12 07:05
Some of the issues you have run in to have been unrelated to pact (eg running the curl command in powershell). But, it does illustrate that our documentation could be improved - the curl command you had came from someone?s blog, rather than the pact documentation.

krishnam.misc
2020-05-12 07:05
Agree. But I am just trying to find diff ways to get past this simple PoC

tjones
2020-05-12 07:05
By the way, I think the best way is to call the pact-publish command from the package json, as in the second snippet I sent you above

tjones
2020-05-12 07:06
The ability to do this is in the documentation, but I?d like to surface it more

krishnam.misc
2020-05-12 07:13
``` "pactPublish": "pact publish --pact-files-or-dirs pacts --consumer-version concumser-1.0 --pact-broker localhost:9009"```

krishnam.misc
2020-05-12 07:17
``` Executing task: npm run pactPublish < pact-example-jest@1.0.0 pactPublish C:\ContractTesting\pact-js-master\pact-js-master\examples\jest pact publish --pact-files-or-dirs pacts --consumer-version concumser-1.0 --pact-broker localhost:9009 Could not find command "publish".```

tjones
2020-05-14 02:12
Ah yes, sorry. I gave you completely the wrong example.

tjones
2020-05-14 02:13
Try: ``` pact-broker publish pacts --consumer-app-version=concumser-1.0 --broker-base-url=http://localhost:9009```

tjones
2020-05-14 02:14
by the way, I would recommend not hardcoding your version

hans.brouwer
2020-05-14 07:18
has joined #pact-js

cesar.lopes
2020-05-15 12:31
```"overview": "All versions of `http-proxy` are vulnerable to Denial of Service. An HTTP request with a long body triggers an `ERR_HTTP_HEADERS_SENT` unhandled exception that crashes the proxy server. This is only possible when the proxy server sets headers in the proxy request using the `proxyReq.setHeader` function. \n\nFor a proxy server running on `http://localhost:3000`, the following curl request triggers the unhandled exception: \n```curl -XPOST http://localhost:3000 -d \"$(python -c 'print(\"x\"*1025)')\"```", "recommendation": "No fix is currently available. Consider using an alternative package until a fix is made available.",```

cesar.lopes
2020-05-15 12:32
do we have any ticket to replace http-proxy?

tjones
2020-05-15 12:33
We don?t, and could accept a fix if someone wanted to make one. However, I don?t think this is a practical problem. The proxy is only spun up locally during tests, and the worst that could happen is someone could interrupt your CI process if they had access to your CI environment (and if that has happened, you have bigger problems than someone interrupting your pact tests).

cesar.lopes
2020-05-15 12:37
Ok, my pipeline is currently broken because it fail on npx audit

matt.fellows
2020-05-15 13:29
With respect Cesar, that's not our problem. If the package can be upgraded then great. We'll accept a PR or if you'd like to raise an issue please do. I suspect if it's a new vulnerability, snyk will notify us.

matt.fellows
2020-05-15 13:30
A blanket security rule is useless if you don't know what the problems are. That vulnerability simply is not an issue for the use case.

matt.fellows
2020-05-15 13:34
You could ignore dev dependencies or find other ways to manage vulnerabilities.

closenet.uk
2020-05-15 13:40
same here, 4 vulnerabilities @pact-foundation/pact package

closenet.uk
2020-05-15 13:40
@matt.fellows can you help with that?

cesar.lopes
2020-05-15 13:45
I understand @matt.fellows ty for the answers

cesar.lopes
2020-05-15 13:45
:+1:

matt.fellows
2020-05-15 14:10
I'm trying to say we don't care, obviously we do!

yousafn
2020-05-15 14:38
you can either use audit-ci to skip particular vulns, https://github.com/IBM/audit-ci

yousafn
2020-05-15 14:38
@closenet.uk Hey Mo!

cesar.lopes
2020-05-15 14:38
that?s what I did, ty @yousafn

closenet.uk
2020-05-15 14:57
hey @yousafn :slightly_smiling_face:

closenet.uk
2020-05-15 14:58
disabled devDependecies in audit, cheers guys

raghu.alapati1
2020-05-16 00:07
has joined #pact-js

antonello
2020-05-18 06:33
Morning! The eachLike matcher expects a minimum array length of 1. How to match an array that can be empty? The java dsl has, for example, minArrayLike.

tjones
2020-05-18 06:33
Use an empty array

tjones
2020-05-18 06:34
An empty array is a separate test case (otherwise you could have passing tests that never test the contents of the array)

antonello
2020-05-18 06:35
That?s fair! Thank you! I should?ve thought of that :)

tjones
2020-05-18 06:36
No worries :slightly_smiling_face: It?s a common question, we should add it to the docs for `eachLike`


matt.fellows
2020-05-18 08:00
My first PR to the Ruby part of the code base, or at least an early one

antonello
2020-05-18 08:12
awesome, I think it?s the right thing.

antonello
2020-05-18 08:15
An approach that one of the teams has gone for (at least on a specific instance that I?m aware of) is to define an interaction with a minimal response, where minimal means with only the properties and values that are not optional and empty arrays for properties where that?s allowed. This can be sensible in the case of relatively big responses where having a state or interaction for, for example, each array that can be empty would lead to quite a large number of interactions.

tjones
2020-05-18 08:16
I think ideally, you would create interactions with the minimal response that you need, and all the properties that you understand / use

matt.fellows
2020-05-18 08:16
kind of like a min and max set?

antonello
2020-05-18 08:21
Yep, I think that?s what I mean. :slightly_smiling_face:

matt.fellows
2020-05-18 08:21
That seems a reasonable starting point for most I think

matt.fellows
2020-05-18 08:22
And then if strange/weird edge cases start to emerge, you can get more specific

antonello
2020-05-18 08:22
There are some (old) endpoints that rightly or wrongly would require a huge amount of interactions to cover all possible and meaningful examples.

antonello
2020-05-18 08:30
So yes, min set and max set are good starting points. Probably max set is not enough in the majority of cases, even as a starting point.

tjones
2020-05-18 08:49
Yeah- testing all permutations of possible responses is hard to cover even in traditional unit tests. I think it?s good to make a reasonable choice about what to cover, and it sounds like you?re making good choices in your situation

yousafn
2020-05-18 14:49
how did you guys managed to disable devDependecies in audit-ci? I?d like that option but couldn?t find it in the docs

matt.fellows
2020-05-18 22:28
```npm audit --only=prod```

robert.strauch_slack
2020-05-18 23:46
has joined #pact-js

robert.strauch_slack
2020-05-18 23:57
Good evening, We're having a web application based on VueJS. In order to isolate its testing I'd like to introduce pact-js for the communication to the provider. As written in the https://github.com/pact-foundation/pact-js#example > Write your tests - the important thing here is that you test the outbound _collaborating_ function which calls the Provider, and not just issue raw http requests to the Provider. In a Vue application there's a Vue component which has a method, e.g. `submit()`. This method issues an HTTP request. Would the above mean that the consumer test should preferrably invoke the `submit()` method instead of something like `axios.get()`?

tjones
2020-05-19 00:10
Almost. Usually, the pattern would be the other way around

tjones
2020-05-19 00:11
So, your vue component and your consumer test both call an API layer

tjones
2020-05-19 00:11
separating the API concern from the component


tjones
2020-05-19 00:12
here?s a React example, but the principle is the same

tjones
2020-05-19 00:14
For vue: ```new Vue({ el: '#app', data () { return { info: null } }, mounted () { axios .get('https://api.coindesk.com/v1/bpi/currentprice.json') .then(response => (http://this.info = response)) } })```

tjones
2020-05-19 00:14
This is the example in the docs

tjones
2020-05-19 00:26
For Pact, you?d want to do something like: ``` mounted () { api.getPrices() .then(response => (http://this.info = response)) }``` Irrespective of pact, I like this better, because it separates how to get the data from what to do with it

matt.fellows
2020-05-19 02:12
yep. Separate out front end / display logic from integration logic

matt.fellows
2020-05-19 02:13
makes things much more testable

robert.strauch_slack
2020-05-19 07:03
Yeah, that's what I was thinking of. The problem is that our current codebase is somewhat messy and that API calls are made sirectly with axios from within the component. Maybe we need some refactoring first :stuck_out_tongue:

tjones
2020-05-19 07:04
I think that is likely to be true whatever test framework you choose

robert.strauch_slack
2020-05-19 07:07
Thanks for your help, guys... this clears some things for me :slightly_smiling_face:

jarmy
2020-05-22 16:58
has joined #pact-js

robert.strauch_slack
2020-05-24 20:37
Dear pact-js members, I'm still taking my first steps with Pact and there's one thing I couldn't get running. There is a REST resource on the provider side for registering new users. On a successful registration, this resource responds with HTTP 200 and a Bearer token in the response header like `Authorization: Bearer someToken`. This is the interaction on the consumer side but the mock response does not contain `Authorization: Bearer someToken` ```await provider.addInteraction({ state: "default", uponReceiving: "register new user", withRequest: { method: "POST", path: "/register" }, willRespondWith: { status: 200, headers: { "Authorization": "Bearer TOKEN" } } });```

matt.fellows
2020-05-24 23:20
It definitely should return that header, can you show some logs or something proving otherwise?

matt.fellows
2020-05-24 23:20
The mock server will show what it thinks it needs to return

matt.fellows
2020-05-24 23:20
If you could share the test code, the logs or both that would be helpful. Most helpful would be to fork an example in the JS repository and show the bug in action

paul.davies
2020-05-27 04:05
has joined #pact-js

tjones
2020-05-28 01:27
In addition to Matt?s comment, this code returns `Bearer TOKEN`, but your question is about `Bearer someToken`.

sairsule
2020-05-30 10:49
has joined #pact-js

danhitchcock
2020-06-01 15:55
has joined #pact-js

weyert.deboer
2020-06-01 21:56
has joined #pact-js

lankala321
2020-06-05 03:24
has joined #pact-js

lankala321
2020-06-05 03:33
I am getting this error. ERROR in node_modules/@pact-foundation/pact-node/src/message.d.ts(6,32): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/pact.d.ts(23,55): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(24,47): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(25,49): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-web/dsl/options.d.ts(35,45): error TS2304: Cannot find name 'Exclude'. src/api/services/auth.service.pact.spec.ts(16,7): error TS2345: Argument of type '{ consumer: string; provider: string; port: number; }' is not assignable to parameter of type 'PactWebOptions'. Object literal may only specify known properties, and 'consumer' does not exist in type 'PactWebOptions'.

lankala321
2020-06-05 03:37
I am following this article.



lankala321
2020-06-05 03:40
I am setting up pact karma using npm install --save-dev @pact-foundation/karma-pact @pact-foundation/pact-node @pact-foundation/pact-web

lankala321
2020-06-05 03:41
can somebody please help me what should i do to fix this issue.

tjones
2020-06-05 03:46
It looks like you?re not passing the right options to PactWeb - can you provide your code?

tjones
2020-06-05 03:51
The example code you linked to works for me. How are you configuring your Pact settings?

lankala321
2020-06-05 03:54
import { HttpClientModule } from '@angular/common/http'; import { service } from './abc.service'; import { User } from './../models/user'; import {TestBed} from '@angular/core/testing'; import { Matchers, PactWeb } from '@pact-foundation/pact-web' describe('UserServicePact', () => { let provider; // Setup Pact mock server for this service beforeAll(async () => { /*provider = await new Pact({*/ provider = await new PactWeb({ consumer: 'webclient', provider: 'service', port: 1234 }); // required for slower CI environments await new Promise(resolve => setTimeout(resolve, 1000)); // Required if run with `singleRun: false` await provider.removeInteractions(); }); // Configure Angular Testbed for this service beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpClientModule ], providers: [ service ] }); }); // Verify mock service afterEach(async () => { await provider.verify(); }); // Create contract afterAll(async () => { await provider.finalize(); }); describe('get()', () => { const userId = 1; const expectedMeDetails: User = { id: '123', username: 'xyz', enabled: true, accountNonExpired: true, accountNonLocked: true, }; beforeAll(async () => { await provider.addInteraction({ state: `get me details`, uponReceiving: 'a request to GET me details', withRequest: { method: 'GET', path: `/me` }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedMeDetails) } }); }); it('should get a user', async () => { const service: service = TestBed.get(service); await http://service.me().toPromise().then(response => { expect(response).toEqual(expectedMeDetails); }); }); });

abubics
2020-06-05 03:57
(as a little aside, using the "code block" formatting in Slack will make your code samples much easier to read & distinguish against conversation messages)

tjones
2020-06-05 03:57
What version of typescript are you using?

lankala321
2020-06-05 03:58
```2.4.2```

tjones
2020-06-05 03:59
Could you try again with typescript 3? It looks like the definitions we are exporting aren?t compatible with typescript 2. Apologies for not having this documented

lankala321
2020-06-05 03:59
sure

tjones
2020-06-05 04:03
Looks like this was introduced in pact-node 9.01 - I didn?t expect it would be a breaking change.

lankala321
2020-06-05 04:04
ERROR in node_modules/@pact-foundation/pact-node/src/message.d.ts(6,32): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/pact.d.ts(23,55): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(24,47): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-node/src/service.d.ts(25,49): error TS2304: Cannot find name 'unknown'. node_modules/@pact-foundation/pact-web/dsl/options.d.ts(35,45): error TS2304: Cannot find name 'Exclude'. src/api/services/auth.service.pact.spec.ts(16,7): error TS2345: Argument of type '{ consumer: string; provider: string; port: number; }' is not assignable to parameter of type 'PactWebOptions'. Object literal may only specify known properties, and 'consumer' does not exist in type 'PactWebOptions'.

lankala321
2020-06-05 04:04
same errors

tjones
2020-06-05 04:05
I believe `Cannot find name 'unknown'` is caused by using TS 3 types with TS 2

tjones
2020-06-05 04:06
Can you tell us which versions you are using of pact-web / pact-node, and typescript please?

tjones
2020-06-05 04:06
Also, does the example code you linked work for you?

lankala321
2020-06-05 04:06
```"@pact-foundation/karma-pact": "^2.3.1", "@pact-foundation/pact-node": "^10.9.5", "@pact-foundation/pact-web": "^9.11.0",```

tjones
2020-06-05 04:07
would you be able to share an example repository that I can use to reproduce the problem?

lankala321
2020-06-05 04:09
yes. I am working on it i will provide.

tjones
2020-06-05 04:09
Thanks!

lankala321
2020-06-05 04:21
05 06 2020 00:12:26.007:INFO [Chrome 83.0.4103 (Windows 10.0.0)]: Connected on socket E1XhRprV1Vk04NpdAAAA with id 24754627 WARN: 'Passing in consumer/provider to PactWeb is deprecated, and will be removed in the next major version' Chrome 83.0.4103 (Windows 10.0.0): Executed 0 of 7 SUCCESS (0 secs / 0 secs) WARN: 'Passing in consumer/provider to PactWeb is deprecated, INFO: 'Setting up Pact using mock service on port: "1234"' Chrome 83.0.4103 (Windows 10.0.0): Executed 0 of 7 SUCCESS (0 secs / 0 secs) INFO: 'Setting up Pact using mock service on port: "1234"' 05 06 2020 00:12:33.461:WARN [proxy]: failed to proxy /api/users/42 (connect ECONNREFUSED 127.0.0.1:1234) 05 06 2020 00:12:35.464:WARN [proxy]: failed to proxy /api/users/42 (connect ECONNREFUSED 127.0.0.1:1234) 05 06 2020 00:12:37.469:WARN [proxy]: failed to proxy /api/users/42 (connect ECONNREFUSED 127.0.0.1:1234) Chrome 83.0.4103 (Windows 10.0.0) UserServicePact update() should update a user FAILED HttpErrorResponse: Http failure response for /api/users/42: 0 Unknown Error Error: PopsicleError: Unable to connect to "http://127.0.0.1:1234/interactions/verification" at new VerificationError (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22530:1) at http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:20163:1 at tryCatch (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:488:1) at invokeCallback (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:503:1) at publish (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:477:1) at publishRejection (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:418:1) at MutationObserver.flush (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:207:1) at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:359:1) at Zone.runGuarded (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:134:1) at MutationObserver.<anonymous> (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:118:1) Chrome 83.0.4103 (Windows 10.0.0): Executed 1 of 7 (1 FAILED) (0 secs / 10.422 secs) Chrome 83.0.4103 (Windows 10.0.0) UserServicePact update() should update a user FAILED HttpErrorResponse: Http failure response for /api/users/42: 0 Unknown Error Error: PopsicleError: Unable to connect to "http://127.0.0.1:1234/interactions/verification" at new VerificationError (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22530:1) at http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:20163:1 at tryCatch (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:488:1) at invokeCallback (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:503:1) at publish (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:477:1) at publishRejection (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:418:1) at MutationObserver.flush (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:207:1) at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:359:1) at Zone.runGuarded (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:134:1) Chrome 83.0.4103 (Windows 10.0.0) ERROR { "message": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node _modules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at XMLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:3 91:1)\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-everg reen.js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/ dist/zone-evergreen.js:1629:1)", "str": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node_mod ules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at X MLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:391:1 )\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen .js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist /zone-evergreen.js:1629:1)" } Chrome 83.0.4103 (Windows 10.0.0): Executed 1 of 7 (1 FAILED) ERROR (0 secs / 10.422 secs) Chrome 83.0.4103 (Windows 10.0.0) ERROR { "message": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node _modules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at XMLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:3 91:1)\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-everg reen.js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/ dist/zone-evergreen.js:1629:1)", "str": "An error was thrown in afterAll\nPopsicleError: Unable to connect to \"http://127.0.0.1:1234/interactions\"\nerror properties: Error\n at <Jasmine>\n at Request.error (http://localhost:9876/_karma_webpack_/node_mod ules/@pact-foundation/pact-web/pact-web.js:18862:1)\n at XMLHttpRequest.xhr.onerror [as __zone_symbol__ON_PROPERTYerror] (http://localhost:9876/_karma_webpack_/node_modules/@pact-foundation/pact-web/pact-web.js:22417:1)\n at X MLHttpRequest.wrapFn (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1191:1)\n at ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:391:1 )\n at Zone.runTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:168:1)\n at ZoneTask.invokeTask [as invoke] (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen .js:465:1)\n at invokeTask (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:1603:1)\n at XMLHttpRequest.globalZoneAwareCallback (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist /zone-evergreen.js:1629:1)" Chrome 83.0.4103 (Windows 10.0.0): Executed 1 of 7 (1 FAILED) ERROR (13.691 secs / 10.422 secs) [2020-06-05T04:12:41.975Z] INFO: pact-node@10.2.2/24448 on lan: Removing all Pact servers. [2020-06-05T04:12:41.976Z] INFO: pact-node@10.2.2/24448 on lan: Removing Pact with PID: 10236 ERROR: The process "10236" not found.

lankala321
2020-06-05 04:21
example files also throwing errors

tjones
2020-06-05 04:31
There should be lines like this in the log above the quote you sent: ```10% building 1/1 modules 0 active[2020-06-05T04:29:51.809Z] INFO: pact-node@10.2.2/7337 on Timothys-MBP.fritz.box: Creating Pact Server with options: {"cors":true,"spec":3,"port":1234,"log":"/Users/tim/office/pact/pact-example-angular-spring-boot/consumers/angular8-karma/logs/mockserver-integration.log","dir":"/Users/tim/office/pact/pact-example-angular-spring-boot/pacts","pactFileWriteMode":"overwrite","ssl":false,"host":"localhost"} 05 06 2020 14:29:53.499:INFO [pact]: Pact Mock Server running on port: 1234 05 06 2020 14:29:53.543:INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/```

lankala321
2020-06-05 04:38
yes i have those lines

lankala321
2020-06-05 04:40
10% building 1/1 modules 0 active[2020-06-05T04:11:55.168Z] INFO: pact-node@10.2.2/24448 on : Creating Pact Server with options: {"cors":true,"spec":3,"port":1234,"log":"C:\\Users\\IdeaProjects\\pact-example-angular-spring-boot\\consumers\\angular8-karma\\logs\\mocks erver-integration.log","dir":"C:\\Users\\IdeaProjects\\pact-example-angular-spring-boot\\pacts","pactFileWriteMode":"overwrite","ssl":false,"h ost":"localhost"} [2020-06-05T04:11:57.035Z] ERROR: pact-node@10.2.2/24448 on Ulankala: Pact Binary Error: C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/ standalone/win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/app.rb:5:in `require': cannot load such file -- pact/co nsumer/mock_service/cors_origin_header_middleware (LoadError) from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/app.rb:5:in `<top (required)>' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/run.rb:2:in `require' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/run.rb:2:in `<top (required)>' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone /win32-1.72.2/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.2.0/lib/pact/mock_service/cli.rb:33:in `require' from C:/Users/IdeaProjects/pact-example-angular-spring-boot/consumers/angular8-karma/node_modules/@pact-foundation/pact-node/standalone 05 06 2020 00:12:25.179:ERROR [pact]: Error while trying to run karma-pact: Error: Couldn't start Pact with PID: 10236

tjones
2020-06-05 04:53
That looks like the windows 10 pathing issues, see: https://github.com/pact-foundation/pact-node/issues/100

phil.endsley
2020-06-05 14:14
has joined #pact-js

lankala321
2020-06-05 17:41
example file is working for me. That was windows path issue

lankala321
2020-06-07 03:06
Hi team, actual interactions do not match expected interactions for mock mock service. I am getting this error pacts files not getting generated.

lankala321
2020-06-07 03:07
Can anybody know how to overcome these

matt.fellows
2020-06-07 03:07
it means what your test code is doing does not match what you said it would do

matt.fellows
2020-06-07 03:07
please share your consumer test and any log files

lankala321
2020-06-07 03:14
describe('UserServicePact', () => { let provider; // Setup Pact mock server for this service beforeAll(async () => { provider = await new PactWeb({ }); // required for slower CI environments await new Promise(resolve => setTimeout(resolve, 1000)); // Required if run with `singleRun: false` await provider.removeInteractions(); }); // Configure Angular Testbed for this service beforeEach(() => { TestBed.configureTestingModule({ imports: [ HttpClientModule ], providers: [ Service ] }); }); // Verify mock service afterEach(async () => { await provider.verify(); }); // Create contract afterAll(async () => { await provider.finalize(); }); describe('get()', () => { const expected: User = { id: '123', username: 'test', firstName: 'xyz', lastName: 'abc', }; beforeAll(async () => { await provider.addInteraction({ state: `Get User`, uponReceiving: 'a request to Get User Details', withRequest: { method: 'GET', path: `http://localhost:1234/User`, headers: {'Content-Type': 'application/json'}, query: "" }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedDetails) } }); }); it('should get a user', async () => { const service: UserService = TestBed.get(UserService); await service.getUser().toPromise().then(response => { expect(response).toEqual(expected); }); }); });

lankala321
2020-06-07 03:20
Log file:

lankala321
2020-06-07 03:20
I, [2020-06-06T22:06:01.771382 #4336] INFO -- : Registered expected interaction GET /User D, [2020-06-06T22:06:01.771382 #4336] DEBUG -- : { "description": "a request to Get User Details", "providerState": "Get User", "request": { "method": "GET", "path": "/User", "headers": { "Content-Type": "application/json" } }, "response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::SomethingLike", "contents": { "id": "123", "username": "test", "firstName": "xyz", "lastName": "abc", } } }, "metadata": null } W, [2020-06-06T22:06:01.780417 #4336] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /User I, [2020-06-06T22:06:03.151564 #4336] INFO -- : Cleared interactions

matt.fellows
2020-06-07 03:21
path should just be `/User`. Is `UserService` configured to hit the pact mock service instead of the real thing?

lankala321
2020-06-07 03:28
I tried /User also it was not working i am getting same errors. So I used localhost beforeAll(async () => { await provider.addInteraction({ state: `Get User`, uponReceiving: 'a request to Get User Details', withRequest: { method: 'GET', path: `/User`, headers: {'Content-Type': 'application/json'}, query: "" }, willRespondWith: { status: 200, body: Matchers.somethingLike(expectedDetails) } });

matt.fellows
2020-06-07 03:28
The log file above is very clear - it did not see a request to `/User`. Please ensure your UserService is configured to point to the Pact Mock service on whatever port you?ve configured Pact to run on

lankala321
2020-06-07 03:39
My userservice class is like this

lankala321
2020-06-07 03:39
@Injectable() export class UserService { baseUrl = environment.userServiceBaseUrl;

lankala321
2020-06-07 03:40
what changes should i make here

matt.fellows
2020-06-07 03:40
what port are you starting pact on

lankala321
2020-06-07 03:40
userServiceBaseUrl is pointing to the actual url

lankala321
2020-06-07 03:40
1234

matt.fellows
2020-06-07 03:40
it should point to `http://localhost:1234`

lankala321
2020-06-07 03:41
pact: [ { cors: true, spec: 3, port: 1234, consumer: 'ui', provider: 'userservice', log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pact') } ], proxies: { '/api': 'http://localhost:1234' }

lankala321
2020-06-07 03:41
this is my my karma.conf

matt.fellows
2020-06-07 03:42
thx, sorry I don?t know karma very well

matt.fellows
2020-06-07 03:42
I think any api calls that go to `/api/*` will be proxied, but you?re not using that

matt.fellows
2020-06-07 03:42
I could be wrong, you?ll need to read the docs

lankala321
2020-06-07 03:55
thank you. I tried even this one http://localhost:1234 not working.

lankala321
2020-06-07 03:56
Do you have any refernces for github working codes for angular.

matt.fellows
2020-06-07 04:04
what does the log file say after you updated the endpoint?



lankala321
2020-06-07 04:17
It is giving same error even after updating.

matt.fellows
2020-06-07 04:17
what do the logs say

matt.fellows
2020-06-07 04:18
the logs will tell you how you?re interacting with Pact

matt.fellows
2020-06-07 04:18
if no request is coming in, that?s all todo with your angular/karma setup

matt.fellows
2020-06-07 04:18
I?m afraid I can?t tell you how to configure your own setup

lankala321
2020-06-07 04:30
I, [2020-06-07T00:28:54.008388 #18500] INFO -- : Cleared interactions I, [2020-06-07T00:28:55.351390 #18500] INFO -- : Cleared interactions

lankala321
2020-06-07 04:30
I am just getting this now and pact is not generating

matt.fellows
2020-06-07 05:57
that can?t be the whole log file

matt.fellows
2020-06-07 05:57
It should first ?register an interaction? (as per above)

matt.fellows
2020-06-07 05:58
If you can provide a reproducable example we could help troublesheet (e.g. a working git repository)

tjones
2020-06-07 10:34
@lankala321 I think you?ve got the `proxies` setting from the example repository you linked, but it?s not appropriate for your API. Try `proxies: { '/User': 'http://localhost:1234' }`

lankala321
2020-06-07 21:23
@tjones, Thank you. I fixed the proxy issues. It is working fine now.

lankala321
2020-06-08 07:48
How to publish pacts to pact broker from angular project?

matt.fellows
2020-06-08 12:30
It has nothing to do with Angular


cristian.schez
2020-06-09 11:21
has joined #pact-js

godfrey
2020-06-10 07:35
has joined #pact-js

pact.io971
2020-06-11 01:13
has joined #pact-js

matt.fellows
2020-06-11 02:23
we are looking for more JS core maintainers. As now the _second most_ popular Pact library (in terms of stars) we have a lot we?d like to do. Our top priority is building a healthy community and sustainable contributor base. https://github.com/pact-foundation/pact-js/issues/451ssues tagged `good first issue` or `help wanted` could be a great place to start https://github.com/pact-foundation/pact-js/labels/help%20wanted

bradley.smith
2020-06-11 23:03
has joined #pact-js

michaelphi
2020-06-16 22:36
has joined #pact-js

yousafn
2020-06-17 23:00
has anyone come across this before, looks pretty cool? https://github.com/ASaiAnudeep/pactum


tjones
2020-06-17 23:10
Oh, that?s cool! I?ve been wanting to add better configuration to pact-js for a while

tjones
2020-06-17 23:11
Unless I?m missing something, in terms of features, this only adds some new environment variables?

tjones
2020-06-17 23:12
> Publish Pacts to broker > Check if if?s safe to deploy > Start stub loclly using the Pact contract ^ This is part of pact-node already. It highlights that we should improve the documentation substantially

yousafn
2020-06-17 23:13
I started looking into it and yes it looks like just some additional scripts which point to the cli executables, and the env vars which are set, are automatically picked up by the cli tool

yousafn
2020-06-17 23:14
I use those features out of the box with pact-js, but I suppose it worked for their use case (minimal effort, same lines in a package.json can be replicated easily across of their projectts) I just have a shared verifier and publishing script that is used by any of our microservices which use pact

tjones
2020-06-17 23:14
I might reach out to them - better lifecycle and configuration a the direction I?d like to take pact-js

yousafn
2020-06-17 23:15
Aye, always nice to get real world feedback, especially for the future roadmap of jest-pact, pact-js and the like. You never really know what people really care about, and what they want, without chatting to them :slightly_smiling_face: You are deffo more of a people person than me :right-facing_fist:

yousafn
2020-06-17 23:16
I?ve been off work for 2 weeks, looking forward to getting back in and showing the guys all the stuff I?ve been doing with serverless and pact

matt.fellows
2020-06-17 23:17
Wow, that?s interesting

matt.fellows
2020-06-17 23:18
So, it looks like Pact?but I can?t see any dependency on it

matt.fellows
2020-06-17 23:19
But the DSL does have some niceities about it - similar to the nock discussion I was having with Tim recently

matt.fellows
2020-06-17 23:20
They?ve done a very decent job of documenting and there seems to be a lot of care/thinking involved - we should def chat

matt.fellows
2020-06-17 23:21
Might just be me, but I genuinely feel like the last few weeks the community members here have lifted their game - it?s so awesome to see

yousafn
2020-06-17 23:30
There also looked to be the beginning of a pact js native implementation using request interceptors https://github.com/seek-oss/nodejs-consumer-pact-interceptor

yousafn
2020-06-17 23:31
Sounds exactly like the nock discussion. i used it to build a slack mock web server for my integration tests in a slack package I?ve published and it?s been fantastic

matt.fellows
2020-06-17 23:37
So, I worked with the team who wrote that :stuck_out_tongue:

matt.fellows
2020-06-17 23:37
(it was actually my first client at DiUS, and my first exposure to Pact)

yousafn
2020-06-17 23:41
Right, so pactum basically uses polka which is an express style alternative to spin up a mock server, and you are correct, no pact deps, looks like it will create a pact file at the end, which on very cursory glance looks like it meets pact v2

yousafn
2020-06-17 23:44
the docs are brilliant. Hat deffo tipped. I like the split readme?s for diff things rather than shoehorning into one big readme as it cana be. terribly daunting or people will ctrl + f and that is it

tjones
2020-06-17 23:52
Yeah! It?s so inspiring

a.smith
2020-06-18 16:25
Is anyone using jest-pact on Windows? My tests appear to be failing intermittently, and I can't quite see why. This is logged to the console: ```[2020-06-18T16:13:22.004Z] ERROR: pact-node@10.9.5/43640 on IESO-LAP155: Pact Binary Error: Could not load existing consumer contract from C:/path/to/pacts/pact/consumer-provider.json due to 757: unexpected token at 'null'. Creating a new file.```

a.smith
2020-06-18 16:30
I've a Ruby stack trace I can share privately. Might be a pact-standalone problem rather than jest-pact.

a.smith
2020-06-18 17:05
(PS: I found the bug reports about file locking, etc. on Windows. I don't know if this is the same issue.)

tjones
2020-06-18 23:25
Are you running your tests with `--runInBand` ?

tjones
2020-06-18 23:26
I?ve hit this on a mac, but I can?t remember the solution. I think it was a configuration issue, but if it?s happening regularly I?d love to improve the error message

a.smith
2020-06-19 08:43
@tjones thanks for the reply :slightly_smiling_face: We don't think we are using `--runInBand`, but I'm just going to check the create-react-app docs to make sure...

tjones
2020-06-19 08:49
So, when we created jest-pact, I thought it would mean tests could be run in parallel. However, I think sometimes it means that the pact writing collides (which might be what you?re experiencing)

tjones
2020-06-19 08:51
If you?re using CRA, you can use: ```"test": "react-scripts test --runInBand"```

tjones
2020-06-19 08:51
I will add this to the docs tomorrow, apologies for missing it.

tjones
2020-06-19 08:51
(and, please let me know if this doesn?t fix your problem)

a.smith
2020-06-19 09:23
No worries! ~This doesn't seem to have fixed the issue though, sadly~ :disappointed: It has fixed the issue, thank you :slightly_smiling_face:

a.smith
2020-06-19 09:54
I think I've also found that the log file for earlier tests in a run is overwritten by later tests in the same run.

a.smith
2020-06-19 14:31
I haven't been able to find any resources yet about using Pact with batched/paged result sets. Let's say I want to retrieve all the orders a particular customer has placed. That might be 0, 1, many, or "lots". 0 and 1 results obviously fit on one page; let's assume "many" is also sufficiently small to fit on a single page, but "lots" is more than that: e.g. 104 orders placed by that customer with 25 orders per page. How would you go about writing interactions for that kind of API?

uglyog
2020-06-20 03:01
I would test first page, last page and middle page with unit tests, and then have Pact tests to test a page which has a next page, and one that does not.

tjones
2020-06-21 09:33
@a.smith Good pickup! Would you be able to open an issue against jest-pact so it doesn?t get forgotten?

a.smith
2020-06-22 07:36
Nice one, thanks @uglyog

a.smith
2020-06-25 09:09
@tjones Now done :+1: Sorry it's a bit sketchy.

tjones
2020-06-25 09:46
Thanks - it?s clear and has repro instructions, which is all we need. I?ll try to get a fix out in the next couple days.

ayyamuthutechnical
2020-06-25 17:56
has joined #pact-js

ag.robinson
2020-06-27 15:40
has joined #pact-js

chandanakurumeti27
2020-06-29 11:34
has joined #pact-js

tjones
2020-06-29 11:36
The code sample you have above looks right to me. What problems are you having?

tjones
2020-06-29 11:39
Oh, I see what you mean. You could do: ```before("setup provider general hook", done => { Promise.all([provider.setup(), provider_savedames.setup()]).then(() => { done() }) })```

matt.fellows
2020-06-29 12:04
You?re already using async/await elsewhere, I?d just go for this

matt.fellows
2020-06-29 12:04
```before(async () => { await provider1.setup() await provider2.setup() })```

chandanakurumeti27
2020-06-29 12:20
It didnt help either, same logs again

chandanakurumeti27
2020-06-29 12:21
Thanks @tjones and @matt.fellows for your suggestions

matt.fellows
2020-06-29 12:58
You need to configure your code - the one making the http calls - to point at the different providers

matt.fellows
2020-06-29 12:58
from the outside, it looks like you?re testing at too high a level (i.e. multiple interactions in a single test)

matt.fellows
2020-06-29 12:58
If you can split it into separate tests, things will be much better - easier to maintain, easier to understand, less configuration like this, and it will have more of the good properties of a unit test

chandanakurumeti27
2020-06-29 14:18
yeah i tried to do that as well, but my consumer code base is too complex to split that specific function getsavedgames. so decided to have it like this. and am sure that its just not more than two contracts.

chandanakurumeti27
2020-06-29 14:21
@matt.fellows Can you please provide me some example link for the same, like how to configure my code in such a way that it talks to two different providers. I remember that it is possible in pact jvm by mentioning two provider names inside @pactverification annotation @pactverification(?provider1?,?provider2")

chandanakurumeti27
2020-06-29 14:21
but couldnt find any example for the same in javascript

matt.fellows
2020-06-29 22:06
Presumably your code has a way of configuring where it sends it's http requests. You need to set one to localhost:10000 and the other to localhost:10001 (or whatever you set the ports to)

matt.fellows
2020-06-29 22:07
Make your http client code configurable (maybe thru the use of an env var) and the sent them to the correct URL before you run the pact test

matt.fellows
2020-06-29 22:08
All JS example have this for one provider, it's the same process for more than 1

matt.fellows
2020-06-30 00:03
If you don?t specify the port in the Pact configuration, it will just assign a random available port - you can get the port and configure your http client after calling `setup()` e.g. https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js#L87-L92

abubics
2020-06-30 02:01
Maybe a helpful note here is: this isn't fundamentally a Pact concept. This is a "how you architect your code" concept, and you need to provide interfaces in your own code that allow this kind of configuration. For example, you might have an API client that takes a `baseUrl` constructor parameter. Or `host` and `port` params. This is all up to you as a dev, whether you use Pact or not.

amaljayaraj07
2020-06-30 08:51
has joined #pact-js

chandanakurumeti27
2020-06-30 10:53
Hi , is this possible in pact js as well?


chandanakurumeti27
2020-06-30 10:53
If so , can someone please provide the example link ?

matt.fellows
2020-06-30 10:54
No sorry it's not. You could possibly use request filters/state handlers to attempt the same

chandanakurumeti27
2020-06-30 10:54
Thank you Matt :slightly_smiling_face:

chandanakurumeti27
2020-06-30 10:55
Is it good practice to use requestfilters to change the request body itself?

chandanakurumeti27
2020-06-30 10:56
Anyways thank you for your prompt response :blush:

chandanakurumeti27
2020-06-30 10:57
FYI, my consumer is javascript based one and provider is java based service here

tjones
2020-06-30 10:58
Usually no. Why do you need to do this?

chandanakurumeti27
2020-06-30 10:58
Now, how can i use the pact jvm framework request filters to replace something in the request without using this feature of `"valuefrom providerstate"` ?

chandanakurumeti27
2020-06-30 10:58
very confused now

chandanakurumeti27
2020-06-30 10:59
As i mentioned in the channel, consumer is javascript service where i used pact js framework to write consumer tests and published the contract. Now while running the provider tests i want to replace the request body value with which i get from provider states

chandanakurumeti27
2020-06-30 11:00
and my provider here is java based service wher aam using pact jvm framework to have provider junit tests

tjones
2020-06-30 11:04
Ah, sorry- I didn?t realise this was a follow-on question. My bad.

chandanakurumeti27
2020-06-30 11:05
No prob at all, can you please help me on this , like how can i proceed in this sceanrio as above

tjones
2020-06-30 11:05
I?m not across the state parameters from v3, but the request filters would be done on the provider tests

tjones
2020-06-30 11:05
Usually I implement this with a state handler on the server, setting up the state that is expected

tjones
2020-06-30 11:06
in v2 pacts, there?s conceptually a mapping from the state string to the state you setup, so my state would be something like `"A user exists with user ID 10"`

tjones
2020-06-30 11:07
then you can use a provider state handler to set up the provider

tjones
2020-06-30 11:07
it?s not as elegant as the provider state callback feature

chandanakurumeti27
2020-06-30 11:08
Just to be clear for you, my req in the contract is to `authentication/session/get` which has body like {?sessionuid? : ?7eyudow223"} so before runnning the provider(java service) tests, using `statechange` method, i planned to create a session and i will get `sessionuid` as a response when i create a session in statechange method

chandanakurumeti27
2020-06-30 11:09
And I want to use the `sessiouid` i have in contract with the one which i get form `statechange method` before running provider tests

chandanakurumeti27
2020-06-30 11:10
This is my exact problem right now, as `consumer` and `provider` are using two diff languages `(JS and Java)`, it looks complicated to me

tjones
2020-06-30 11:13
I think it may be straightfoward, but you might not be able to use the provider state value injection feature (so you will just have to use regular provider state strings). I?m in the middle of something at the moment, but I?ll drop back in an hour or so and outline a solution (if someone else hasn?t already)

chandanakurumeti27
2020-06-30 11:14
sure thank you :+1:

chandanakurumeti27
2020-06-30 13:49
@phil.endsley yeah, but not exaclty what i want yet.,can you please help me on this?

phil.endsley
2020-06-30 14:17
I would think it depends on what you're doing. For your case above, setting a sessionUid in the request body, I think it's fine. I would also defer to the docs and core maintainers for best practices. In our case, we modify the request by adding auth headers. We don't include the auth headers as part of our pacts, though. https://docs.pact.io/implementation_guides/jvm/provider/junit/#modifying-the-requests-before-they-are-sent

greg.tyler
2020-07-02 09:46
has joined #pact-js

ravi.mijar
2020-07-03 06:53
has joined #pact-js

sarathojha
2020-07-03 12:33
has joined #pact-js

ravi.mijar
2020-07-07 05:52
Hello.. I'm writing some provider verification tests for a node-express API. I've followed the pact workshop and some other blogs to get to a point where I can run the `npm run test:pact` using jest. It reads the local contract from a directory and tries to run the interactions with the API running in the other terminal. I'm running this on a Windows laptop. However, I constantly see this - ```Unsupported Media Type: unsupported media type application/x-www-form-urlencoded at BodySchemaParser.toSchema```

matt.fellows
2020-07-07 06:07
Hi Ravi!

matt.fellows
2020-07-07 06:07
Glad to see you giving it a go

matt.fellows
2020-07-07 06:07
we may need more information to find out where things are going wrong here.

matt.fellows
2020-07-07 06:08
Did you mean to be sending using `application/json` or is it indeed a form post?

ravi.mijar
2020-07-07 06:21
it isn't a form post.. I fiddled around with some of the values in the contract file, but I get the same error..

abubics
2020-07-07 06:41
It might be a better/easier idea to change the test that outputs the pact file, rather than manually editing the contract :thinking_face:

matt.fellows
2020-07-07 07:15
Can you please share the code or something? As it stands, it?s too hard to understand. It doesn?t look like a Pact specific code, so it could be in your library or something upstream

matt.fellows
2020-07-07 07:15
My guess is that you have body parser that is expected another media type, but is getting `application/x-www-form-urlencoded`.

matt.fellows
2020-07-07 07:16
If you?re editing the contract and it?s not working, there is likely an issue on the provider code

ravi.mijar
2020-07-07 19:51
Last night, I found a possible cause. I haven?t proven it yet. After @abubics suggested to look at the consumer tests, I found that the `http://axios.post` I have is not configured for any headers. That may be a reason why the contract doesn?t have it in the right format or something. Will try to do this later today and post here.

matt.fellows
2020-07-07 22:04
You still need to add the header explicitly in the test to ensure your code behaves the way it should too. Share the test code and we can help

yousafn
2020-07-08 18:22
Hey to any users of the serverless framework. I?ve built a plugin for serverless that will allow you to start a pact stub service by providing a pact file in your serverless.yml file. Currently only supports macosx but will update shortly to download the corresponding binaries for the underlying OS https://github.com/YOU54F/serverless-offline-pact

yousafn
2020-07-08 18:24
Additionally, I?ve also built a lambda template that can be used to host a pact stub service as a lambda function backed by api gateway. https://github.com/YOU54F/serverless-pact This was an iteration over using ecs with docker images containing the pact stub service and a contract file

matt.fellows
2020-07-08 23:31
This is awesome, in fact, I think we?ll try and use it on one of the internal Pactflow systems :stuck_out_tongue:

yousafn
2020-07-09 00:39
I was looking at some of the packages and mechanisms that pact-js/pact-node uses to download the binaries for the various os?s, in the case of serverless-offline-pact. It?s easy with serverless-pact as the lambda runtime is a known quantity. Would be ace to see it used in pact-flow, I?ve still to implement it at work, been caught up in lots of things in the two weeks being back. Will be able to do some cost comparisons against running it in ecs vs lambda over a certain time period. Not that I am too fussed, as I am not paying the bills :slightly_smiling_face:

matt.fellows
2020-07-09 00:57
haha

matt.fellows
2020-07-09 00:58
Sorry, I was referring to the offline pact (we have a few control-plane microservices that could use it)

matt.fellows
2020-07-09 00:58
the serverless-pact deployment would require a lot more testing to ensure all of the features worked reliably etc.

matt.fellows
2020-07-09 00:58
We do actually use ECS for our platform.

matt.fellows
2020-07-09 00:58
100% lambda would be cheaper, I could probably do some back of the envelope numbers, but it would be significant

matt.fellows
2020-07-09 00:59
I think it would probably halve our bill. Our main costs are EC2, RDS and all of the automations on the back of cloudtrail events.

matt.fellows
2020-07-09 01:00
Lambda (which is used for all of the control plane services) is costing us, like, $10's of dollars /mth or something

ayyamuthutechnical
2020-07-09 09:11
@matt.fellows, Currently i am working on doing consumer contract test for frontend using js. While trying to publish in local pact-broker i am getting below issue. Can you please help on this ```[2020-07-09T09:02:25.790Z] INFO: pact-node@10.9.5/14812 on HUNANMBP18: Publishing Pacts to Broker [2020-07-09T09:02:25.791Z] INFO: pact-node@10.9.5/14812 on HUNANMBP18: Publishing pacts to broker at: https://localhost:8090 [2020-07-09T09:02:36.260Z] WARN: pact-node@10.9.5/14812 on HUNANMBP18: Pact exited with code 1. [2020-07-09T09:02:36.260Z] ERROR: pact-node@10.9.5/14812 on HUNANMBP18: Could not publish pact: Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 1 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 2 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 3 of 3 Failed to tag version 15.0 of FrontendWebsite due to error: Errno::ECONNREFUSED - Connection refused - connect(2) for "localhost" port 8090} One or more pacts failed to be published Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" Pact contract publishing failed: Error: Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 1 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 2 of 3 Error making request - Errno::ECONNREFUSED Connection refused - connect(2) for "localhost" port 8090 /Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/standalone/darwin-1.85.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.26.0/lib/pact_broker/client/base_client.rb:101:in `put', attempt 3 of 3 Failed to tag version 15.0 of FrontendWebsite due to error: Errno::ECONNREFUSED - Connection refused - connect(2) for "localhost" port 8090} One or more pacts failed to be published Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" Tagging version 15.0 of FrontendWebsite as "prod" at ChildProcess.<anonymous> (/Users/hunan/pactjspoc/consumer/node_modules/@pact-foundation/pact-node/src/publisher.js:72:40) at Object.onceWrapper (events.js:417:26) at ChildProcess.emit (events.js:322:22) at maybeClose (internal/child_process.js:1021:16) at Socket.<anonymous> (internal/child_process.js:443:11) at Socket.emit (events.js:310:20) at Pipe.<anonymous> (net.js:672:12)```

matt.fellows
2020-07-09 12:25
I mean, that looks pretty clear to me - the pact publish step is unable to communicate to the broker

matt.fellows
2020-07-09 12:26
if you?re running the publish step in docker, but the pact broker is not in the same environment they will not be able to communicate

matt.fellows
2020-07-09 12:26
are you sure the broker is running on port `8090`?

ayyamuthutechnical
2020-07-09 14:03
@matt.fellows, thanks i have mapped the wrong port number. I have changed and now it is working fine. Thanks for the help. Have a great day

jarmy
2020-07-09 20:45
Hi. I?d like some clarification on pact verification regarding `providerVersionTag` vs `providerVersionsTag`. When I use `providerVersionTag: [gitBranch, TEST_ENV]`, I get this warning message ```[2020-07-09T20:17:34.917Z] WARN: pact-node@10.9.4/92598 on jarmy-m02: 'consumerVersionTag' and 'providerVersionTag' have been deprecated, please use 'consumerVersionTags' or 'providerVersionTags' instead``` Followed by this ``` INFO: Tagging version 8e6353a of graphql as "http://DEVTOOLS-561-ja-integrate-pact.io" INFO: Tagging version 8e6353a of graphql as "shared"``` The provider version is updated with those tags in the pact matrix. If I use `providerVersionsTag: [gitBranch, TEST_ENV],` nothing is logged and no tags are applied. Is there a more preferred way to tag the provider version?

matt.fellows
2020-07-09 23:27
You keep referring to `providerVersionsTag` but the error message says to migrate to `providerVersionTags`. Basically, we did something stupid and gave it a dumb name - it should have been a pluralised version of what you were using that?s currently working

abubics
2020-07-10 01:48
the `s` is on `Tags` not `Versions` :slightly_smiling_face: maybe the problem is it's hard to read the diff on that long warning line?

matt.fellows
2020-07-10 02:11
personally, I would just copy what is in the error message - but happy for suggestions!

matt.fellows
2020-07-10 02:11
(also, the TypeScript bindings should give hints if you?re using a _good_ editor :stuck_out_tongue: )

tjones
2020-07-10 04:00
Only if you?re using TypeScript :stuck_out_tongue:

matt.fellows
2020-07-10 04:26
well, VS code should bring the types in for pure JS projects e.g. here is an example JS provider (https://github.com/pactflow/example-provider) and code completion works :ok_hand:

matt.fellows
2020-07-10 04:28
I?m not sure about other editors. But I imagine Sublime and Atom at the very least also have pretty decent support. Heck, it works in my vim

matt.fellows
2020-07-10 04:30
We actually publish the types as part of the release, specifically for non-TypeScript users to get this exact benefit

matt.fellows
2020-07-10 04:31
Not to drag it out, but you can see the types are also sent along with the package to give info to IDEs

tjones
2020-07-10 07:25
Huh, that?s cool

jason
2020-07-14 10:15
has joined #pact-js

chris.mitchell
2020-07-14 12:12
has joined #pact-js

danhitchcock
2020-07-15 14:47
Hi, I've just come back to my pact tests to update them and it appears the JS end(Client) seems to be failing on each test with ``` Cannot open port 1234 on ipv4 or ipv6 interfaces at ../node_modules/@pact-foundation/src/common/net.ts:27:13``` Currently scratching my head, as i didn't change anything in the tests since they last ran successfully.

yousafn
2020-07-15 17:55
whats running on 1234 your client or the mock server? have you got anything running on 1234 anyway? you done a netstat? Assuming this is failing locally on your machine only, if you revert your changes , is it still ok

yousafn
2020-07-15 17:57
1234 is quite a low port number so i?d always choose much higher or random ports and pass it into your client

matt.fellows
2020-07-15 22:43
I would avoid explicit port allocation, if you don't set the port pact will find a free one for you and return it in the call to setup()

matt.fellows
2020-07-16 01:25
It may be a previous pact test that was terminated without being able to clean up processes

matt.fellows
2020-07-16 01:26
if you?re on a mac/linux, you could do this

matt.fellows
2020-07-16 01:26
`lsof -i :1234` to see what process is holding the port

danhitchcock
2020-07-16 09:37
Aha almost forgot, i solved this, and it seemed to have been caused by out of date versions, I might update the port allocation now just to be safe.

chandanakurumeti27
2020-07-16 12:31
Hello there! I am trying run provider tests for my JS based provider service and To make those tests isolated , i wanted to use `nock` which basically intercepts the calls from the provider and sends back required response to my provider while running the pact provider tests. But I can see that the `nock` couldnt intercept the request calls from my provider. Is it because pact has no integration with nock or something am missing? Please respond and am looking forward to any reply or help. This is my provider tests looks like.

chandanakurumeti27
2020-07-16 12:33
And i made sure that my provider service which is listening at localhost:5059 talks to localhost:8088 before running these tests

chandanakurumeti27
2020-07-16 12:34
But getting `"connect refused"` error!

matt.fellows
2020-07-16 12:37
I don't see how your provider is being started in that process, so I'm not sure what effect nock would have

matt.fellows
2020-07-16 12:38
Nock can't intercept request happening in a separate process

chandanakurumeti27
2020-07-16 12:51
I started my provider manually sepeartely, so does that need to be included in test code it self?

matt.fellows
2020-07-16 12:59
Its up to tou. I normally would (see also our examples). If you want to use nock that way though it needs to happen in the same process the provider is running otherwise it will have no effect.

chandanakurumeti27
2020-07-16 13:06
Yeah you are right, when i included the step of starting the provider and pointing that to nock inside the provider tests, then it is working fine

chandanakurumeti27
2020-07-16 13:06
Thank you so much for your help!

chandanakurumeti27
2020-07-16 13:06
Have a great day :slightly_smiling_face:

matt.fellows
2020-07-16 13:10
You too!

os.shulyak
2020-07-17 07:09
has joined #pact-js

tjones
2020-07-18 05:10
For fans of `jest-pact`, I?ve just released 0.7.0, which includes two new DSL functions: `xpactWith` (which skips the tests inside it) and `fpactWith` (which only runs the tests inside it) - these match Jest?s `xdescribe` and `fdescribe`.

yousafn
2020-07-18 08:52
Ace! I?ve heard on .only and .skip but not the x/f prefixed equiv. good work!

tjones
2020-07-18 08:52
Probably, we should actually support both.

tjones
2020-07-18 10:44
Thoughts on `pactWith.only` and `pactWith.skip` ? Also, I realised recently that `pactWith` is potentially confusing, because it?s only for consumer tests. I?m not sure that there?s any extra handling necessary for Jest in a provider test (in fact, a test framework isn?t even necessary for provider verification). Any thoughts on whether it?s worth clarifying this at the DSL?

yousafn
2020-07-18 20:55
It may be, does it cause confusion? the verifier exposed through pact-node is the pact version. Maybe we need to make it clear this is for the consumer side only?

paul.stitt
2020-07-23 09:24
has joined #pact-js

fernando.martin
2020-07-23 12:58
has joined #pact-js

gcoradini
2020-07-23 13:01
has joined #pact-js

poojashree_gopal
2020-07-27 04:00
has joined #pact-js

david025
2020-07-28 16:39
has joined #pact-js

daniel.pritchard
2020-07-28 16:51
has joined #pact-js

guilherme.correa-ext
2020-07-28 19:45
has joined #pact-js

paul.fairless
2020-07-28 21:48
has joined #pact-js

matias.waterloo
2020-07-30 12:22
has joined #pact-js

maciej.olko
2020-07-31 08:01
has joined #pact-js

maciej.olko
2020-07-31 08:01
Hello, is there a way to make pact-js generate v2 specs?

matt.fellows
2020-07-31 08:11
umm? it does generate v2 specs.

matt.fellows
2020-07-31 08:11
or are you referring to the beta branch?

matt.fellows
2020-07-31 08:12
If you are using the message features, that will always generate a v3 pact

maciej.olko
2020-07-31 08:14
thanks for the response, I thought it generates v3 because we see warnings while verifying with pact-python; I have to double check that

matt.fellows
2020-07-31 08:14
hmm let me know

matt.fellows
2020-07-31 08:14
If you are using the standard install `@pact-foundation/pact/@latest` it will generate v2 by default

matt.fellows
2020-07-31 08:15
in fact, it basically cant? generate anything else, unless you are using the ?message? feature

srinivasan.sekar1990
2020-07-31 10:36
has joined #pact-js

maciej.olko
2020-07-31 11:57
for what it?s worth I published a question on #pact-python about the problem: https://pact-foundation.slack.com/archives/C9VECUP6E/p1596195216224800

francis.lobo
2020-08-04 22:48
has joined #pact-js

brendan.j.donegan
2020-08-07 10:39
Hi folks. We're trying to do provider verification using pact-js and we keep getting an error back from the broker, 405. Is our broker too old?

matt.fellows
2020-08-07 10:43
which versions of things are you using? `405` would potentially indicate that a resource doesn?t exist that new code needs which versions of things do you have?

brendan.j.donegan
2020-08-07 11:04
How do I find the pact broker version?

brendan.j.donegan
2020-08-07 11:04
Is it shown anywhere in the UI?

matt.fellows
2020-08-07 11:09
click on the ?API Browser? and you?ll see it in the headers

matt.fellows
2020-08-07 11:09
(or via any direct API call)

brendan.j.donegan
2020-08-07 11:16
Yeah, it's 2.39.0 and we are trying to use the latest version of pact js

matt.fellows
2020-08-07 11:19
ok yeah, so getting on close to 1 year old. There?s a bunch of new things in the broker that we?ll be taking advantage of

matt.fellows
2020-08-07 11:19
were you using any new features in Pact JS or did you just do an upgrade?

brendan.j.donegan
2020-08-07 11:42
This is the first time we are needing to use it for verification

brendan.j.donegan
2020-08-07 11:43
Until now we've only used the consumer side, and the providers have been pact-jvm

matt.fellows
2020-08-07 11:45
Gotcha. It?s likely calling the new pacts for verification feature (which is almost certainly something you want). Any reason why you can?t upgrade the broker?

brendan.j.donegan
2020-08-07 11:48
No reason, just wanted to make sure it would work before going through it :D

brendan.j.donegan
2020-08-07 11:49
Another question while you're here. We have a problem with HTTPS, do you happen to know where certificates need to be put for ruby to find them?

brendan.j.donegan
2020-08-07 11:52
I may as well kill two birds with one stone and get that working while upgrading

matt.fellows
2020-08-07 11:53
when you say you have issues with https, can you elaborate - is it the client calling the server which has a self-signed cert, or is it the broker issuing outbound calls (via e.g. webhooks) to targets with self-signed certs?

matt.fellows
2020-08-07 11:53
`$SSL_CERT_FILE` or `$SSL_CERT_DIR` for the clients (see https://github.com/pact-foundation/pact-ruby-standalone/releases amongst other places)


brendan.j.donegan
2020-08-07 11:54
Basically if we try to communicate with the broker using HTTPS it fails

brendan.j.donegan
2020-08-07 11:54
Webhooks seem to be ok

matt.fellows
2020-08-07 11:54
ok cool, then the above environment variables should do


brendan.j.donegan
2020-08-07 11:55
They are to be set to the path containing the pem file when launching the broker?

brendan.j.donegan
2020-08-07 11:55
Sorry, I should say, the client does have the self signed certificate

brendan.j.donegan
2020-08-07 11:55
But the broker doesn't

matt.fellows
2020-08-07 11:56
the broker doesn?t need the certificate, whatever load balancer / web server in front of it will have the certificate

matt.fellows
2020-08-07 11:56
(e.g. nginx)

brendan.j.donegan
2020-08-07 11:57
I should probably loop back with our infra team and if I have more specific questions I'll come back here

matt.fellows
2020-08-07 11:57
your clients (e.g. Pact JS, which is Ruby under the hood) will need to know that the broker is presenting a self-signed certificate, and have it configured to trust it

matt.fellows
2020-08-07 11:58
if you?re going to bother the infra team, tell them to go out and setup a real (free) certificate using letsencrypt and this problem goes away (they will likely not appreciate said comment)

brendan.j.donegan
2020-08-07 11:58
:joy:

brendan.j.donegan
2020-08-07 11:59
I think I get what you're saying now though, will try that first

brendan.j.donegan
2020-08-07 12:00
So set SSL_CERT_FILE when running, for example the pact-broker command

brendan.j.donegan
2020-08-07 12:07
I understand what was happening now. We run the CI in a standard node docker container which doesn't have the client cert. We'd need to add it in there :+1:

brendan.j.donegan
2020-08-07 12:07
Cheers for the help

matt.fellows
2020-08-07 12:12
you?re welcome

matt.fellows
2020-08-07 12:13
Just note (and I know it?s confusing) that setting the certificate for NodeJS using standard Node config files won?t help - Pact JS actually bundles a Ruby app (which is the main engine) which is the thing that actually talks to the broker. So those env vars are likely still needed)

jacques.murekezi
2020-08-11 16:29
has joined #pact-js

jacques.murekezi
2020-08-11 16:29
Hi All, I have this function: ```saveApplication(details: Application): Observable<any> { return http://this.http.post(`http://localhost:5000/Apply`, details); }``` And I am writing a Pact Test for it (API contract testing) and below is the test: ```describe('ApplicationService contract testing', () => { let provider: PactWeb; let applicationService: ApplicationService; beforeAll(function (done) { provider = new PactWeb({ cors: true, host: '127.0.0.1', port: 9776, logLevel: 'error' }); setTimeout(done, 2000); provider.removeInteractions(); }); afterAll(function (done) { provider.finalize().then(function () { done(); }, function (err) { done.fail(err); }); }); beforeEach(() => { TestBed.configureTestingModule({ providers: [ApplicationService], imports: [HttpClientTestingModule] }); applicationService = getTestBed().get(ApplicationService); }); afterEach((done) => { provider.verify().then(done, e => done.fail(e)); }); describe('Save', () => { const _details: Application = { title: 'Mr', firstName: 'Application', lastName: 'applicant', dob: new Date(1977, 10, 10).toString(), gender: 'M' }; beforeAll((done) => { provider.addInteraction({ state: ' a task to save the dashboard application to mongo', uponReceiving: ' a request to post', withRequest: { method: 'POST', headers: { 'Content-Type': 'application/json' }, path: '/Apply', body: _details }, willRespondWith: { status: 201, headers: { 'Content-Type': 'application/json' } } }).then(done, e => done.fail(e)); it('should call the API to Post the application Content', (done) => { const _response: any = {}; applicationService.saveApplication(_details).subscribe(res => { expect(res).toEqual(_response); done(); }, error => { done.fail(error); } ); }); }); }); });``` The test isn't running when id npm run test or ng test, ut the pacts directory is being created. I don't know what is missing from my configs This is what I have in Karma: ``` frameworks: ['jasmine', '@angular-devkit/build-angular','pact'], plugins: [...., require('@pact-foundation/karma-pact')], pact: [{ cors: true, port: 9776, consumer: "ui", provider: "Apply", dir: "pacts/", spec: 2 }], proxies: { '/api/applications/v1/': 'http://localhost:9776/Apply/' },``` Not sure what I am missing. any help?

joel.whalen
2020-08-11 19:44
How do I match a field that can be either null or an array? Is multiple type checking supported by pact-js?

uglyog
2020-08-11 23:12
The recommendation is to use two tests, one for each value you want in the contract

matt.fellows
2020-08-12 01:25
What do you mean by ?the test isn?t running?? as in, the `it` block isn?t firing? That would imply an issue unrelated to Pact, or at least, if Pact is throwing an error you?re missing it somehow

matt.fellows
2020-08-12 01:25
If it?s creating the Pact directory, that implies the mock server part (the karma) bit _is_ running

matt.fellows
2020-08-12 01:26
I don?t know angular/karma very well, but worth looking to see if Pact is generating any logs (defaults to `./log`)

yousafn
2020-08-12 02:03
are you expecting saveApplication to be hitting the pack mock? ```saveApplication(details: Application): Observable<any> { return http://this.http.post(`http://localhost:5000/Apply`, details); }``` ``` provider = new PactWeb({ cors: true, host: '127.0.0.1', port: 9776, logLevel: 'error' });``` your mock provider is starting up but your app code should be using port `9776` in you test in order for the request to hit the mock

matt.fellows
2020-08-12 02:11
:point_up:

jacques.murekezi
2020-08-12 07:01
@yousafn what do you mean by that?

jacques.murekezi
2020-08-12 07:09
@matt.fellows I have checked there is no ./log folder

matt.fellows
2020-08-12 10:09
Set the log dir in your karma config

matt.fellows
2020-08-12 10:10
That should allow you to specify where the logs are written

matt.fellows
2020-08-12 10:11
I think the angular proxy configuration above redirects to the mock server, am I write? Otherwise what Yousaf is trying to say is that you need to make sure your client code is configured to use the mock service you started, not whatever the default is

matt.fellows
2020-08-12 10:12
Maybe increase loglevel also

jacques.murekezi
2020-08-12 14:46
well the proxy should either use the mocked server. I switched to live server and nothing happened

jacques.murekezi
2020-08-12 14:46
how do you add log level though? not sure if angular allows logs on the webapp level

joel.whalen
2020-08-12 16:02
We?ve had pact implemented in our consumer pipeline (Jenkins) for a few months now, and every so often we get this intermittent error that I cannot seem to reproduce locally at all: ```09:17:35 > jest web/static/scripts/ --runInBand --config jest.pact.js 09:17:35 09:17:38 FAIL web/static/scripts/services/cart/api-cart.service.pact.js 09:17:38 ? Test suite failed to run 09:17:38 09:17:38 TypeError: Cannot read property 'writePact' of undefined 09:17:38 09:17:38 18 | 09:17:38 19 | async teardown() { 09:17:38 > 20 | await this.global.mockServiceProvider.finalize(); 09:17:38 | ^ 09:17:38 21 | this.global.mockServiceProvider = {}; 09:17:38 22 | await super.teardown(); 09:17:38 23 | } 09:17:38 09:17:38 at MockServiceProvider.Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) 09:17:38 at CartEnvironment.teardown (web/static/scripts/unit-tests/pact/pactEnvironment.js:20:43) 09:17:38 09:17:38 [2020-08-11T14:17:37.565Z] INFO: pact-node@10.2.4/35469 on http://injkn31a.vpc.zoro.com: 09:17:38 Creating Pact Server with options: 09:17:38 {"consumer":"zoro","cors":false,"dir":"/pub/jenkins/workspace/zoro.com/development/web/static/scripts/unit-tests/pact/pacts","host":"127.0.0.1","log":"/pub/jenkins/workspace/zoro.com/development/web/static/scripts/unit-tests/pact/logs/mockCartServer-integration.log","pactFileWriteMode":"overwrite","port":8921,"provider":"cart-service","spec":2,"ssl":false} 09:17:38 Test Suites: 1 failed, 1 total 09:17:38 Tests: 0 total 09:17:38 Snapshots: 0 total 09:17:38 Time: 0.454s, estimated 10s 09:17:38 Ran all test suites matching /web\/static\/scripts\//i. 09:17:38 [2020-08-11T14:17:37.744Z] INFO: pact-node@10.2.4/35469 on http://injkn31a.vpc.zoro.com: Removing all Pact servers.``` Usually just rerunning the pipeline fixes it, but it?s quite annoying to have this ?non failure? halt development progress. Anyone else run into this?


matt.fellows
2020-08-13 01:02
I have seen this before

matt.fellows
2020-08-13 01:03
from memory, it?s when the mock service hasn?t started properly in the first place (perhaps due to a timeout or otherwise) and because of the way jest/others do the before/after blocks, it shows up at this moment

matt.fellows
2020-08-13 01:03
If you could pop an issue on Pact JS, we should be able to get better state modelling to prevent it trying to do something to an `undefined`

iesmite
2020-08-14 00:40
has joined #pact-js

iesmite
2020-08-14 00:42
Hello!! I'm having some trouble running the pact workshop(https://github.com/pact-foundation/pact-workshop-js), step10 && step11 :disappointed: After the pact is created on consumer and moving to the provider I'm getting this error: ```Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'product with ID 10 exists' for consumer 'FrontendWebsite' at http://localhost:64378/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/iesmite/github/pact-workshop-js/provider/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/iesmite/github/pact-workshop-js/provider/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:76:11)</pre> </body> </html>``` Any idea to help? Thank you!!!

iesmite
2020-08-14 00:43
I installed the modules using npm ci on root and using MacOS catalina

matt.fellows
2020-08-14 00:45
root??

matt.fellows
2020-08-14 00:45
maybe just check that no other processes are running on that port

matt.fellows
2020-08-14 00:46
and just check for rogue npm processes ensuring they?re all shut down

tjones
2020-08-14 00:54
@matt.fellows I think "root" in this context means the root dir of the project, not the root user

iesmite
2020-08-14 01:04
Yep means the root of the process :grinning:

iesmite
2020-08-14 01:05
Sorry the root of the repository

iesmite
2020-08-14 01:07
I'll check that the weird thing is if I remove the utf8 from the content type the problem is unlocked :grinning: I'll send more logs after dinner ; thanks for you help

iesmite
2020-08-14 01:50
now worked when I did with the pacts loaded from file but failing when I tie with a pact broker I will try to debug the node modules and try to get more info

iesmite
2020-08-14 19:46
k was able to fix the issue, adding `--testTimeout=30000` to the jest execution on the provider fixed the problem. Since my broker was remote 5 second wasn;?t enough to run and the log seems to be a weird issue on the express proxy manifested by the iconv-lite encoding loading `{}` and not able to finde the utf-8 decoder. As always the answer was simple that the manifestation of the problem since that problem was raised since that part of the code was executed after jest tests finished by timout.

matt248
2020-08-18 08:27
has joined #pact-js

tjones
2020-08-18 09:32
Hi Pact friends! `jest-pact` v0.8.1 is out. New since 0.7.0: * Support for jest 26 and non-jasmine test runners * More appropriate peer dependencies (all 24.x and 25.x) * Convenience options `logDir` and `logFileName` in case you want to specify only one of those things Each of these improvements was made in response to an issue reported from a user - so thanks are due to cah-timhuddle, Pascal Betting and Alastair Smith. Keep the feedback coming!

damianattademo
2020-08-19 01:49
has joined #pact-js

vladyslav
2020-08-19 08:25
has joined #pact-js

brendan.donegan
2020-08-19 16:13
has joined #pact-js

brendan.donegan
2020-08-19 16:17
Hi. We are trying to add an interaction where there is an ID in the URL that needs to be replaced as the object which the requests acts on needs to be set up by the state handler. The consumer is using pact-js but the provider verification is using Junit and I cannot see any way to update the url. I have seen https://github.com/DiUS/pact-jvm/tree/master/provider/junit#returning-values-that-can-be-injected but it's a bit vague since it just mentions "There are methods on the consumer DSLs that can provider an expression that contains variables" but I can't find anything in the pact-js docs about this.

uglyog
2020-08-19 22:52
This requires V3 Pact support, which vanilla Pact-JS doesn't support (it is V2).


uglyog
2020-08-19 22:54
One thing you could do, is amend the pact file to make it V3 format and add the appropriate matchers and generators to get it to work.

matt.fellows
2020-08-19 23:49
Just confirming that you can?t use the usual provider states to manage this? i.e. setup a state `ID 1234 exists` in the JS test, and have the JVM test ensure ID `1234` exists, such that you can then make a call to a URL with the ID in it without issues

matt.fellows
2020-08-19 23:49
this is definitely the preferred path

tjones
2020-08-20 02:30
> i.e. setup a state ID 1234 exists in the JS test, and have the JVM test ensure ID 1234 exists, ^ this is what I usually do

tjones
2020-08-20 02:31
That approach has the advantage that you can keep the pact file as opaque

brendan.donegan
2020-08-20 08:41
We can't choose the IDs unfortunately, they are generated by the database

brendan.donegan
2020-08-20 08:43
What if we were to update to the Pact JS beta?

florian.nagel
2020-08-20 09:16
has joined #pact-js

brendan.donegan
2020-08-20 09:24
Am I correct in thinking it's not possible to just modify the HttpRequest url, the same as we do for adding additional headers?

jan.krejci
2020-08-20 18:11
has joined #pact-js

iannsantos8
2020-08-20 18:23
has joined #pact-js

uglyog
2020-08-20 21:52
You'll still need a way to get the ID

matt.fellows
2020-08-21 00:21
> What if we were to update to the Pact JS beta? Yes, PactJS v3 doesn?t support URL generation just yet. It?s actually slated for work in the next few weeks, so I?ve just added it to https://pact.canny.io/feature-requests/p/url-generators

brendan.donegan
2020-08-21 08:19
@matt.fellows do you mind if I DM you about this?

matt.fellows
2020-08-21 08:34
Sure. It's just dinner time here but will be online a bit later and I'll do my best to answer

kristine.jetzke
2020-08-21 15:23
has joined #pact-js

ian.letourneau
2020-08-22 14:00
has joined #pact-js

ian.letourneau
2020-08-22 14:32
Hi there! :wave: Sorry if it's already documented somewhere, but I couldn't find the info in the repository. If I want to contribute to the V3 support for pact-js that is currently in beta, where do I start? What is in progress and what are the next steps? Thanks!

uglyog
2020-08-22 23:23
@ian.mcwilliams there is a branch in the pact-js repo -> `feat/v3.0.0`



matt.fellows
2020-08-22 23:25
Master issue to track/comment progress: https://github.com/pact-foundation/pact-js/issues/413

ian.letourneau
2020-08-23 15:37
Thanks @matt.fellows @uglyog!

heytaco
2020-08-25 03:57
has joined #pact-js

heytaco
2020-08-25 03:57
Hi there! My name is HeyTaco!, and you can use me to give people tacos to show your appreciation. My tacos will spread joy through Slack!

tjones
2020-08-25 04:00
I love tacos!

abubics
2020-08-25 04:11
And they love you too, @tjones :taco:

rcrodrigues39
2020-08-25 11:53
has joined #pact-js

rcrodrigues39
2020-08-26 17:59
Hello Pacts! I'? new here and am looking forward to implement a contract test between a consumer (Angular app) and a provider. I found a very nice example with React (https://github.com/pact-foundation/pact-workshop-js), but I was think if we have something similar with Angular?

matt.fellows
2020-08-27 03:27
Not that I?m aware of sorry, but the principles are the same

matt.fellows
2020-08-27 03:28
If someone were to create one? that?d be ace!


matt.fellows
2020-08-27 03:28
If so, I?ll link to it from our site somewhere

tjones
2020-08-27 03:44
The pattern is the same with an angular app - the usual recommendation is to set up the api layer outside Angular, so Pact doesn't need to know about it

matt.fellows
2020-08-27 03:44
Yep

matt.fellows
2020-08-27 03:44
From memory, angular has opinions on the http framework unlike React where it?s a choose your own adventure

matt.fellows
2020-08-27 03:45
but aside from that it?s the same idea

matt.fellows
2020-08-28 02:18
@tjones I can see you and Neezer have been doing a lot of work on the log stuff - awesome! There is a lot of context there that you have, is it OK if I leave that PR with you?

matt.fellows
2020-08-28 02:18
Was picking up a bit of the OSS today to clean up, but given the effort I don?t want to double up if you?ve got it mentally in hand

tjones
2020-08-28 02:42
Yep! Happy to run with it. I'll have some Pact time this weekend too.

matt.fellows
2020-08-28 02:42
Awesome, thanks Tim

tjones
2020-08-28 02:56
@matt.fellows https://github.com/pact-foundation/pact-node/tree/feat/defer-hal-to-clii I noticed this old branch while clearing out merged ones - is it something we might need?

tjones
2020-08-28 03:00
https://github.com/pact-foundation/pact-node/tree/vgrigoruk-fix/consumer_version_tag_array This looks safe to remove as well - I think (and github thinks) it was merged, but it says it is ahead in commits. Maybe we rebased?

matt.fellows
2020-08-28 03:32
yeah, can both go

lewis.prescott
2020-09-03 12:49
has joined #pact-js

lewis.thorley
2020-09-03 15:30
has joined #pact-js

lewis.thorley
2020-09-03 15:31
Does pact-js work on latest version of node? Before I raise an issue I am having with running pact on my new macbook, I just wanted to check

matt.fellows
2020-09-03 22:55
It looks like we don't test against 14 but I've used it on 14. What issues are you having?

tjones
2020-09-04 06:27
Also, I have just updated the builds so that we now test against 14.

lewis.thorley
2020-09-07 07:31
Was completely unrelated to node version in the end. Just needed to increase the jest timeout.

vittorio.guerriero
2020-09-10 12:43
has joined #pact-js

jagiles
2020-09-10 13:19
has joined #pact-js

vittorio.guerriero
2020-09-10 16:33
Hi :wave: . I've noticed that using `@pact-foundation/pact": "^9.6.0"` with the latest broker version (I believe `2.60.1)` is not working correctly when verifying the pacts. I receive the error `Error retrieving` with status `405`. I've tried to update `@pact-foundation/pact` to the latest version and its working. I'm okay to update, I just would like to understand what's the issue and if we can prevent this kind of breaking changes in the future. I'm quite new to pact flow so forgive me if I post it in the wrong channel or If I misunderstood something about the versioning. Let me know if you need any more informations

matt.fellows
2020-09-10 21:41
We normally make things backwards compatible at the broker level so this disturbing. I wonder if it relates to https://pact-foundation.slack.com/archives/C9VPNUJR2/p1599697864045500

matt.fellows
2020-09-11 06:25

vittorio.guerriero
2020-09-11 06:28
Thanks @matt.fellows . Really dumb question. Does pactflow automatically uses the latest version of pact broker?

matt.fellows
2020-09-11 06:29
not a dumb question at all

matt.fellows
2020-09-11 06:29
There is usually a small lag between the OSS version being published and Pactflow using it, but that lag is usually only a few days

matt.fellows
2020-09-11 06:30
you can see what version Pactflow is on by looking at the response headers to any API call, it has the specific OSS version documented so you can check

matt.fellows
2020-09-11 06:31
```x-pact-broker-git-sha: 4a98db4a x-pact-broker-version: 2.60.1```

vittorio.guerriero
2020-09-11 06:33
Thanks. Ive checked. Its using version 2.60.1. I?ll update pact js to the latest version! Thanks for your help

vittorio.guerriero
2020-09-11 07:04
Just to let you know, ive digged into it a bit more, @pact-foundation/pact-node version 10.3.1 fixed the issue. We were using 10.2.4. Not sure if does help. Release changes. https://github.com/pact-foundation/pact-node/compare/v10.2.4...v10.3.1


matt.fellows
2020-09-11 07:11
Appreciate the follow up, I can?t dig into it right this moment I?m afraid but good to know the latest fixes it.

vittorio.guerriero
2020-09-11 07:15
No problem! Have a nice day!

bethskurrie
2020-09-11 08:53
405 is Method not supported.

bethskurrie
2020-09-11 08:55
That version of the ruby standalone was using a beta version of the API that used a GET request. Since then, that API method support has been removed in favour of the POST method that allows structured data. The feature was only officially released out of beta this week.

bethskurrie
2020-09-11 08:59
The API that supports the pending pact, WIP pacts, and consumer version selectors during verification has been officially released. There are some versions of the pact-ruby-standalone (the underlying shared pact code) that use a beta version of the API that is now no longer supported (the original API used a GET, but the parameters turned out to be too complex, so it was changed to a POST). If you find issues, please upgrade to the latest version of your Pact client library.

vittorio.guerriero
2020-09-11 09:05
Thanks @bethskurrie !

jonathanmorley
2020-09-14 17:01
has joined #pact-js

louisallenfrank
2020-09-15 13:45
has joined #pact-js

mcruzdrake
2020-09-17 14:38
Hello :wave: we are currently using pact-js and so far it?s been great but currently our team is facing some limitations for the following use cases: ? expectations for nullable data fields ? expectations for data field which could vary ( unions/interfaces ) Would it be possible if we can go on a call with someone from the Pact team just to explain our uses cases better? Thanks!

tjones
2020-09-17 23:08
So, usually it's best to have two interactions for a nullable field, rather than allow a field to be nullable in the test

tjones
2020-09-17 23:10
this is because if you have a pact where you could say: ```{ someField: SomeComplexObject | null; }``` the test might pass erroneously if the provider could only produce `null`

tjones
2020-09-17 23:15
it's better to specify this in the state: ```state: '<describe whatever condition would cause the field to be null>', willRespondWith: { body: { someField: null } }``` ```state: '<describe whatever condition would cause the field to be present>', willRespondWith: { body: { someField: { /* ...whatever the object would be in a non-null case */ } } }``` does that make sense?

tjones
2020-09-17 23:16
This is a good (and common) question, so it probably highlights that we can make some documentation improvements

tjones
2020-09-17 23:17
The same situation is true for union types - ideally you want to be explicit in the contract, which may result in more than one interaction for successful responses

abubics
2020-09-17 23:38
All the :taco: for @tjones :3

mcruzdrake
2020-09-18 08:27
I see... Okay thanks @tjones for the input, I will pass this on to our team!

tjones
2020-09-18 08:28
You?re welcome. Happy to chat further if you need

mcruzdrake
2020-09-18 08:39
Yes please that would be great. If there's some availability next week for a call that would be really appreciated!

alex.elmekeev
2020-09-18 10:52
has joined #pact-js

alex.elmekeev
2020-09-18 10:54
:wave: https://github.com/pact-foundation/pact-js#pact-js-v3 states that PactJS v3 is not ready for production but all the "not supported" features refers to pacts verification. Does it mean that it's `production-ready` if it's used only on consumer side?

matt.fellows
2020-09-18 11:47
Mmm probably

matt.fellows
2020-09-18 11:47
There are a few rough edges (e.g. types and things need cleaning up)

matt.fellows
2020-09-18 11:47
But it should work

alex.elmekeev
2020-09-18 11:53
ok, will try to give it a try today

thomas.hibbard
2020-09-18 15:49
has joined #pact-js

mui_ume
2020-09-20 05:07
I got an error TypeError: Must provide the pactBroker argument when I run npm run publish:pact, I recalled this was able to run 2 months back. is there any changes? I am running on pact broker docker at http://localhost:9292

matt.fellows
2020-09-20 05:10
The error seems clear. Please share you code because we can't help with what you've provided

matt.fellows
2020-09-20 05:14
See also howtoask

2020-09-20 05:14
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help


matt.fellows
2020-09-20 06:42
I can't see how that property would have ever worked. The type expects `pactBroker` (see https://github.com/pact-foundation/pact-node)


mui_ume
2020-09-20 06:57
thanks I fixed the line at publishPacts.js pactBroker: process.env.PACTBROKERURL, it works now :slightly_smiling_face:

amicicristiano
2020-09-20 14:20
has joined #pact-js

alex.elmekeev
2020-09-21 08:46
``` Cannot find module '../native' from 'node_modules/@pact-foundation/pact/v3/index.js'``` :thinking_face: am I missing something? @matt.fellows

alex.elmekeev
2020-09-21 08:53
9.x works fine for me

matt.fellows
2020-09-21 08:55
What version was failing?

matt.fellows
2020-09-21 08:55
We technically support 10/12/14

alex.elmekeev
2020-09-21 08:55
`10.0.0-beta.15` `node v12.16.2`

alex.elmekeev
2020-09-21 09:25
:wave: I'm moving our js repo from pact-js 8.x to 9/10.x. One of the issues I have is ```Query must only contain strings.``` that is triggered on the interaction with: ``` query: term({ generate: 'limit=50&status=finished&order=desc', matcher: '^limit=[0-9]+&status=(finished)&order=(desc|asc)$', }),``` Are we supposed to use this now: ``` query: { limit: term({ generate: '50', matcher: '[0-9]+', }), status: term({ generate: 'finished', matcher: '(finished)', }), order: term({ generate: 'desc', matcher: '(desc|asc)', }) }```

alex.elmekeev
2020-09-21 09:37
I'm not sure if those are really the same


alex.elmekeev
2020-09-21 11:32
If this change is not an issue how should I write something like ``` query: term({ generate: `filter[id]=${ID}&fields=uuid%2Cgender`, matcher: '^filter\\[(id|first_name)\\]=[^&]+&fields=uuid%2Cgender$', }),``` I would prefer to not have these as separate interactions cause I will have to add 5 of them with essentially the same everything except this first query param.

alex.elmekeev
2020-09-21 11:42
Or this: ```query: term({ generate: 'page=999999&size=1&sort=created,desc', matcher: 'page=999999&size=1(&sort=created,desc|)', }),```

alex.elmekeev
2020-09-21 11:55
Please let me know if you want me to raise an issue for this.


matt.fellows
2020-09-21 12:42
The _values_ of an object should be strings

matt.fellows
2020-09-21 12:42
but the query shouldn?t necessarily be one

matt.fellows
2020-09-21 12:44
But, aren?t you using the new v3 interface?


matt.fellows
2020-09-21 13:02
ah, i didn?t see your reply, sorry

matt.fellows
2020-09-21 13:02
let me quickly look now - otherwise will tomorrow

matt.fellows
2020-09-21 13:07
Do the install logs indicate any form of failure?

matt.fellows
2020-09-21 13:07
2 things come to mind: 1. Pact is in a nested folder or something, and there is bad relative path finding for that module 2. It wasn?t able to download the native module in the first place

alex.elmekeev
2020-09-21 14:27
I see `native` under `node_modules/@pact-foundation/pact` We have yarn with workspaces and this is how structure looks like: ```/ - node_modules - @pact_foundation - pact - native - subproject1 - I run the `jest` here``` Do you think this is related?

alex.elmekeev
2020-09-21 14:29
I see that we already have https://github.com/pact-foundation/pact-js/issues/483. I've added a comment to it.


thomas.hibbard
2020-09-21 16:01
New to Pact. New to Jest. I?m looking for a little help. I see from the `jest-pact` readme that it > Setups Pact mock service before and after hooks so you don?t have to So does that mean I do not have to have a server running to return data. The example sets a base URL to an actual URL, but to just experiment locally, would I need to set up a server at `localhost:3000/health` (and change the `defaultBaseUrl` to that address)? ```const defaultBaseUrl = 'http://your-api.example.com'; export const api = (baseUrl = defaultBaseUrl) => ({ getHealth: () => axios.get(`${baseUrl}/health`).then((response) => response.data.status), /* other endpoints here */ });``` This does seem to be the case, I just want to double-check it isn?t necessary for me to maintain a test server. I?m guessing the `addInteraction` block determines the body that jest-pact?s mock server will return. Also, I note that when I change the xhr of my service to just resolve without any HTTP at all, eg, ```const defaultBaseUrl = 'http://localhost:3000'; export const api = (baseUrl = defaultBaseUrl) => ({ getHealth: () => Promise.resolve('up'), });``` the test fails with > `Pact verification failed!` > `Actual interactions do not match expected interactions for mock MockService.` > `Missing requests:` > `GET /health` Is it necessary to have the actual endpoint in the service so that the jest-pact lib will know to include that in its mock server, or else why would this fail?

matt.fellows
2020-09-21 21:26
Pact starts a mock service which is where you should configure you API client to send it's requests

matt.fellows
2020-09-21 21:26
So you're right, you don't need to start the provider API but jest pact will start one for you

matt.fellows
2020-09-21 21:27
If you don't make the request it will fail, because it checks your code does what you says it does to ensure the contract only has things in it that your client actually needs/uses

ranjanayush03
2020-09-22 08:40
has joined #pact-js

tyler.mehr
2020-09-22 16:59
has joined #pact-js

ranjanayush03
2020-09-23 05:52
Hello.. I was trying to figure on how to set the SSL_CERT_FILE so does this property needs to set in the environment variables of my system or should this be set inside a pact.rb file . Thanks for your help..

matt.fellows
2020-09-23 07:24
It?s an environment variable e.g. `export SSL_CERT_FILE=?`

ranjanayush03
2020-09-23 07:40
ya I tried that but still the same issue , I provided .cer as the file should it be .pem or something like that.

matt.fellows
2020-09-23 09:49
It needs to be an x509 certificate from memory, i'm not sure the extension matters

ranjanayush03
2020-09-23 10:46
Yeah thanks Mat will look into it.

thomas.hibbard
2020-09-23 14:27
Awesome, thank you very much @matt.fellows

begovic.malik
2020-09-23 14:35
has joined #pact-js

begovic.malik
2020-09-24 10:08
Hi all, first time writting in here and I am really new to PACT topic so would really need your help. This is my test case scenario Environment: VueJS Jest PACT I would like to test API that returns me all users /rest/users. My problem is that response body can be empty array, and ofc. array with existing users. Response body looks like this when thare are users in it ```const USERS_DATA = { id: 123, userName: "Test user", userExternalNumber: "0123456789", userInternalNumber: "12" }``` Thing is that I can write test for both case scenarios, one is when provider returns me users with data, and one is when provider returns me a users as empty array. Here are tests: ```test("users exists", async () => { // set up Pact interactions await provider.addInteraction({ state: 'users exist', uponReceiving: 'get all users', withRequest: { method: 'GET', path: '/rest/users' }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: Matchers.eachLike({ id: Matchers.like(123), userName: Matchers.like("Test user"), userExternalNumber: Matchers.like("0123456789"), userInternalNumber: Matchers.like("12") }), }, }); let url = provider.mockService.baseUrl + '/rest/users'; await axios.get(url).then((response => { if(response.data) { if(response.data.length > 0) { expect(response.data[0]).toStrictEqual( {id: 123, userName: "Test user", userExternalNumber: "0123456789", userInternalNumber:"12"}); } } })); }); test("users do not exists", async () => { // set up Pact interactions await provider.addInteraction({ state: 'users do not exist', uponReceiving: 'get all users', withRequest: { method: 'GET', path: '/rest/users' }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: [], }, }); let url = provider.mockService.baseUrl + '/rest/users'; await axios.get(url).then((response => { if(response.data) { expect(response.data).toStrictEqual([]); } })); });``` When I do consumer tests it pass, but problem is when I do provider test, one of those tests will always fail. How to approach this issue?

alex.elmekeev
2020-09-24 10:13
:wave: You should setup you provider to desired state (the one from `state` in your test).

begovic.malik
2020-09-24 10:18
@alex.elmekeev Good point, did not understand (see) that, I found a documentation and will try to solve my problem. Thank you!

matt.fellows
2020-09-24 10:58
There is an e2e example in the project you could use as a basis


begovic.malik
2020-09-24 11:00
@matt.fellows as I manage to understand so far in stateHandlers I need to define different cases and for example in ?users exists? I need to send (create users) and store them in DB? Also in stateHandlers ?users do not exist? I need to delete everything from DB? Am I on correct path?

matt.fellows
2020-09-24 11:01
something like that, yes

begovic.malik
2020-09-24 11:01
ok, thank you, I will keep digging!

matt.fellows
2020-09-24 11:02
Another option as has been stated elsewhere, you could have a single data fixture that knows how to deal with all states (that?s pretty much impossible for empty data sets though, so at the least you?ll need to be able to load/empty a database or replace a DB with an in-memory replacement)

begovic.malik
2020-09-24 11:03
a oke, so to have separate backend instance with all data needed for tests, and then for example if I need to test fetch single user by ID API I would already know in advance what my ID should be?

begovic.malik
2020-09-24 11:10
PS: Another question, Consumer is javascript and for consumer tests I am using pact-js. Backend is JAVA, is it smart to do also provider test then in pact-js?

matt.fellows
2020-09-24 11:11
most people would use Java on the provider side - basically match the language to the code base

matt.fellows
2020-09-24 11:12
Here is a springboot example with Junit that might be helpful: https://github.com/pactflow/example-provider-springboot


begovic.malik
2020-09-24 11:16
Excellent, now I have better understanding of logic behind PACT and also have a lot of material to cover. Thank you again, will stop with questions until I go trough all of this. Wish you a nice day!

matt.fellows
2020-09-24 11:16
hehe you?re welcome

matt.fellows
2020-09-24 11:16
if you have time, highly recommend one of these workshops :point_down:

matt.fellows
2020-09-24 11:16
howtolearn

2020-09-24 11:16
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

begovic.malik
2020-09-24 11:19
Did go with Pact JS workshop and in it I understand relation between consumer -> broker <- provider. Now I am writing my own tests, and will for sure go again to workshop

matt.fellows
2020-09-24 11:44
Release on the way with fix for this @alex.elmekeev (`v9.12.1`) - https://travis-ci.org/github/pact-foundation/pact-js/builds/729923791

matt.fellows
2020-09-24 11:45
thanks for your patience!

artur
2020-09-24 11:49
has joined #pact-js

alex.elmekeev
2020-09-24 12:15
Thank you @matt.fellows! But I think this comment should be https://pact-foundation.slack.com/archives/C9VBGLUM9/p1600680307014400 :slightly_smiling_face: This thread is about issue in v10 beta which is (I guess?) sill not resolved.

matt.fellows
2020-09-24 12:37
Yes, you're right sorry!


thomas.hibbard
2020-09-24 14:26
I have a service I?m testing that calls Angular?s `http.delete` method. Effectively, before I started to write a Pact test for it, it was just throwing away the server response, which was simply a status code of `204` and the body was empty. Within Pact, what is the preferred way to validate a response with an empty body? I can update my `http.delete` method?s options object so that it will return all the HTTP data, including the status code, something like: ```class MyService { deleteItems(config) { return this.http.delete(config.url, { observe: 'response' }) } } /* boilerplate to inject http, instantiate MyService, etc */ await myServiceInstance .deleteItem(deleteItemConfig) .toPromise() .then((response: HttpResponse<Object>) => { expect(response.status).toBe(204); });``` But is this a useful test? Typically I?d be expecting literal body that I put in a matcher, eg a PUT/POST/etc ```const expectedResponse = { some: 'response' } /* pact config */ willRespondWith: { status: 200, body: Matchers.like(expectedResponse) } /* additional pact config */ it('should update a record', async () => { await myService .put(someConfig) .toPromise() .then(response => { expect(response).toEqual(expectedResponse) }) })``` But I?m having trouble understanding what I should do with DELETE/empty response bodies. Has anyone on our channel got any thoughts/preferences?

phil.endsley
2020-09-24 16:29
Does your angular application care about what the response is at all? Is it checking status code or anything? I can tell you how we handle it within our company. As a general rule, we check status codes so we can handle errors explicitly. So our angular services will throw explicit errors for some status codes. For DELETE, the only thing in our contract is that it responds with 204. For the test, we just make sure the service call returns successfully, we don't assert against anything. Since we don't do anything with the response, but we throw errors on "bad" status codes, returning without any thrown errors is good enough for us. This has worked well for us so far, but I'm also curious if anyone is doing anything else

thomas.hibbard
2020-09-24 21:36
I think this is more-or-less what I was leaning toward really, just would have to update that ?response? option in several places. But yeah I?m still super curious to hear others weigh in, since I am still very new to Pact. Thanks for your input @phil.endsley!

tjones
2020-09-24 23:48
Great answer, @phil.endsley :taco:

abubics
2020-09-25 00:08
I completely agree with @phil.endsley :party_parrot:

abubics
2020-09-25 00:10
As an aside, you might want to be wary of responding with a 204 in a ReST API, because it precludes self-describing metadata (along the trajectory to HATEOAS).

thomas.hibbard
2020-09-25 00:28
@abubics How does it preclude self-describing metadata? (Sorry I?m not really following what you mean) Do you mean the server should be transmitting a different code, or there should be supplemental information in the response body? Thanks!

abubics
2020-09-25 02:05
The short version is: rest describes resources, but http responses don't necessarily model resource contents only. One longer rationale is here: https://blog.ploeh.dk/2013/04/30/rest-lesson-learned-avoid-204-responses/

yann.courtel
2020-09-25 12:21
has joined #pact-js

christopher.lampert
2020-09-25 14:53
has joined #pact-js

collin.johnson
2020-09-29 13:58
has joined #pact-js

thomas.hibbard
2020-10-01 14:38
Is there anyway to supply multiple `given`s for a test?

thomas.hibbard
2020-10-01 14:40
I see there is a `state` property, but can i provide many states?

thomas.hibbard
2020-10-01 21:47
It seems the v3 spec has yet to be implemented. Is there any kind of workaround for providing a more complicated data structure to the `state` than just a string?

uglyog
2020-10-01 23:03
You can try the V3 version. It supports multiple givens.

thomas.hibbard
2020-10-01 23:03
@uglyog I get a ts error complaining about giving it an object and it wants just a string.

uglyog
2020-10-01 23:09
Ok, on the given? Is this for the parameters, or the provider state description?

thomas.hibbard
2020-10-01 23:13
On the consumer, I am trying to add an interaction with this code ``` await provider.addInteraction({ state: {}, // compilation error here providerState: {}, uponReceiving: 'a request to load data', withRequest: { method: 'GET', path: `/api/data`, headers: requestHeaders, }, willRespondWith: { status: 200, body: expectedBodyMatcher, headers: responseHeaders, }, });``` > `Type '{}' is not assignable to type 'string'.`

thomas.hibbard
2020-10-01 23:18
`state` works with a string, but not an object. Also:, > Ok, on the given? I don?t have a property called `given` . Is that done in the provider pact code?

tjones
2020-10-02 03:45
By given, do you mean state? Why do you need multiple states?

alex.elmekeev
2020-10-02 12:19
@thomas.hibbard are you using beta version of v3? It's not working for me though: https://pact-foundation.slack.com/archives/C9VBGLUM9/p1600426474003300 multiple states can be useful in some cases when provider needs to seed a number of completely separate entities for you cause state management on their side becomes a bit more readable

thomas.hibbard
2020-10-02 14:34
@alex.elmekeev yeah, I tried the beta and it didn?t work

thomas.hibbard
2020-10-02 17:17
@tjones Sorry I probably worded that poorly. I just need more complex state than a string to mock provider state.

vitaliy.grigoruk
2020-10-02 18:47
we?re still using v2 version and just serializing state object to a string `state: JSON.stringify(stateObject)`

vitaliy.grigoruk
2020-10-02 18:47
@thomas.hibbard ^ it is ugly, but works for us

thomas.hibbard
2020-10-02 18:48
Yeah that was my fallback solution.

thomas.hibbard
2020-10-02 18:48
I note that if I just do like, ```state: { name: `get_data`, data: ['some', 'list', { of: 'stuff' }], } as any``` the compiler won?t complain and it appears to build the pact file correctly.

thomas.hibbard
2020-10-02 18:49
I?m not a ts expert at all though so I?m not sure what the negative consequences of this might be.

thomas.hibbard
2020-10-02 18:49
Any thoughts?

thomas.hibbard
2020-10-02 18:50
@vitaliy.grigoruk

uglyog
2020-10-02 23:42
Just remember that with TS, it is basically JS with types added. But objects are still plain JS objects in the end. What you're doing is just telling the compiler that that object has no specific type, i.e., it is just a plain JS object.

uglyog
2020-10-02 23:43
You just loose the ability of TS to tell you if you have the correct attributes on the object.

tjones
2020-10-04 23:10
@thomas.hibbard: I wouldn't recommend using `as any`, as Ron says, you lose the ability for the compiler to check that you're using the correct types (which isn't the case here, because provider state is meant to be a string). If it's working, I think it's a coincidence with how the unmarshalling works once it gets into Ruby land. There's no special or additional processing of the state in pact-js

nazar.khmil
2020-10-05 10:34
has joined #pact-js

xandebianchi
2020-10-05 13:05
has joined #pact-js

thomas.hibbard
2020-10-05 14:38
And anyway the broker seems unable to parse the file :disappointed:

dorin.enache
2020-10-05 15:01
has joined #pact-js

thomas.hibbard
2020-10-05 15:14
But I guess I don?t really understand what the big deal is with overriding the type. It?s not like I do anything with the `state` property after I add my interaction, and I am _just_ doing the `as any` on the `state` property, not the entire `addInteraction` config object. I mean it?s all a little academic because, as I say, the broker seems unable to parse it so I guess strings will have to do :wink: but thanks guys for the feedback!

ruth
2020-10-05 18:53
has joined #pact-js

ruth
2020-10-05 18:55
Hi! My tests on the provider side is silently failing and Im not sure why

ruth
2020-10-05 18:55
I wonder if its my configurations, was wondering if anyone would have insight

rcrodrigues39
2020-10-05 21:52
@ruth do you have any error logs? If so, would you mind sharing them here so we can have a better idea of what the problem could be?

ruth
2020-10-05 21:56
Hey! Thanks for responding! I actually got it to work. I had to use `async/await` so it waited till it was finished. Then used `publishVerificationResult: false` so I wouldnt seen any unnecessary information

ruth
2020-10-05 21:57
The one thing I also did was `enablePending: false` so I could see pending tests which was very weird because I would assume `enablePending` when `true` would mean you can run tests that are pending but it looked like that wasnt the case.

uglyog
2020-10-05 23:36
I think we don't really understand what you're trying to do. I assume you have tried to use a JS object in place of the string value for the state? If this is the case, it will not work properly because it will get serialised to a string in the resulting Pact file.

uglyog
2020-10-05 23:37
If you use the V3 beta version of Pact-JS instead, you can use the `given` method which allows structured data to be associated with the state description as parameters.


uglyog
2020-10-05 23:39
For current Pact-JS (9.x), you will need to use `JSON.stringify` so that the object can be serialised correctly, but that would need to then be parsed on the other end

tjones
2020-10-05 23:39
If you're not using the V3 beta, the usual workaround is to use a string for state: ```state: JSON.serialise({ name: `get_data`, data: ['some', 'list', { of: 'stuff' }], })``` Note that you will need to deserialise the string in your provider code

matt.fellows
2020-10-05 23:40
He?s right though - you can literally put anything into state and it does get serialised into the pact file as properly structured JSON - and it comes out the other side too (there is a WIP PR that Honza created that does exactly this)

matt.fellows
2020-10-05 23:40
I haven?t merged it, because I?m not sure it?s the ?right thing?

tjones
2020-10-05 23:41
Pact-JS just passes it off to the ruby binary via http.

matt.fellows
2020-10-05 23:41
yep

matt.fellows
2020-10-05 23:41
I don?t want to encourage it though, because it?s more undefined behaviour that is incidentally helpful, but is likely to stop working

brendan.donegan
2020-10-06 09:45
Hi - we?re using jest-pact (which is fantastic) for writing our consumer tests, but we are now trying to add a test which uses Pact V3. I can?t seem to see any way to make jest-pact use v3 functionality. I?m guessing I probably need to write the test in raw Jest and use PactV3 directly?

yousafn
2020-10-06 10:21
Hey @brendan.donegan if you create an issue on jest-pact, I have a feeling that @tjones might have created a branch for it

brendan.donegan
2020-10-06 10:30
done

tjones
2020-10-06 10:33
I haven?t, but I?m happy to chat about what such a branch might look like, since you?re not the first person to ask this

tjones
2020-10-06 10:33
(I haven?t yet used v3 myself)

yousafn
2020-10-06 10:33
Cheers squire :slightly_smiling_face:

yousafn
2020-10-06 10:33
Me neither, but hearing good things!

brendan.donegan
2020-10-06 10:34
@tjones sure, maybe i can help take a look at that?

tjones
2020-10-06 10:41
That would be excellent! I'm just taking a look at the V3 branch now to see what would be useful

tjones
2020-10-06 10:42
Last time I checked, the API was a bit different, so the setup and teardown thing might not be so useful

tjones
2020-10-06 10:42
my gut is that it would be nicest to be able to say `import { pactWith } from 'jest-pact/v3';`

tjones
2020-10-06 10:49
Also, while I've got you - I'm keen to hear from Pact-JS (and jest-pact) users about how you're doing your config. I'd like to improve the way pact-js gets its config

tjones
2020-10-06 10:50
I'm thinking it might make sense to have a `pact` key in `package.json`, which allows specifying some of the things that would be in every pact config in each test.

tjones
2020-10-06 10:58
Looks very straight forward to add V3...

brendan.donegan
2020-10-06 10:59
cool

tjones
2020-10-06 11:00
Ah, of course. We can't import V3 in standard jest-pact because of peer deps. It'll have to be a separate release.

brendan.donegan
2020-10-06 11:08
that won?t prevent us from using both v3 and v2 in the same project? i mean i could upgrade all our tests to v3 i suppose

tjones
2020-10-06 11:15
I believe you'll be ok, because the V3 branch includes V2

tjones
2020-10-06 11:16
Hm. There's an annoying property where we can't inject the provider as easily, because it needs to be remade on each test

tjones
2020-10-06 11:18
more thought around the API needed. I haven't written any V3 tests yet, so I'm not sure what would be nice

tjones
2020-10-06 11:18
I'll make some sketches just now - but input is very welcome

tjones
2020-10-06 11:32
```pactWith(options, (pactDescribe) => { pactDescribe('some interaction', (provider) => { beforeEach(() => provider .given('Some state') .uponReceiving('Some request') .withRequest({ path: '/whatever/path', method: 'GET' }), ); it('works', () => provider .executeTest((mockserver) => api(mockserver.url).getWhatever()) .then((response) => { expect(response).toEqual({ whatever: 'it-should-be' }); })); }); });```

tjones
2020-10-06 11:33
Something like that, maybe?

brendan.donegan
2020-10-06 12:16
that looks good to me

brendan.donegan
2020-10-06 12:17
only curious why we need to inject pactDescribe?

tjones
2020-10-06 12:17
it remembers the options

tjones
2020-10-06 12:17
I've got something a little cleaner

tjones
2020-10-06 12:19
```pactWith(options, (interaction) => { interaction('some interaction', ({ provider, execute }) => { beforeEach(() => provider .given('Some state') .uponReceiving('Some request') .withRequest({ path: '/whatever/path', method: 'GET' }), ); execute('some api call', (mockserver) => api(mockserver.url) .getWhatever() .then((response) => { expect(response).toEqual({ whatever: 'it-should-be' }); }), ); }); });```

tjones
2020-10-06 12:19
unsure on the names

tjones
2020-10-06 12:20
but this one has the advantage that it is implemented

tjones
2020-10-06 12:20
(just working on publishing)

tjones
2020-10-06 12:22
The implementation is a bit raw, but it should work and will help us discover what the interface should be

tjones
2020-10-06 12:23
I nearly injected custom functions like this for the original jest-pact - I thought it might help people remember to return promises.

tjones
2020-10-06 12:24
I think the `{ provider , execute }` thing could be improved too, abstracting the beforeEach. Maybe. I'm not really sure what's best.

tjones
2020-10-06 12:25
This exercise has highlighted that V3 is missing the object interaction description method

ledinhcuong99
2020-10-06 12:53
has joined #pact-js

matt.fellows
2020-10-06 13:05
description?

matt.fellows
2020-10-06 13:07
do you mean `uponReceiving`?

tjones
2020-10-06 13:15
@brendan.donegan You can now get the V3 interface as above with ```npm install --save-dev jest-pact@0.9.0-beta.v3``` Try it out and see if it works for you. I'd like to consider the interface non-final until a few people have had a play with it. I'm conscious that the original jest-pact was based off a pattern we developed after writing a lot of tests, and this interface is just based on what I thought would work.

tjones
2020-10-06 13:17
@matt.fellows Sorry, I wasn't clear. In the current pact-js, you can add interactions by creating an interaction and using the `.given().uponReceiving()` methods, or by passing a config object that describes everything in the interaction. For ease of conversion to V3, I think we should support both.

matt.fellows
2020-10-06 13:19
gotcha

matt.fellows
2020-10-06 13:19
Amazing stuff Tim!!

matt.fellows
2020-10-06 13:39
@tjones please enjoy a midnight :taco: (why are you up so late?)

tjones
2020-10-06 13:39
practice :wink:

matt.fellows
2020-10-06 13:39
Heck, @tjones have _another_ taco. This time with :tomato: sauce (really!? no :sauce: emoji??)

matt.fellows
2020-10-06 13:39
_nods_

matt.fellows
2020-10-06 13:40
also, daylight savings

ruth
2020-10-06 13:40
hey quick question

matt.fellows
2020-10-06 13:41
Hopefully quick, because I?m in the same TZ as Tim and very shortly my wife will be forcing me off this computer :stuck_out_tongue:

matt.fellows
2020-10-06 13:41
(or pointing me at the couch)

ruth
2020-10-06 13:41
Im using pact in typescript and when import using this `const { Verifier } = require('@pact-foundation/pact');` everything is all good. But when I use `import { Verifier } from '@pact-foundation/pact';` it gives me a typing error

tjones
2020-10-06 13:41
Something I've wanted to do for a while is to automatically get the test name from jest (but you can't). It could be good to swap: ``` beforeEach(() => provider .given('Some state') .uponReceiving('Some request') .withRequest({ path: '/whatever/path', method: 'GET' })``` for ``` setupInteraction("Some request", provider => provider .given('Some state') .withRequest({ path: '/whatever/path', method: 'GET' }) ``` We could do a similar thing with the base jest-pact pretty easily.

ruth
2020-10-06 13:42
```import { Verifier } from '@pact-foundation/pact'; ... const opts = { provider: 'tpt-education-standards', providerBaseUrl: 'http://localhost:3000', pactBrokerUrl: 'https://tpt.pactflow.io', pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: false, providerVersion: '1.0.0', consumerVersion: '1.0.0', enablePending: false, logLevel: 'info', includePendingStatus: true, stateHandlers: { 'I have a standard': () => { // TODO: provider state is handler in beforeAll hook }, 'I have a jurisdiction': async () => { // TODO: provider state is handler in beforeAll hook } } };```

ruth
2020-10-06 13:42
``` Argument of type '{ provider: string; providerBaseUrl: string; pactBrokerUrl: string; pactBrokerToken: string | undefined; publishVerificationResult: boolean; providerVersion: string; consumerVersion: string; enablePending: boolean; logLevel: string; includePendingStatus: boolean; stateHandlers: { ...; }; }' is not assignable to parameter of type 'VerifierOptions'. Type '{ provider: string; providerBaseUrl: string; pactBrokerUrl: string; pactBrokerToken: string | undefined; publishVerificationResult: boolean; providerVersion: string; consumerVersion: string; enablePending: boolean; logLevel: string; includePendingStatus: boolean; stateHandlers: { ...; }; }' is not assignable to type 'ProxyOptions'. Types of property 'logLevel' are incompatible. Type 'string' is not assignable to type '"info" | "trace" | "debug" | "warn" | "error" | "fatal" | undefined'```

ruth
2020-10-06 13:43
Im not sure why its not understanding that ?info? is the part of the LogLevel type. It keeps saying my input is a string when its clear that its one of the options.

tjones
2020-10-06 13:43
Oh yeah. Sorry about this one. It's because the type is an enum.

ruth
2020-10-06 13:43
Sorry for keeping yall up!

matt.fellows
2020-10-06 13:44
I think we do expose an enum for that

tjones
2020-10-06 13:44
We dooo, but I don't think it has been exposed at the root.

matt.fellows
2020-10-06 13:44
ah


ruth
2020-10-06 13:44
so I cant import it that way then

matt.fellows
2020-10-06 13:44
ah yes, nice idea

tjones
2020-10-06 13:45
```import { LogLevel } from '@pact-foundation/pact/dsl/options';```

matt.fellows
2020-10-06 13:45
ugly

tjones
2020-10-06 13:45
This will work, but I don't like it, because what if we move it

tjones
2020-10-06 13:45
I think I'll just go release a fix that exports it at the root.

matt.fellows
2020-10-06 13:45
Easily fixed from our side.

matt.fellows
2020-10-06 13:45
thx

ruth
2020-10-06 13:45
Thank you!!!

matt.fellows
2020-10-06 13:45
did you want Ruth to raise an issue?

tjones
2020-10-06 13:46
Nah, I'll just fix it now.

matt.fellows
2020-10-06 13:46
You have my blessings to ship it without a PR :white_check_mark: approval. Pre approval!

ruth
2020-10-06 13:46
Yall are awesome I appreciate it!

tjones
2020-10-06 13:46
I've been meaning to do it for a while, because we have the same potentially brittle import in jest-pact

matt.fellows
2020-10-06 13:47
_nods_

matt.fellows
2020-10-06 13:47
you are a gentleman and a scholar (I think literally, right?!)

matt.fellows
2020-10-06 13:47
good night y?all :stuck_out_tongue:


tjones
2020-10-06 13:49
Sleep well, Matt!

thomas.hibbard
2020-10-06 14:22
> If you use the V3 beta version of Pact-JS instead, you can use the `given` method which allows structured data to be associated with the state description as parameters. @uglyog The documentation is pretty explicit about not using this in a production env though. Do you think it?s okay?

tjones
2020-10-06 14:22
@ruth I've just released 9.12.2 which exports the types you need at the root. You can then say `logLevel: http://LogLevel.Info,` in your config object.

tjones
2020-10-06 14:24
Also don't listen to GitHub. I released 9.12.2, not Matt :stuck_out_tongue:

thomas.hibbard
2020-10-06 14:24
> I think we don?t really understand what you?re trying to do. I?m just trying to pass a data structure more complex than a string to my producer code, like seems should be available in the Pactv3 spec

tjones
2020-10-06 14:24
....we should fix that

ruth
2020-10-06 14:24
Ill test it out now :slightly_smiling_face:

tjones
2020-10-06 14:26
At the moment, the best way is to marshal any complex type to a string (and back again).

ruth
2020-10-06 14:26
That worked but there are new typing issues. What Ill do is checkout what other typing issues are happening and raise an issue. What is the process to raise an issue?

ruth
2020-10-06 14:27
Also you should go to bed its probably really late for yall

tjones
2020-10-06 14:27
Given the recent uptick in interest in the V3 spec, I think we'll put some concentrated effort into sorting out the remaining V3 spec tasks so it is prod ready.

tjones
2020-10-06 14:27
(especially given that it's Hacktoberfest)


thomas.hibbard
2020-10-06 14:29
Awesome. Stringification is fine for now, but I know my producer-writers are using V3 so yeah it would be awesome to be in lockstep with them. Thanks again.

tjones
2020-10-06 14:29
No worries. I'll take a look in the morning - should hopefully be an easy fix. If you need to import things directly, the folder structure doesn't change often. However, I wouldn't want to rely on it (on my loose todo list is to refactor a bit so the types are easier to reason about internally).

brendan.donegan
2020-10-06 14:30
@tjones this is great, thanks!

tjones
2020-10-06 14:31
You're welcome! I'm heading to bed here, but I'll check back tomorrow for any feedback.

tjones
2020-10-06 14:37
Just quickly, you have `consumerVersion: '1.0.0',`, which I don't think is the right option. You might want: ```consumerVersionSelectors: { pacticipant: 'consumer name goes here', version: '1.0.0' }``` but you probably want to remove it entirely (or use `latest` or another tag)

tjones
2020-10-06 14:38
Similarly I don't think `includePendingStatus` is valid - you might have meant `enablePending`

tjones
2020-10-06 14:39
(also if those properties were copied from an example, let us know which one and we'll correct it)

ruth
2020-10-06 15:46
@tjones Thank you! and everything works :relaxed: The example I was going by was this: https://github.com/pactflow/example-provider/blob/e7cd82fe146a04513ddb41b57e537f00774e0415/src/product/product.pact.test.js#L18 I figured I needed to also add a consumerVersion not realizing looking down that I needed to actually look at https://github.com/pactflow/example-provider/blob/e7cd82fe146a04513ddb41b57e537f00774e0415/src/product/product.pact.test.js#L31 My assumption is that it automatically goes to `latest` so Ill just remove it entirely.

ruth
2020-10-06 15:54
I figured out why the typing was a bit of. I needed to do this: So I created a constant (`LOGLEVEL_INFO` ) that?s type is `LogLevel` so that the constant is an `Enum` and I can use it in the `opts` object ```import { LogLevel, Verifier } from '@pact-foundation/pact'; ... const LOGLEVEL_INFO: LogLevel = 'info'; const opts = { provider: 'tpt-education-standards', providerVersion: '1.0.0', providerBaseUrl: 'http://localhost:3000', pactBrokerUrl: 'https://tpt.pactflow.io', pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: false, enablePending: true, logLevel: LOGLEVEL_INFO, stateHandlers: { 'I have a standard': async () => { // TODO: provider state is handler in beforeAll hook }, 'I have a jurisdiction': async () => { // TODO: provider state is handler in beforeAll hook } } };```

matt.fellows
2020-10-06 23:11
> @uglyog The documentation is pretty explicit about not using this in a production env though. Do you think it?s okay? Sorry for confusion here @thomas.hibbard. It?s actually production ready in the sense that all of the matching works, it?s integration with the pact broker that needs a little work (see https://github.com/pact-foundation/pact-js/issues/413 for the master tracking issue)

uglyog
2020-10-06 23:18
That was added by @bethskurrie when she went on a mad tangent and put that to tell everyone not to use it. But if nobody uses it, we won't ever get the feedback needed to improve it to useable state to be able remove the warning to not use it.

tjones
2020-10-06 23:23
Yes, that will work. If you want a slightly shorter version, you can also tell typescript that the `opts` is a `VerifierOptions`: ```const opts: VerifierOptions = { logLevel: 'info', ....``` Apologies for steering you wrong before - I thought we had an enum and not a string literal type. String literal types are an annoying part of typescript because the compiler gets confused unless you're explicit.

ruth
2020-10-06 23:26
No worries! I didnt see the `VerifierOptions` type, will refactor to use that then. :slightly_smiling_face:

brendan.donegan
2020-10-07 07:54
so, i?m getting an error of a kind i?ve never seen before and there are no logs being created?

brendan.donegan
2020-10-07 07:54
```Test failed for the following reasons: Test code failed with an error: Cannot read property 'matches' of undefined Mock server failed with the following mismatches: 1) QueryMismatch Unexpected query parameter 'assignmentTitle' received 2) QueryMismatch Unexpected query parameter 'studentAssignmentId' received 3) QueryMismatch Unexpected query parameter 'studentAssignmentStatus' received 4) QueryMismatch Unexpected query parameter 'assignmentDueDate' received 5) QueryMismatch Unexpected query parameter 'activityId' received```

brendan.donegan
2020-10-07 07:55
maybe i need to define the query differently?

tjones
2020-10-07 07:55
Hmm. What have you got?

matt.fellows
2020-10-07 07:55
How are you doing it now?

brendan.donegan
2020-10-07 07:55
I just pass a string key=value&key2=value2 etc

matt.fellows
2020-10-07 07:56
v3 pact changes the way it deals with query strings (it internally represents them as a map of string keys to values (`[]`)

matt.fellows
2020-10-07 07:56
so is that your http client doing that, or how you define it in the pact test?

brendan.donegan
2020-10-07 07:56
```.withRequest({ method: 'GET', path: `${API_URL}/${RESOURCE_ID}`, query: QUERY_STRING_PARAMS, headers: new Headers({ Accept: 'application/json', 'Content-Type': 'application/json', Authorization: 'sif', }), })```

brendan.donegan
2020-10-07 07:57
```const QUERY_STRING_PARAMS = 'studentAssignmentId=308983e7-3a84-40e1-9596-6fb44217f39c&activityId=bd37478f-a6c7-440f-8593-d6a20304db7f&studentAssignmentStatus=NOT_STARTED&assignmentTitle=QA+Test+19+Jun+2020+12%3A10%3A24+-+eBookTestData+Student+Dashboard+Due+Today+-+Print+Student+Edition+PDF%3A+HMH+Science+Dimensions%3A+Grade+5&assignmentDueDate=2020-06-19T22%3A59%3A59.000Z';```

matt.fellows
2020-10-07 07:57
aha

brendan.donegan
2020-10-07 07:57
should ?query? be an object?

matt.fellows
2020-10-07 07:58
that may be it, let me check to see how the new API is designed

matt.fellows
2020-10-07 07:58
I think so


tjones
2020-10-07 07:59
The old DSL supports both. I think the new one should too.

matt.fellows
2020-10-07 07:59
so more like: ```query: { "studentAssignmentId": [3089], ... }```

matt.fellows
2020-10-07 07:59
yes probably

matt.fellows
2020-10-07 08:00
I?ve been updating the Golang lib recently over time to support v3 and have been careful to add backwards compatibility for these things

matt.fellows
2020-10-07 08:00
one thing I found is that ? query string behaviour is very framework dependent. but that?s a whole other thing

tjones
2020-10-07 08:00
Also looks to me like query string doesn't support arrays or matchers in V3

matt.fellows
2020-10-07 08:00
for now, you?ll need to convert into that object format

matt.fellows
2020-10-07 08:01
well, it supports arrays because the key value _must_ be an array

tjones
2020-10-07 08:01
```export interface V3Request { method: string path: string query?: { [param: string]: string } headers?: { [header: string]: string } body?: any }```

matt.fellows
2020-10-07 08:01
but it doesn?t appear to support matchers, true. At least, the type definition belies it

brendan.donegan
2020-10-07 08:02
well it works now :smile:

matt.fellows
2020-10-07 08:02
There is an issue relating to the type definitions - I think you _can_ put matchers in things that based on their type, you wouldn?t think you could

matt.fellows
2020-10-07 08:03
sorry yes, Tim and I are looking from a different perspective. Good to hear it?s up and going though :stuck_out_tongue:

brendan.donegan
2020-10-07 08:07
@matt.fellows now i?m just trying to update this test to integrate the url generator. I followed the example you sent me but it fails and doesn?t give very much information

brendan.donegan
2020-10-07 08:08
ignore me. typo (i think)

brendan.donegan
2020-10-07 08:09
there was a typo, but it still fails

brendan.donegan
2020-10-07 08:09
I defined path like this now: ```path: regex( `${API_URL}/\\w+`, `${API_URL}/11112222-3333-4444-5555-66666666`, ),```

tjones
2020-10-07 08:11
I'm nervous about that definition of path

brendan.donegan
2020-10-07 08:13
i think my regex is probably wrong

brendan.donegan
2020-10-07 08:13
it wants to match a UUID

brendan.donegan
2020-10-07 08:14
@tjones any idea where the logs might be now?

tjones
2020-10-07 08:17
I think there are no logs (apologies, I haven't been involved with the v3 work, so I only started looking at it last night)

tjones
2020-10-07 08:18
So, usually what I do is not put matchers in the request, because you want to make sure that the test is "When I ask for X, the provider receives a request for X", and not "the provider receives some kind of valid request"

tjones
2020-10-07 08:20
If for some reason you need this, then it is supported, but I'm not sure if it's supported by V3 yet

brendan.donegan
2020-10-07 08:20
yep, this conversation has been had - it?s been added :slightly_smiling_face:

matt.fellows
2020-10-07 08:20
sorry I?m just making dinner etc. Is this the example you?re looking at https://github.com/pactflow/example-siren/blob/master/consumer/src/__tests__/delete-order.spec.js ?

brendan.donegan
2020-10-07 08:21
yes

matt.fellows
2020-10-07 08:22
ok ta

matt.fellows
2020-10-07 08:22
For reference, Tim, this is the canny ticket: https://pact.canny.io/feature-requests/p/url-generators

matt.fellows
2020-10-07 08:23
Brendan, are you using the `url` generator or the `regex` matcher (what I can see above)? Or are they separate problems you?re running into?

brendan.donegan
2020-10-07 08:23
unfortunately we need to put uuid?s generated by our database in the url

matt.fellows
2020-10-07 08:26
no that?s OK. I noticed that you used the `regex` above but we?re talking about generators, just trying to clarify your example

brendan.donegan
2020-10-07 08:27
i?m not using the `url` generator. i didn?t notice that

matt.fellows
2020-10-07 08:28
I?m confused. I thought you wanted the URL generator :laughing:

brendan.donegan
2020-10-07 08:28
i think i?m the one who?s confused :slightly_smiling_face:

matt.fellows
2020-10-07 08:28
:slightly_smiling_face:

matt.fellows
2020-10-07 08:30
So let?s start fresh (and then I _really_ gotta run :grimacing: ) 1. You have a provider that has UUIDs for IDs so you can?t use a provider state, because they are generated 2. Your consumer just needs to be able to send a message to path with a UUID in it (can be any, but you?ll use a regex to match it) 3. ON the provider side, you need to be able to dynamically substitute in the UUID, right? @uglyog will be able to clarify if the new feature does this. I fear I may have steered you in the wrong direction

brendan.donegan
2020-10-07 08:31
that?s all correct

dothetan.040490
2020-10-07 09:14
has joined #pact-js

brendan.donegan
2020-10-07 19:32
Just wanted to follow up on this. I?m still kind of none the wiser. Is url() the correct construct to use for the path?

waquino
2020-10-07 21:43
Hi, i?m having an issue where the verifications result are not been publish to the broker

waquino
2020-10-07 21:43
not error just not publishing the results

waquino
2020-10-07 21:43
```[2020-10-07T21:04:53.645Z] INFO: pact-node@10.8.1/41 on 744ea855f640: Verifying Pact Files PASS src/cats.controller.pact.test.ts (7.707s) Pact Verification verify the provider ? should verify the provider (1902ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 7.764s Ran all test suites matching /.pact.test.ts$/i. [2020-10-07T21:04:55.491Z] INFO: pact-node@10.8.1/41 on 744ea855f640: Pact Verification succeeded. console.log src/cats.controller.pact.test.ts:73 Verification Ran```

waquino
2020-10-07 21:43
is there any place where i should look for that error?

waquino
2020-10-07 21:45
it has the publishVerificationResult set to true

matt.fellows
2020-10-07 21:47
can you please share your pact test? Are you fetching the pacts from the broker or using local files?

waquino
2020-10-07 21:47
from the broker

waquino
2020-10-07 21:48
```describe('Pact Verification', () => { let catsController: CatsController; let catService: CatService; const pactBrokerUrl = process.env.PACT_BROKER_URL || 'http://localhost:8080'; const pactBrokerUsername = process.env.PACT_BROKER_USERNAME || 'user'; const pactBrokerPassword = process.env.PACT_BROKER_PASSWORD || 'pass'; const providerVersion = process.env.PROVIDER_VERSION || '1.0.0'; const providerUrl = process.env.PROVIDER_URL || "http://localhost:3050"; let publishVerification = true; if(process.env.PUBLISH_VERIFICATION ){ publishVerification = true; } const catExample: Cat = { 'name': 'cat', 'age': 12, 'breed': 'angora', 'color': 'orange' }; const providerBrokerOpts = { logLevel: "trace", providerBaseUrl: providerUrl, pactFilesOrDirs: ['./pacts/'], pactBrokerUrl: pactBrokerUrl, pactBrokerUsername: pactBrokerUsername, pactBrokerPassword: pactBrokerPassword, provider: 'catsProvider', enablePending: true, verbose:true, publishVerificationResult: publishVerification, providerVersion:providerVersion, consumerVersionTag: ['prod', 'test'], stateHandlers:{ 'I have a single cat with color': ()=>{ return Promise.resolve(catExample); }, 'I have a single cat object with color': ()=>{ return Promise.resolve(catExample); } } }; beforeEach(async ()=> { const moduleRef: TestingModule = await Test.createTestingModule({ controllers: [CatsController], providers: [CatService], }).compile(); catsController = await moduleRef.resolve(CatsController); catService = moduleRef.get<CatService>(CatService); console.log(pactBrokerUrl); console.log(pactBrokerPassword); console.log(pactBrokerUsername); console.log(providerVersion); }); describe('verify the provider', () => { it('should verify the provider', async () => { return new Verifier(providerBrokerOpts).verify().finally(() => { console.log('Verification Ran') }); }); }); })```

waquino
2020-10-07 21:49
```? npm run test:pact > pact-provider@0.0.1 test:pact /Users/wellingtonaquino/Documents/wiser-repo/pact-nestjs-provider-sample > jest ".pact.test.ts$" console.log src/cats.controller.pact.test.ts:63 http://localhost:8080 console.log src/cats.controller.pact.test.ts:64 user console.log src/cats.controller.pact.test.ts:65 pass console.log src/cats.controller.pact.test.ts:66 1.0.0 [2020-10-07T21:41:56.223Z] INFO: pact-node@10.8.1/53691 on Wellingtons-MacBook-Pro.local: Verifying Pact Files PASS src/cats.controller.pact.test.ts Pact Verification verify the provider ? should verify the provider (846ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 3.476s, estimated 7s Ran all test suites matching /.pact.test.ts$/i. [2020-10-07T21:41:57.025Z] INFO: pact-node@10.8.1/53691 on Wellingtons-MacBook-Pro.local: Pact Verification succeeded. console.log src/cats.controller.pact.test.ts:73 Verification Ran```

matt.fellows
2020-10-07 21:50
is `PUBLISH_VERIFICATION` definitely set?

matt.fellows
2020-10-07 21:50
maybe comment that out and hard code it to `true`


waquino
2020-10-07 21:51
i even removed the variable and set it manually

matt.fellows
2020-10-07 21:51
`pactFilesOrDirs` is set - is that intended?

uglyog
2020-10-07 21:53
To enable logging, set the LOG_LEVEL environment variable.

waquino
2020-10-07 21:53
is set to pactFilesOrDirs: [?./pacts/?],

matt.fellows
2020-10-07 21:54
yes, don?t do that. The pacts won?t being fetched from the broker if you do that, and therefore won?t have verification results

uglyog
2020-10-07 21:54
Regex on path should work, set LOG_LEVEL=debug and you will see what is being matched and how

waquino
2020-10-07 21:56
if i remove it i get the same :disappointed:

matt.fellows
2020-10-07 21:56
Ron, see point above. Is it fair to say that the new `url` feature won?t actually address Brendan?s needs?

uglyog
2020-10-07 21:58
Yes, `url` was not designed to work with paths, it expects a full URL. Regex should work with paths

matt.fellows
2020-10-07 21:58
Can you please share a reproducible code sample? THis code definitely works, because I ran a demo this morning doing it (see our example consumer/provider)

matt.fellows
2020-10-07 21:58
my guess is that your consumer version tags don?t actuallly match up (i.e. your checking for `prod` and `test` but I can?t see the tags on the broker)

matt.fellows
2020-10-07 21:58
have you published the contract AND tagged with `prod` or `test`?

matt.fellows
2020-10-07 21:59
It actually doesn?t appear to be verifying any pacts

uglyog
2020-10-07 21:59
We should have a way of tracking all the improvements, like supporting string query parameters.

uglyog
2020-10-07 21:59
I'll create a GH issue, unless we have a better way

matt.fellows
2020-10-07 22:00
regex won?t work on the provider side though. He needs the generator feature > We should have a way of tracking all the improvements, like supporting string query parameters. hmm, something like a github issue? ;)

matt.fellows
2020-10-07 22:00
He needs the ?injecting provider states? in the URL feature, I think

waquino
2020-10-07 22:01
i added the pact as part of the contract

waquino
2020-10-07 22:01
not sure how to validate that part on the published version

uglyog
2020-10-07 22:01
Ah, yeah, that has not been exposed to the consumer DSLs yet

waquino
2020-10-07 22:05
i know it worked for me before, i?m going to retry from scratch or create a reproducible flow

waquino
2020-10-07 22:05
and let you thanks for the quick response

matt.fellows
2020-10-07 22:08
thx, I?ll raise that too

matt.fellows
2020-10-07 22:08
Brendan - let?s chat. Apologies for any confusion

matt.fellows
2020-10-07 22:51
If you could share your publishing code, I could help you out

matt.fellows
2020-10-07 22:51
but TL;DR - make sure tags on consumer and provider side align, otherwise the verifier may not catch the pacts you want to verify

matt.fellows
2020-10-07 22:52
Also do the CI/CD workshop in howtolearn

2020-10-07 22:52
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

dagostino.remy
2020-10-07 23:03
has joined #pact-js

waquino
2020-10-07 23:30
the consumer has the tags, but is not publishing those

waquino
2020-10-07 23:30
tags are just latest

waquino
2020-10-07 23:34
if i add latest

waquino
2020-10-07 23:34
it pick it up

waquino
2020-10-07 23:36
thanks : :blush:

matt.fellows
2020-10-07 23:40
Ah, _don?t_ use latest - that?s an anti-pattern. Use something like `main` or `development` . Latest has a special meaning

matt.fellows
2020-10-07 23:40
but good to hear it works!

waquino
2020-10-07 23:41
yes updated the consumer

waquino
2020-10-07 23:42
the issue was that i defined the tags while creating the pacts but not while publishing

matt.fellows
2020-10-07 23:45
what do you mean by ?while creating the pacts??

waquino
2020-10-07 23:55
i?ve created to different task to run ?publish:pact?: ?node publish.js?, ?test:pact?: ?jest \?.pact.test.ts$\??,

waquino
2020-10-07 23:55
publish.js just takes all the pacts an publish to the broker

matt.fellows
2020-10-07 23:56
but you mentioned that you were tagging when creating the pacts, but not publishing - what does that mean sorry?

waquino
2020-10-07 23:58
yes basically when i run the test

waquino
2020-10-07 23:58
is creating the contracts and storing in a folder

matt.fellows
2020-10-07 23:58
how is that ?tagging? it?

waquino
2020-10-08 00:02
i was missing this

matt.fellows
2020-10-08 00:02
yep

abhi.nandan
2020-10-08 06:38
has joined #pact-js

brendan.donegan
2020-10-08 08:18
@matt.fellows that?s ok. I understand now what the issue is anyway. Really appreciate everything you?ve done so far. As I mentioned before, if there?s any way I can jump in and help, I?m cool with that

matt.fellows
2020-10-08 08:25
Thanks, and apologies again

matt.fellows
2020-10-08 08:25
So I think we start up the need as an issue on Pact JS and we can work with you to get it done. Could he a good hacktoberfest item?

brendan.donegan
2020-10-08 08:25
aww, you mean I can?t just update your README with Gr8 Project?

brendan.donegan
2020-10-08 08:26
I can raise an issue. Something like ?url generator needs to support path?s??

matt.fellows
2020-10-08 08:34
@brendan.donegan :point_up: sorry already done here

brendan.donegan
2020-10-08 08:34

brendan.donegan
2020-10-08 08:36
@matt.fellows can I get a rough idea of where to start looking?

uglyog
2020-10-08 08:37
Yeah, that was me

matt.fellows
2020-10-08 09:23
Ron's probably best placed for immediate advice

przemyslaw.dabrowski
2020-10-08 12:36
has joined #pact-js

emiliano.righi
2020-10-08 13:25
has joined #pact-js

yousafn
2020-10-08 17:14
What have I started :joy: going to need a big cup of :tea: before settling down to read this.

yousafn
2020-10-08 17:15
Sounds like you lot are ON IT. kudos, now this is the power of OSS

cariaga.bh
2020-10-08 21:03
has joined #pact-js

matt.fellows
2020-10-08 21:38
Ah yes, this thread got... A little out of hand

campellcl
2020-10-09 00:06
has joined #pact-js

elenitsaa043
2020-10-09 10:00
has joined #pact-js

adriangabrieloros
2020-10-09 11:05
has joined #pact-js

tjones
2020-10-09 12:13
Friends! It's hacktoberfest, and to celebrate, I'm keen to work towards releasing support for V3 specs in Pact-JS. I've created #pact-js-spec-v3 for people to collaborate and discuss implementation. Anyone interested is welcome to join

tjones
2020-10-09 12:22
Also tacos for both @brendan.donegan and @yousafn for the activation energy required to start looking in to this :taco:

brendan.donegan
2020-10-09 12:30
i just had lunch, but thanks :slightly_smiling_face:

ruth
2020-10-09 13:03
This is probably a realy silly question, but I am confused on how to download schema from pactflow to the provider. I?ve been googling it and most articles I found says I need to do it but doesnt give me guidance on how.

antonello
2020-10-09 13:06
HI @ruth, just to clarify, you have a provider written in Javascript and you would need to verify a pact that you have published to pactflow?

ruth
2020-10-09 13:07
So I did the verification part.

ruth
2020-10-09 13:08
The purpose of my question is that if the provider changes there are tests to make sure that it still does what the consumer expects

ruth
2020-10-09 13:08
so I figured I would need to download the schema and then test against that.

ruth
2020-10-09 13:09
but now sure how to download the schema into the provider so I can make those tests.

antonello
2020-10-09 13:10
so it?s the provider verification test that you are talking about. you have written a consumer test and published the pact to pactflow?


antonello
2020-10-09 13:10
(I don?t know what you mean by schema, as there are no schemas in Pact, so I imagine that you meant the pact file between your consumer and provider)


ruth
2020-10-09 13:11
yes the pact file! I believe its a JSON schema.

ruth
2020-10-09 13:12
Yep and I did all those steps


antonello
2020-10-09 13:13
I?m not familiar with that I?m afraid

ruth
2020-10-09 13:13
ah okay, no worries!

phil.endsley
2020-10-09 13:18
In the context of that blog series, Pact is not a schema-based contract test. It is a code-based contract test. That series was talking about other alternatives to do contract testing besides Pact. Ex: For something more provider driven rather than consumer driven


ruth
2020-10-09 13:19
ah okay!

phil.endsley
2020-10-09 13:19
> The purpose of my question is that if the provider changes there are tests to make sure that it still does what the consumer expects If you have pact tests for the consumer and provider, your provider build should inherently do this. Each time the provider builds, it should be downloading the pacts from pactflow and running verifications against it

phil.endsley
2020-10-09 13:20
If you had a breaking change in your provider, such that your services are returning unexpected data, your provider build should fail

ruth
2020-10-09 13:20
got it! So essentially because I verfied it will state if there is any difference between the two and create a diff.

ruth
2020-10-09 13:22
So that means I dont have to create any tests because verifying does it for me. The only tests i need to create is on the consumer side.

phil.endsley
2020-10-09 13:22
When you verify, if the response from the provider doesn't match the expected response defined by the consumer, your test should fail. When that happens, you should get a diff of what was expected vs the actual, similar to other unit tests

ruth
2020-10-09 13:22
That makes sense

antonello
2020-10-09 13:22
no, @ruth - that is incorrect, you need tests both on the consumer and provider side.

antonello
2020-10-09 13:23
if you use the pact broker, the consumer will have some tests that aim at creating the pact and upload it to the broker

antonello
2020-10-09 13:25
the provider will also have tests to ensure that it is indeed compatible with what the consumer expects. if you use the pact broker, the provider tests will have to get the pact from the broker.

antonello
2020-10-09 13:25
The pact is a json file. If you?ve written consumer tests, you will be able to see what?s inside if you?re curious

phil.endsley
2020-10-09 13:25
There's a pact-js workshop that goes through each step of the workflow https://github.com/pact-foundation/pact-workshop-js

ruth
2020-10-09 13:26
thanks Ill check this out now!

cariaga.bh
2020-10-09 14:10
Hi everyone, thanks for this great work. I have a weird issue, im trying add pack consumer tests on one project. Locally works great but on gitlab ci don't works. This is the error: ```ERROR: pact-node@10.10.1/118 on runner-wcLUYPAX-project-2580-concurrent-0: Pact Binary Error: XXX/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir XXX in PATH, mode 040777``` This occurs on docker on Gitlab Runner (docker image: node:14-stretch) The ruby ??standalone need some user or files configuration for work? package.json: `"@pact-foundation/pact": "^9.12.2","jest-pact": "^0.8.1",` Can someone help me? (if need to create a github issue tell me) Thanks a lot :smile:

tjones
2020-10-10 04:28
There's a semantic difference that is worth pointing out: * Consumer pact _tests_ on the consumer side are usually run from a unit testing framework * Provider pact _verification_ on the provider side is a kind of test, but doesn't need to be run from a unit testing framework (I usually don't, but you can if it is easier for you).

matt.fellows
2020-10-10 09:15
I've seen the insecure issue before but I don't think that's the real issue. Could you please share the full log at debug level?

cariaga.bh
2020-10-10 14:42
Thanks for the reply @matt.fellows this is the file. For some reason (that I don't know) when i'm commit the change for get the logs in debug level its works although the warning exists

matt.fellows
2020-10-10 23:16
Thanks

matt.fellows
2020-10-10 23:16
The problem seems to be that it can't assign the port

matt.fellows
2020-10-10 23:16
`Error: Cannot assign requested address - bind(2) for "::1" port 1234`

cariaga.bh
2020-10-10 23:23
Wow! I missed it. I need talk to the devops to know if exists some limitation on for the container on gitlab runner. Thanks a lot!

matt.fellows
2020-10-10 23:57
Of you don't specify a port, pact will find an available one for you and return it in the call to `setup`. Also, you may need to test what host/ip to bind to

matt.fellows
2020-10-10 23:57
E.g. 127.0.0.1

sh.ilgam_pact
2020-10-11 16:13
has joined #pact-js

abubics
2020-10-12 01:03
:taco: for @antonello & @phil.endsley :party_parrot: Always so helpful~*

anastasiia.bielik
2020-10-12 11:13
has joined #pact-js

elenitsaa043
2020-10-12 11:30
Hello all! I have a strange issue appearing when running my pact tests (consumer side). From a quick search I haven?t found any relevant response, but please feel free to forward me to any similar issue? When executing the contracts I get this error warning: ```RROR: pact-node@10.10.1/34891 on **: Pact Binary Error: WARN: No content type found, performing text diff on body``` The tests pass, because the text comparison is verified, but I have added the relevant headers in ```willRespondWith``` headers ```Accept: 'application/json' or 'Content-Type' = 'application/json'``` and it seems to ignore it! Any ideas??

brendan.donegan
2020-10-12 11:57
we have this issue too. would love to know what causes it

matt.fellows
2020-10-12 12:40
Hmm can you please share your code?

matt.fellows
2020-10-12 12:41
(or the pact file actually)

elenitsaa043
2020-10-12 12:58
sure !

elenitsaa043
2020-10-12 12:59
``` it('verify request for generated questionnaire', async () => { await provider.addInteraction({ state: 'send a successful request', uponReceiving: 'A generated questionnaire', withRequest: { method: 'POST', path: `/v1/generate`, headers, body: startRequestBodyShort }, willRespondWith: { status: 200, headers : { Accept: 'application/json' }, body: responseBodyShort } }); await generateScript(startRequestBodyShort.job, 1); return provider.verify(); });```

elenitsaa043
2020-10-12 12:59
I have also tried with ```'Content-Type' = 'application/json'```

elenitsaa043
2020-10-12 12:59
but none of them worked

elenitsaa043
2020-10-12 13:01
I keep taking the same warning error in all cases : ```[2020-10-12T10:42:23.225Z] ERROR: pact-node@10.10.1/34891 on **: Pact Binary Error: WARN: No content type found, performing text diff on body```

matt.fellows
2020-10-12 13:01
What are the request headers?

matt.fellows
2020-10-12 13:02
Accept is definitely the wrong response header though, content-type is what you want

matt.fellows
2020-10-12 13:02
Accept is a request header

elenitsaa043
2020-10-12 13:02
the request headers is just a bearer

elenitsaa043
2020-10-12 13:02
yes, i ve tried with just content-type but it didnt work

matt.fellows
2020-10-12 13:03
Try content type on the request too. It might be warning about that side of the test?

matt.fellows
2020-10-12 13:03
Otherwise I'll take a look with fresh eyes tomorrow morning on the e2e example test in pact JS repo

phil.endsley
2020-10-12 13:03
Quotes around content-type? ```headers : { 'Content-Type': 'application/json' },```

elenitsaa043
2020-10-12 13:04
yeap

elenitsaa043
2020-10-12 13:04
thanks!

aleksmarg
2020-10-12 13:05
has joined #pact-js

deepika.krishnakumar
2020-10-12 15:03
has joined #pact-js

anbansal27
2020-10-12 23:02
has joined #pact-js

olarrmide
2020-10-13 00:49
has joined #pact-js

olarrmide
2020-10-13 00:49
Hi Folks, anyone have experience successfully running pact-node from a windows mapped network drive? I am able to install the npm packages but starting my tests throws this error: _CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows Directory._

matt.fellows
2020-10-13 00:50
why are you running pact-node on a mapped network drive, are you able to elaborate?

olarrmide
2020-10-13 00:53
Corporate Infosec requirements. The ruby executable bundled with the Pact libraries is blocked from running by policy restrictions, when I install directly to my local drive. However, the network location has less restrictions- its whitelisted to allow the ruby.exe run.

olarrmide
2020-10-13 01:02
I?d like to know early enough if it?s possible so I know if I need to find another way. Already invested a whole day into finding a solution.

matt.fellows
2020-10-13 01:02
I?m sorry, I just have no idea here

matt.fellows
2020-10-13 01:03
In theory it should be, but there are limitations on how things can run on network drives (I have previous experience doing this, and it is painful)

matt.fellows
2020-10-13 01:03
Could you please do me a favour, and see if https://github.com/pact-foundation/pact-js#pact-js-v3 solves your issue with permissions?

matt.fellows
2020-10-13 01:03
It?s a new version of Pact

matt.fellows
2020-10-13 01:04
It implements more of the v3 features, but doesn?t fully integrate with all of the Pact Broker features just yet

matt.fellows
2020-10-13 01:04
If you can run it locally, and describe the usage you have, it might be a good option. In the next few months, it should come out of beta

olarrmide
2020-10-13 01:08
Thank you. I?ll check it out.

abubics
2020-10-13 02:14
If the security team is heavy-handed and unmoving, you'll always have trouble :sob: One workaround might be to run dev in docker, as long as they'll allow it. Can unblock a lot of use cases, but has a performance & maintenance cost.

matt.fellows
2020-10-13 02:15
In my experience, places that don?t like you running abritrary binaries usually restrict docker also.

abubics
2020-10-13 02:16
just let me run something sandboxed, how do you expect me to get any work done :upside_down_face:

abubics
2020-10-13 02:17
as I said (unfortunately): > you'll always have trouble :sob:

matt.fellows
2020-10-13 02:18
Last time I worked at a place that locked docker, this is what happened:

matt.fellows
2020-10-13 02:19
We used docker for builds. They couldn?t test the build locally, so just edited the build script directly from bitbucket. There are many pages of scrolling :exploding_head:

matt.fellows
2020-10-13 02:19
anyway, I digress

abubics
2020-10-13 02:55
rip in peace

olarrmide
2020-10-13 03:16
You?re right, Docker isn?t available.

abubics
2020-10-13 04:45
The actual solution is to isolate dev environments properly so you don't have to trust them :innocent: But that's probably a big effort, if no one's started on it yet.

abubics
2020-10-13 04:45
Until then, that policy only slows people down.

abubics
2020-10-13 04:48
(and docker would actually help in that case, because you can throw away the fs layer touched by pact, except for the one JSON file, then everything is secure like you want)

prabhakar.thippa
2020-10-13 04:58
has joined #pact-js

matt.fellows
2020-10-13 05:59
That argument only works with rational people, not irrational policies :stuck_out_tongue:

giadinhluong
2020-10-13 06:24
has joined #pact-js

matt.fellows
2020-10-13 07:49
From what I can see, and glean from a glance at the underlying matching code, is that the _request body_ doesn?t have a content-type associated with it

matt.fellows
2020-10-13 07:50
I can make that error show up if you don?t specify a content-type for the request headers

matt.fellows
2020-10-13 07:51
the response headers are fine in your consumer test - they aren?t being matched by Pact yet (they just get returned as you ask)

matt.fellows
2020-10-13 07:51
Only when you verify the provider does the matching of the _response_ body get done

matt.fellows
2020-10-13 07:51
So at this stage, I?m 90%+ sure that it?s just that you?re missng a content-type on the request body

matt.fellows
2020-10-13 07:53
the `content-type` header is used to signal the content type being sent (in this case, by the consumer). The `accept` header is about what content types the receiver can deal with. The `accept` header makes no sense on the provider - it?s too late, the consumer has already made the request and can?t alter the `content-type`. So you can remove it from the `willRespondWith` block. In your case, _both_ the consumer and provider should specify a `content-type` (and they should both by something like `application/json`)

matt.fellows
2020-10-13 07:53
cc @brendan.donegan - would be ideal to confirm that for you too

matt.fellows
2020-10-13 07:54
After all of that, it?s actually not really a problem either, unless you?re applying matching rules to the _request_ (most times you don?t need to, because you can control what the consumer can send in a unit test - so the warning is just that).

elenitsaa043
2020-10-13 07:57
Ok, thanks a lot for your reply!

elenitsaa043
2020-10-13 07:57
I ll try that!

borsuk.artem034
2020-10-13 08:13
Hello, any progress for this issue? https://github.com/pact-foundation/pact-node/issues/179 maybe somebody find better solution?

pavank
2020-10-13 08:41
has joined #pact-js

matt.fellows
2020-10-13 09:03
Not yet, albeit it is being dealt with in the v4 spec

stephane.meng
2020-10-13 09:06
has joined #pact-js

abirlal.bose
2020-10-13 09:45
has joined #pact-js

alex.elmekeev
2020-10-13 17:24
:wave: do you have somewhere handy an example/guide of migration of existing v2 consumer contracts to v3? I've just noticed that API has changed quite significantly :thinking_face: 1. I'm not sure about `setup` / `finalize` replacement 2. what is the best way to change `addInteraction` to new methods. Right now I'm thinking about some wrappere for PactV3 We have ~400 contracts in v2 and I really don't want to rewrite those :slightly_smiling_face:

uglyog
2020-10-13 22:49
This has been raised as an issue, and something we need to address. Currently, I'm still working on getting it to a non-beta form before we can work on that. However, it has a totally separate name space and contains all the V2 code which can be used along side it, so you can leave your existing tests as is, and only convert some or new ones.

alex.elmekeev
2020-10-14 08:01
can you please share the link to the issue so I can follow it? I've failed to find it in pact-js repo :thinking_face:

mateusz.mrzyglod
2020-10-14 09:32
has joined #pact-js

cathleen.yuan
2020-10-14 11:16
has joined #pact-js

ramana.jaladurgam
2020-10-14 16:10
has joined #pact-js

rodrigocs
2020-10-14 17:55
has joined #pact-js

alik.berezovsky
2020-10-14 18:38
has joined #pact-js

a.robecke
2020-10-14 19:24
has joined #pact-js

mikahchapman
2020-10-14 21:47
has joined #pact-js

uglyog
2020-10-14 22:13
Sorry, I mean someone previously raised it as causing them an issue, not that they created a Github issue for it :smile:

uglyog
2020-10-14 22:13
Please raise a GH issue for it

tjones
2020-10-15 00:28
@alex.elmekeev We haven't finalised the API for V3, I'd like to make sure migration is as smooth as possible. One specific example is that I'd like to still support `addInteraction` with an object (at the moment, migration is easier for people using the current API with the builder pattern, but harder for people using it with an object - which I think is probably the common case)

hem_kec
2020-10-15 00:44
has joined #pact-js

dothetan.040490
2020-10-15 02:22
@dothetan.040490 has left the channel

alex.elmekeev
2020-10-15 08:03
I will hold off with issue creation then if it's anyway a desire to keep "backward compatibility" of API

marco.cordeiro
2020-10-15 10:54
has joined #pact-js

betty.he
2020-10-15 14:32
has joined #pact-js

uglyog
2020-10-16 07:59
:point_up: Array contains matcher! :tada:

alex.elmekeev
2020-10-16 08:11
v3 only, right?

francislainy.campos
2020-10-16 08:11
has joined #pact-js

francislainy.campos
2020-10-16 08:27
Hello, good morning. I'm going through this tutorial https://katacoda.com/mefellows/scenarios/pactflow-getting-started-json on how to write pact with javascript (I know how to do it in java but first time with js) but am getting an error that says `before is undefined` even though I have mocha installed as a dev dependency as per the sample package.json file and also globally. I then tried it with `beforeEach` instead which seems to work a bit better but I then get this error instead saying `PopsicleError: Unable to connect to "http://127.0.0.1:59166/interactions"` Any ideas please?


francislainy.campos
2020-10-16 08:29
Thank you.

matt.fellows
2020-10-16 09:05
Yes

tamer
2020-10-16 09:08
has joined #pact-js

matt.fellows
2020-10-16 10:32
How are you running the pact test?

matt.fellows
2020-10-16 10:32
It looks like a react project, so there is probably Jest in there somewhere

francislainy.campos
2020-10-16 10:33
npm run test consumer

matt.fellows
2020-10-16 10:33
I tried running the `npm run test:consumer` and it doesn?t do anything, because the pact file is not where that command is expecting

francislainy.campos
2020-10-16 10:33
I'm using this `npm run test consumer` without the :

matt.fellows
2020-10-16 10:33
what does that do?

matt.fellows
2020-10-16 10:34
ah

matt.fellows
2020-10-16 10:34
that?s going to run the react tests

matt.fellows
2020-10-16 10:34
that command doesn?t do what you think it does

francislainy.campos
2020-10-16 10:34
No?

francislainy.campos
2020-10-16 10:35
Okay, I'll try your version

matt.fellows
2020-10-16 10:35
no, if you don?t know why, I suggest go and find somebody in your organisation who does and pairing with them for a bit

matt.fellows
2020-10-16 10:36
With respect, it shows that you don?t understand the node ecosystem (which is great that you?re giving it a go!) - but this will be the first of many pain points.

matt.fellows
2020-10-16 10:36
It would be like if I had to deal with Maven :stuck_out_tongue:

francislainy.campos
2020-10-16 10:36
I wear glasses so it may be that I missed the : as am without them at the moment.

francislainy.campos
2020-10-16 10:36
But yeah, it's the first time I'm trying to run tests like this

francislainy.campos
2020-10-16 10:37
But it's a personal project, and don't have a buddy to pair with.

francislainy.campos
2020-10-16 10:37
So trying to figure it out here.

matt.fellows
2020-10-16 10:38
ah ok

matt.fellows
2020-10-16 10:38
`"test:consumer": "mocha --exit --timeout 30000 src/pact/consumer.pact.spec.js",`

matt.fellows
2020-10-16 10:38
that fixes your immediate issue, anyway

matt.fellows
2020-10-16 10:38
the path to the pact file was incorrect

matt.fellows
2020-10-16 10:38
I ran it locally just now

francislainy.campos
2020-10-16 10:38
Thank you. I'll check it here.

matt.fellows
2020-10-16 10:40
here?s the exact patch

francislainy.campos
2020-10-16 10:47
Yeah, it worked. Thanks once again Matt (now in the Javascript word).

francislainy.campos
2020-10-16 10:48
Happy Friday.

mario.gioiosa
2020-10-16 18:57
has joined #pact-js

abubics
2020-10-19 05:17
TESTING BUILD :party_parrot:

lior.baber
2020-10-19 07:33
has joined #pact-js

jeffbdye
2020-10-19 17:10
has joined #pact-js

dmcgill50
2020-10-19 19:16
has joined #pact-js

jace
2020-10-19 19:22
has joined #pact-js

campellcl
2020-10-19 22:46
Hey all, @matt.fellows and @bethskurrie I'm back again on the JS side of things. Running into open issue: https://github.com/pact-foundation/pact-node/issues/100 is the V3 branch for Pact-JS that you mentioned `feat/v3.0.0`?

matt.fellows
2020-10-19 22:47
:wave:

matt.fellows
2020-10-19 22:47
yes that?s correct

campellcl
2020-10-19 22:49
So we need to do a manual build of Pact somehow with the `feat/v3.0.0` branch? We can't pull it down via NPM, right?

matt.fellows
2020-10-19 22:49
no, it?s available by NPM


matt.fellows
2020-10-19 22:49
`npm i @pact-foundation/pact@beta`

matt.fellows
2020-10-19 22:50
Ron was releasing some things yesterday, but pretty sure that tag still works to get the latest in that stream

campellcl
2020-10-19 22:54
Phew. Didn't want to have to build manually and bypass NPM. Great, thanks! I'll try that out.

matt.fellows
2020-10-19 22:55
hahah yes, that would be a pain

campellcl
2020-10-19 22:55
Still getting that problem with the beta version: ```Error: C:/Users/ccamp/Documents/GitHub/MITEPF/JobManagementServiceV3/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.3/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.32.1/lib/pact/provider_verifier/app.rb:3:in `require': cannot load such file -- pact/provider_verifier/provider_states/add_provider_states_header (LoadError)```

campellcl
2020-10-19 22:55
=(

matt.fellows
2020-10-19 22:56
The beta still includes the old DSL, so that means you?re not using the `v3` interface

uglyog
2020-10-19 22:56
I think that issue may be on install?


matt.fellows
2020-10-19 22:56
it?s a new namespace

matt.fellows
2020-10-19 22:56
`const { PactV3, MatchersV3 } = require("@pact-foundation/pact/v3")`

campellcl
2020-10-19 22:57
Ah, missed that. Thank you!

matt.fellows
2020-10-19 22:57
instead of something like `const { PactV3, MatchersV3 } = require("@pact-foundation/pact")`

campellcl
2020-10-19 22:58
Message Pacts in V3?

matt.fellows
2020-10-19 22:58
not yet

matt.fellows
2020-10-19 22:58
I?m currently adding it to Pact Go to see how to do it with the new reference library

matt.fellows
2020-10-19 22:59
I could be wrong, Ron would know.

matt.fellows
2020-10-19 23:00
The windows pathing issue can usually be resolved by moving closer to the root of the volume e.g. rather than `c:\foo\baz\some\deep\nested\folder` move to `c:\pact`

uglyog
2020-10-19 23:01
No JS V3 DSL for messages yet

campellcl
2020-10-19 23:08
Moving what closer to the root of the volume? The test script itself that leverages Pact? This is an internal Pact error. We are trying to pull files from the remote broker. So if anything it would be the internal `node_modules` file paths that are causing the violation.

matt.fellows
2020-10-19 23:09
So the issue is that within the node modules folder of your project dir `C:/Users/ccamp/Documents/GitHub/MITEPF/JobManagementServiceV3/`

matt.fellows
2020-10-19 23:09
there is an internal Pact library that nests within there. The path > 255 characters, which causes that problem

matt.fellows
2020-10-19 23:10
There are 2 known fixes (at least) that I know of: 1. `C:/Users/ccamp/Documents/GitHub/MITEPF/JobManagementServiceV3/` -> `c:/project` (move the project closer to the root of the volume, so the path isn?t as long) 2. The windows registry fixes documented in several pact issues. They could be out of date now with newer versions of Windows, but apparently there is some way to remove this arcane limitation

campellcl
2020-10-19 23:11
Right, I'm just not sure moving that `node_modules` up a few directories will be enough to resolve that, when the internal file paths are so long.

campellcl
2020-10-19 23:11
I've already tried the windows fixes to enable Win32 longer path names

matt.fellows
2020-10-19 23:11
It?s sad this is a problem in 2020

campellcl
2020-10-19 23:11
Agreed haha

matt.fellows
2020-10-19 23:11
yeah

matt.fellows
2020-10-19 23:12
see how you go moving the directory, it?s worth a shot

campellcl
2020-10-19 23:12
Yup, working on it now!

campellcl
2020-10-19 23:33
Yup, that works. Thanks Matt. Now we just need to restructure our folder hierarchy.

tjones
2020-10-19 23:49
^ I think that would be a better solution than moving to the V3 beta, where not all features are complete

matt.fellows
2020-10-19 23:49
well in this case, he needs message pact - so yes, moving to the v3 beta is not going to be super helpful! :stuck_out_tongue:

tjones
2020-10-19 23:50
Is the windows 10 pathing issue something we could do by upgrading the bundled ruby or something?

matt.fellows
2020-10-19 23:51
Can?t update the bundled Ruby, the ?traveling ruby? library we used hasn?t been updated to support modern Ruby?s

matt.fellows
2020-10-19 23:51
I?ll check again now, because it would be great if it did

tjones
2020-10-19 23:53
It looks like it hasn't been updated in a looong time, but maybe there are other projects we could use, eg: https://github.com/pmq20/ruby-packer

matt.fellows
2020-10-19 23:54
I like that idea

matt.fellows
2020-10-19 23:54
On the one hand, it?ll solve some immediate issues

matt.fellows
2020-10-19 23:54
but on the other, I?d much prefer to spend any available time moving to the strategic goals

uglyog
2020-10-19 23:56
traveling ruby is no longer supported, which is most of the problem with the embedded Ruby version

matt.fellows
2020-10-19 23:56
yep. the lib Tim linked to looks gooder (I think we did a scan a few years back)

alik.berezovsky
2020-10-20 09:19
@alik.berezovsky has left the channel

almaak
2020-10-20 09:35
has joined #pact-js

andra.moraru
2020-10-20 14:13
has joined #pact-js

camila.coder91
2020-10-20 17:06
has joined #pact-js

campellcl
2020-10-20 17:20
Will I run into trouble if I publish a consumer pact in Python (not a Message Pact because it isn't supported in Python) and attempt to verify the pact as a Message Pact on the provider side in NodeJS?

campellcl
2020-10-20 17:20
Is there a generic Pact type that will work across both language implementations?

brendan.j.donegan
2020-10-20 19:52
Contracts are language agnostic. We write consumer contracts in JS and verify them with Java

uglyog
2020-10-20 23:23
You will need to transform the stored pact file, because the format is different for messages

julzelements
2020-10-21 05:25
has joined #pact-js

kapil.mathur
2020-10-21 06:40
has joined #pact-js

mark.hudson
2020-10-21 10:45
has joined #pact-js

campellcl
2020-10-21 15:38
@uglyog That is what i was worried about. Is there a type of Pact file that would work without transformation across both implementations. A generic Pact type?

campellcl
2020-10-21 15:38
The problem only stems from mixing Pact message formats right? So as long as the message format type is implemented in both languages, I should be good?

campellcl
2020-10-21 15:44
@brendan.j.donegan Thanks for the response! My question was about the specific implementation of the language agnostic pacts, not the overall philosophy of the language agnosticism in Pact. I understand that the contracts are intended to be language agnostic. I was looking for clarification on if the types of Pacts are intercompatible as well as language agnostic. That answer appears to be: no, they are not. I should have made that distinction a bit more clear in my original question. So although you can write a Pact in JS and verify it in Java, you _cannot_ (it seems; please correct me if I'm wrong) write a *Message Pact* in JS, publish it to a broker, retrieve the message pact and verify that message Pact with a generic *non-Message Pact* (on the provider side) in Java.

cluu
2020-10-21 17:16
has joined #pact-js

tjones
2020-10-21 17:50
Are you asking if you can verify a (say) RabbitMQ message against a provider that exposes an HTTP interface? The answer is no, but any contract verification is certainly a failure anyway if the contract is not met. The ability to specify and verify contracts for messages is not available in all pact frameworks. In your example of JS and Java, it is. With Pact in Python, it is (I believe) not currently supported.

tjones
2020-10-21 17:53
Pact files adhere to the Pact spec. The most widely supported pact specification version is V2. I think message pacts are a V3 feature. In the case of pact-js, message pacts have been cherry-picked into the current released version (which otherwise only supports V2 features). ^ Someone else may correct this, I'm not sure.

camila.campos
2020-10-21 21:35
has joined #pact-js

campellcl
2020-10-21 23:46
> Are you asking if you can verify a (say) RabbitMQ message against a provider that exposes an HTTP interface? Nope, that wasn't what I was asking either. I'm specifically talking about the serverless context, where everything is conceptually a Message Pact. In this paradigm there is no dedicated provider endpoints and no dedicated consumer endpoints. Sometimes microservices provide, and sometimes microservices consume. We need to implement Message Pacts. We have a multi-language environment with some microservices written in NodeJS and some written in Python. The Python version of Pact `pact-python` does not support Message Pacts currently. The NodeJS version of Pact `pact-js` does support Message Pacts. My question was: can a Message Pact written in `pact-js` be validated by `pact-python` even if Pact python does not yet formally support Message Pacts? Does the framework know enough about the Pact specification V3 to still validate the Message pact, even if it can't yet publish them, and has no dedicated namespace (e.g. reserved `MessagePact` class) for them yet? The answer I received from @uglyog in the above thread was exactly what I was looking for. The answer is: no. We will be unable to use Message Pacts, or we will have to write our own Message Pact verifier on the Python side. If `pact-python` supported Message Pacts, then my original question would not be needed.

uglyog
2020-10-21 23:50
There is a way, if you use one of the CLIs to do the verification. I'll check the Rust one to see if it will work, but you would need to create a test endpoint in the Python project that can return the message to be verified.

uglyog
2020-10-21 23:57
The Rust CLI verifier (https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_verifier_cli) can verify a message pact by using a POST request with the message contents to an endpoint. You would just need to create the endpoint on the provider side (which should be easy in Python), that will receive the message (and one for the provider states), and return an appropriate response if it was processed successfully.

uglyog
2020-10-21 23:58
Actually, it's for the message provider, not consumer


campellcl
2020-10-22 00:53
@uglyog Good to know! Thanks! We will consider it! I'm a bit hesitant to try another language. Our foray into `pact-python` did not go well with the example code not even executing on Windows due to how Flask was being used internally. Likewise the `pact-js` example ran into Windows pathing issues from inside the Ruby logic as well, which was not fun to debug. The last thing I want to do is burn yet another full day of dev time on debugging the language-specific implementations of pact on Windows. But it is good to know that an alternative exists!

campellcl
2020-10-22 00:54
At this point we will probably throw together something incredibly hacky to work with the devils we know (e.g. `pact-python` and `pact-js`).

uglyog
2020-10-22 00:56
PRs would always be welcome on the Pact Python repo

matt.fellows
2020-10-22 00:59
If I understand correctly Chris: 1. JS is your message consumer 2. Python is the message provider (producer) You should be able to: 1. Use Pact JS to create the consumer message pact (with the workarounds you?ve established for pathing issues) 2. Use the CLI verifier as per above, to do the message verification on the producer side (i.e. your Python app), adding a simple route that wraps your functions

matt.fellows
2020-10-22 00:59
I think if it was the other way around, the answer would be ?no? at the moment for the reasons you?ve established

campellcl
2020-10-22 01:03
Yup, we would love to contribute. But we don't have the resources to do so. We are a pretty small shop. If we implemented a monkeypatch or something that worked within the confines of the Pact lib the way it was meant to be used, we would not hesitate to contribute it via PR. But most likely we will hack around the restrictions outside of Pact's CLI in a way that is not architecturally sound. I will consider personally contributing on my own time! I've offered to help take up some entry-level Issues on the Python side. But anything beyond that will require a significant time investment on my part, and I'm vested in ML research right now. So not quite my cup of tea haha.

campellcl
2020-10-22 01:13
@matt.fellows Well we are doing serverless. So ideally we would have pacts going both ways. But in the specific example I described above, what you referenced is correct. I will definitely discuss the idea of using the Rust CLI with the team to validate the message pacts. We are already several dev days into Pact with no interoperability between the NodeJS and Python logic to show for it. And it's getting hard to defend that decision. So i'm hesitant to adopt another language implementation. Right now we are entertaining the (normally terrible) idea of interfacing the NodeJS and Python logic via subprocess, translating the python responses into NodeJS Message Pacts and having the Node logic do all the interactions with the broker, including the verification logic. I'm not happy about it, because it's real hacky. But at least I will get to use my local pytest test fixtures, and we can still use pact.

campellcl
2020-10-22 01:16
So if you want that mess of a solution as a PR, I can see about getting permission to push it up. But I'm anticipating that no one will find that solution feasible in the long term.

matt.fellows
2020-10-22 01:20
No you?re spot on with everything you just said :stuck_out_tongue:

campellcl
2020-10-22 01:48
Yeah, figured you wouldn't want that anywhere near the codebase haha. Let me think about the Rust implementation CLI idea some more though. That is very helpful @uglyog, thank you. Would there be any way to publish a Message Pact on the consumer side in Python? Would the Rust CLI support that? I don't see anything about publishing consumer pacts but I might have missed it.

uglyog
2020-10-22 01:50
You can use the normal pact CLI to publish pact files. https://docs.pact.io/implementation_guides/cli/

campellcl
2020-10-22 01:53
@matt.fellows Just said that if the relationship was reversed and Python was the message consumer, and NodeJS was the message provider then that wouldn't work (I thought). Did I misinterpret?

tjones
2020-10-22 02:03
Interacting with the broker can be done by any framework (including the CLI), and is unrelated to your question about defining or verifying message pacts

tjones
2020-10-22 02:06
> Would there be any way to publish a Message Pact on the consumer side in Python? There are two steps. The first is to define (and test) the consumer contract. This produces a pact file. If your consumer testing framework does not support message pacts, it can't be a message pact. That pact file can then be published to a broker. At this point it doesn't matter what "type" of pact it is.

matt.fellows
2020-10-22 02:07
> @matt.fellows Just said that if the relationship was reversed and Python was the message consumer, and NodeJS was the message provider then that wouldn?t work (I thought). Did I misinterpret? As of this moment, that is correct.

tjones
2020-10-22 02:08
Pact doesn't really have types of pacts, it has spec versions. Message pacts are in spec V3, so you need a pact library that can write V3 specs. There's a partial exception to this in that pact-js only supports messages from V3 - the rest of the V3 features are unimplemented or in beta for pact-js.

tjones
2020-10-22 02:10
That is, at the moment pact-js can read and write V3 specs as long as you only use the messages part of the spec, and not the extended matchers or state parameters. Pact python cannot read or write V3 specs. Any pact file of any spec can be published to the broker by any broker client.

tjones
2020-10-22 02:12
From what you've written above, I think you understand the constraints very well, but I think it might be helpful not to think of message pacts as a distinct type of pact.

tjones
2020-10-22 02:13
Perhaps we should add some diagrams to the documentation to help clear this up? What do you think?

uglyog
2020-10-22 02:15
That's not quite true, the message pacts also differ in format, so can not be swapped with HTTP req/res pact files

campellcl
2020-10-22 02:17
Yeah, I'm hearing two different answers here

uglyog
2020-10-22 02:18
Not two different answers, just a clarification on what Tim said.

campellcl
2020-10-22 02:24
I'm a bit confused. So should I not think of message pacts as a distinct type, even though Message Pacts "differ in format"? Because it seems to matter in cross language implementations, when the python broker client doesn't support Message Pacts. The python broker client doesn't seem able to verify a Message Pact published by the NodeJS broker client. To me that implies a pact type system. What am I missing?

campellcl
2020-10-22 02:26
I get what you are saying about the python broker client not supporting V3 spec.

uglyog
2020-10-22 02:26
If you generated a message pact, published it, and then tried to verify it as an HTTP pact, you would get an error from the verifier because the required attributes in the file would not be correct.

tjones
2020-10-22 02:26
> even though Message Pacts "differ in format"? Yes. They are a different version of the pact spec

uglyog
2020-10-22 02:28
Even with V3 pacts, the V3 message pact files have different JSON attributes to the V3 HTTP pact files

campellcl
2020-10-22 02:30
> Even with V3 pacts, the V3 message pact files have different JSON attributes to the V3 HTTP pact files Right. That is what I am saying makes it a different type of Pact in my mind. An HTTP-Type-Pact and a Message-Type-Pact. There is also some confusion when the `pact-js` code has a distinct `MessageProviderPact` and `MessageConsumerPact` class separate from the generic `Pact` class. We assumed that the `Pact` class was the generic HTTP-type-Pact and that the `MessageProviderPact` class represented another distinct other type of pact (a Message-Type-Pact). But you are saying that's a harmful way of looking at it, right @tjones? I will try your approach of not thinking about it like that then.

campellcl
2020-10-22 02:36
> There are two steps. The first is to define (and test) the consumer contract. This produces a pact file. If your consumer testing framework does not support message pacts, it can't be a message pact. But the fact remains, we need Message Pacts up and running in both NodeJS and Python on both sides of the contract. Irrespective of the fact that `pact-python` does not support Message Pacts on the consumer side or the provider side. So what would you recommend then @tjones?

campellcl
2020-10-22 02:36
Use the Rust CLI to perform message pact verification on the provider side in Python via an endpoint running on localhost. I got that part down now thanks to the help I received above.

campellcl
2020-10-22 02:37
I can already use NodeJS to publish message pacts and verify message pacts thanks to `pact-js`.

campellcl
2020-10-22 02:40
So just use the normal Ruby standalone executable CLI to issue message pacts on the Python consumer side via a provider-states endpoint as well?

tjones
2020-10-22 02:55
Yes, you could use the Ruby CLI - and that's what I would personally do. If you're familiar with the node DSL, and don't want to learn anything extra, you could also use the pact-js to do the same thing. For example: https://github.com/pact-foundation/pact-js/blob/master/examples/jest/publish.js

tjones
2020-10-22 02:56
pact-js just wraps the Ruby executable anyway

longlevan
2020-10-22 09:15
has joined #pact-js

justin.garfield
2020-10-22 16:15
has joined #pact-js

campellcl
2020-10-22 16:51
Great, thanks all. You've been a huge help. We will take what you have proposed and run with it and see where we end up. If we come up with a non-hacky solution I'll get a PR open to contribute back to Pact.

guppy0356.nakira
2020-10-23 00:34
has joined #pact-js

ercalbwar
2020-10-24 19:24
has joined #pact-js

andrewshtamburg
2020-10-25 13:04
has joined #pact-js

siad.ardroumli
2020-10-25 18:16
has joined #pact-js

srikanthpmailid
2020-10-26 01:02
has joined #pact-js

photesthesis_geospiza
2020-10-26 15:10
has joined #pact-js

photesthesis_geospiza
2020-10-26 15:13
Hello, everyone! @tjones -- lemme know when you want to jam on https://github.com/pact-foundation/pact-node/pull/238 :smile:

francislainy.campos
2020-10-27 10:11
Hi, good morning. I come from Java and am used to having different files for each consumer contract but them I name them all finishing with the word Test so that once I run a maven command they become part of the same json file and as one single contract. I'm not sure whether this would happen also with Javascript based contracts as I'm on IntelliJ now and I have two mocha files, but when I run one of them the other is overwritten and the contract only shows the last one run.


thomas.hibbard
2020-10-27 14:21
@uglyog `https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/typescript/test/get-dog.spec.ts#L30` You?ve said that anything can be passed to given in the v3 beta, but in the example it still looks like it?s a string.

thomas.hibbard
2020-10-27 14:23
The definition is a little unclear to me ```export declare class PactV3 { /* ... */ given(providerState: string, parameters?: any): PactV3; /* ... */ }``` `given` here looks like a method that return an instance of the `PactV3` class itself. I?m not really sure how this allows for setting up structured data state.

francislainy.campos
2020-10-27 15:55
Thanks @matt.fellows, sorry, only seeing your reply now. I'll try and give it a go and come back here with the results.

thomas.hibbard
2020-10-27 17:10
ah never mind, that was idiotic, I see now it?s just a chainable method. I?m trying to pass it some data to its second argument, and the pact build succeeds, but it keeps giving me an error `Ignoring value for provider state parameter {whatever_key_i_put_in_the_object_in_the_second_parameter}`

francislainy.campos
2020-10-27 19:36
Yes, it worked. Thanks very much. :)

jackbwheatley
2020-10-27 21:02
has joined #pact-js

uglyog
2020-10-27 22:00
Ok, @thomas.hibbard let me fix that

matt.fellows
2020-10-27 22:01
Should it be object that has string keys with any value?

thomas.hibbard
2020-10-27 22:01
Ah Hi @uglyog I can see now that the issue was `given` can take an object, but it seems only one key-value set deep.

thomas.hibbard
2020-10-27 22:02
eg ```{ "itIs": ["nested"], "something": "not nested", "value": "that is a string" } // will result in { "name": "some_given_state", "params": { "itIs": null, "something": "not nested", "value": "that is a string" } }```

uglyog
2020-10-27 22:03
It should support any object that is provided, as long as it can be serialised to JSON

thomas.hibbard
2020-10-27 22:05
This is not the end of the world to be honest. The main problem I am facing is that with the mock server erroring out on `OPTIONS` preflights (even with CORS set to `true`),

carlosalmeida.xon
2020-10-27 22:06
has joined #pact-js

thomas.hibbard
2020-10-27 22:07
or, failing for something like this ```it('should get items', async () => { return provider.executeTest(async (mockserver) => { let response: ILoadItemsResponseBody; try { response = await itemService.loadItems({}).toPromise(); expect(response).toEqual(expectedBody); } catch (specError) { console.error({ specError }); } finally { console.log('test done'); } }); });``` with an error like > Test code failed with an error: Mock server failed with the following mismatches: > > 1) The following request was expected but not received: > Method: GET > Path: /api/items

uglyog
2020-10-27 22:08
if you can provide an example test with the issue, that would help. You can raise a Github issue for it too.

thomas.hibbard
2020-10-27 22:08
I have tried a variety of scenarios including using the `done` callback, return the expectation (this errors because it?s just a boolean evaluation apparently where `executeTest` is expecting a promise I think. I?ve also tried then wrapping it in async/await, etc

thomas.hibbard
2020-10-27 22:09
Yeah I know this is super vague, so I will make an issue on github for sure.

thomas.hibbard
2020-10-27 22:09
I just thought it might be just me using the API incorrectly so I?d check here first.

uglyog
2020-10-27 22:10
That will help. Also, if you compare the examples in https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3 to yours in might help

uglyog
2020-10-27 22:12
I'm going to be working on Pact-JS V3 for the next 2 days, so if we can identify the issues you're having, I can fix them and get a release out

thomas.hibbard
2020-10-27 22:12
yep, this typescript example is what I was working from. Of course nothing is ever simple so I wasn?t able to use just like an axios.get..it has to go through an angular service, so it?s possible I deviated accidentally

thomas.hibbard
2020-10-27 22:14
That?s excellent.

thomas.hibbard
2020-10-27 22:15
I am around and will be working on this tomorrow as well, so feel free to work with me as much as you need.

francislainy.campos
2020-10-28 01:32
Hi, it's me again, sorry. I'm getting this error `UnhandledPromiseRejectionWarning: AssertionError: expected { Object (id, title) } to deeply equal { Object (id, title) }` when I use somethingLike for my object. I can bypass it by skipping my assertion through a try and catch like this ```getMeCategory(urlAndPort).then(response => { try { expect(response.data).to.eql(EXPECTED_BODY) } catch (e) { } done() }, done)``` However, this may not be the ideal solution and I was wondering what is wrong with my code that may be causing this please. It's very similar to the mocha sample. ```"use strict" const {somethingLike} = require('@pact-foundation/pact/dsl/matchers'); const expect = require("chai").expect const path = require("path") const {Pact} = require("@pact-foundation/pact") const {getMeCategory} = require("../api") describe("Category API test", () => { let url = "http://localhost" const port = 8992 const provider = new Pact({ port: port, log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "pacts"), spec: 2, consumer: "FRONTEND", provider: "BACKEND", pactfileWriteMode: "merge", }) const EXPECTED_BODY = { id: somethingLike("58330784-983c-4ae9-a5a1-d8f8d2b70a59"), title: somethingLike("My category") } // Setup the provider before(() => provider.setup()) // Write Pact when all tests done after(() => provider.finalize()) // verify with Pact, and reset expectations afterEach(() => provider.verify()) describe("get /category/58330784-983c-4ae9-a5a1-d8f8d2b70a59", () => { before(done => { const interaction = { state: "a request for a single category", uponReceiving: "a request for a single category", withRequest: { method: "GET", path: "/category/cdb02322-a8a6-4acf-9644-ddf8b24af9e6", headers: { Accept: "application/json", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json", }, body: EXPECTED_BODY, }, } provider.addInteraction(interaction).then(() => { done() }) }) it("returns the correct response", done => { const urlAndPort = { url: url, port: port, } getMeCategory(urlAndPort).then(response => { try { expect(response.data).to.eql(EXPECTED_BODY) } catch (e) { } done() }, done) }) }) })``` Thank you very much.

uglyog
2020-10-28 03:50
I've fixed the provider state issue. This `.given("i have a project", { id: "1001", name: "Home Chores", tags: ["home", "must do"], vals: { id: 100 } })` now generates ```"providerStates": [ { "name": "i have a project", "params": { "id": "1001", "name": "Home Chores", "tags": [ "home", "must do" ], "vals": { "id": 100.0 } } } ],```

brendan.donegan
2020-10-28 09:14
@francislainy.campos this might have something to do with how your getMeCategory function is implemented, can you show that code?

francislainy.campos
2020-10-28 09:15
Sure, ```"use strict" const axios = require("axios") exports.getMeCategory = endpoint => { const url = endpoint.url const port = endpoint.port return axios.request({ method: "GET", baseURL: `${url}:${port}`, url: "/category/cdb02322-a8a6-4acf-9644-ddf8b24af9e6", headers: {Accept: "application/json"}, }) }```

francislainy.campos
2020-10-28 09:15
Thanks

brendan.donegan
2020-10-28 09:49
Seems ok. Might be worth trying to log the response.data and make sure it is what you think it should be

francislainy.campos
2020-10-28 10:23
This is what I get when break point on response.data

francislainy.campos
2020-10-28 10:23
And here the EXPECTED_BODY

brendan.donegan
2020-10-28 10:25
ah yes

brendan.donegan
2020-10-28 10:26
the expected body contains Pact matchers. This is not going to be the same as the response from the mock server

francislainy.campos
2020-10-28 10:26
Yeah, but the funny thing is that it works for my other contracts.

brendan.donegan
2020-10-28 10:26
might depend what kind of comparison you use

francislainy.campos
2020-10-28 10:26
```const EXPECTED_BODY = { category: { id: uuid("58330784-983c-4ae9-a5a1-d8f8d2b70a59"), title: string("My category"), reports: eachLike({ id: uuid("87f2ebeb-880e-4541-bcf1-d317067b9e6b"), title: string("My report"), runDate: integer(1591609820902), //todo: timestamp createdDate: integer(1591609820902) }) } }```

francislainy.campos
2020-10-28 10:27
This one works fine.

francislainy.campos
2020-10-28 10:27
And it's the same piece for comparing them.

brendan.donegan
2020-10-28 10:28
that could be because you are using literal type matchers rather than somethingLike

brendan.donegan
2020-10-28 10:28
you could try changing the other one to use literal types

brendan.donegan
2020-10-28 10:28
so uuid() and string() instead of somethingLike

matt.fellows
2020-10-28 10:46
yep, you?re spot on Brendan

matt.fellows
2020-10-28 10:47
There is a function to strip away all of the matchers and give you the raw payload

matt.fellows
2020-10-28 10:47
But, honestly, don?t do this: `expect(response.data).to.eql(EXPECTED_BODY)`

matt.fellows
2020-10-28 10:48
I?m almost certain you?ve copied from one of our examples, and ?bad matt? (slaps wrist) there are some example assertions that are not very good - and that is one of them

matt.fellows
2020-10-28 10:48
you almost certainly never want to just check that Pact gave you back what you gave it

matt.fellows
2020-10-28 10:49
The mentality for this test is ?I?m writing a unit test of `getMeCategory()` and as a side effect, i?ll also generate a contract for it?

francislainy.campos
2020-10-28 10:51
Thanks you both. Yeah, I copied from the mocha sample. I'm sorry I thought the other file was working but it was actually inside a try and catch that was avoiding that error from happening.

brendan.donegan
2020-10-28 10:52
@matt.fellows that?s what I keep trying to tell people :slightly_smiling_face:

brendan.donegan
2020-10-28 10:52
You can unit test your API functions *with Pact*

brendan.donegan
2020-10-28 10:52
You don?t need to do both, it?s not ?duplication of effort?

matt.fellows
2020-10-28 10:52
I think it should be a rule somewhere, I?ll add it to the docs now

francislainy.campos
2020-10-28 10:53
I think I'll use expect(response.status).to.eql(200) instead

brendan.donegan
2020-10-28 10:53
That?s probably worse

francislainy.campos
2020-10-28 10:54
It's only asserting a 200 and generating a contract once this passes, which should happen always unless there's some error on the contract it.

francislainy.campos
2020-10-28 10:54
The verification will be done by the provider so not sure we need much here on the consumer side?

brendan.donegan
2020-10-28 10:54
TBH it doesn?t matter too much in this situation when you?re just practicing

matt.fellows
2020-10-28 10:54
It _is_ also fair to say, that JS does make some of these assertions less good, because in JS land you don?t usually do a whole lot with the response - JSON is already a first class citizen, so converting to DAOs etc. is lesss common

matt.fellows
2020-10-28 11:06
how does that read?

nasir.amin
2020-10-28 11:07
has joined #pact-js

thomas.hibbard
2020-10-28 11:10
That?s excellent.

jimish.shah.-nd
2020-10-28 11:26
has joined #pact-js

jimish.shah.-nd
2020-10-28 11:29
Hi, I dont seem to find a way to find a matcher for empty array or an array with values. eg [?Monday?, ?Tuesday?] or [] Please help

antonello
2020-10-28 11:30
Hi Jimish, You won?t find it because it?s not supported. You can read more about why here: https://docs.pact.io/faq/#why-is-there-no-support-for-specifying-optional-attributes If both matter, you?d have to implement them separately.

jimish.shah.-nd
2020-10-28 11:37
Thank you @antonello, makes sense :blush:

brendan.donegan
2020-10-28 11:49
The only thing I?d be concerned about is some peoples interpretation of a ?good unit test? :smile:

brendan.donegan
2020-10-28 11:50
Think about it like this, if you?re verifying that contract and it returns an empty array how can you tell if it is because it was supposed to or if it?s because of a bug?

matt.fellows
2020-10-28 11:58
:grimacing:

adam_figgins
2020-10-28 14:20
has joined #pact-js

thomas.hibbard
2020-10-28 15:01
@uglyog `https://github.com/pact-foundation/pact-js/issues/520` Thanks for having a look. I?m around today for any clarification that may help you.

aperdomobo
2020-10-28 15:42
has joined #pact-js

diazguerra2
2020-10-28 16:06
has joined #pact-js

xsamore
2020-10-28 19:52
has joined #pact-js

simon
2020-10-28 20:49
has joined #pact-js

ruben.cagnie
2020-10-29 01:24
has joined #pact-js

abubics
2020-10-29 02:32
Apart from that bit of subjectivity, I think it reads & scans well :ok_hand:

abubics
2020-10-29 02:32
And :taco: for @brendan.donegan, what a helper \o/

272939217
2020-10-29 05:33
has joined #pact-js

matt.fellows
2020-10-29 06:49
@tjones lol just rediscovered a very crude attempt at a Mocha interface I made 4-5 years ago: https://github.com/pact-foundation/pact-js-mocha. It had some of the intentions behind `jest-pact` . I had a vague memory of _wanting_ to do it, but didn?t realise I did :stuck_out_tongue:

tjones
2020-10-29 06:57
Oh cool! Do you think we should clean it up and match the current DSL? (maybe put some semi colons in?)

matt.fellows
2020-10-29 06:58
I was thinking binning it, mostly because there are already too many things to maintain! (and the interface is both tied to a super old mocha and not very useful)

matt.fellows
2020-10-29 06:58
re-writing it would be faster

matt.fellows
2020-10-29 06:58
also no semis

matt.fellows
2020-10-29 06:58
_smacks Tim?s wrist_

tjones
2020-10-29 07:00
(what do you mean? You don't have to rewrite to put semicolons in :smile: )

tjones
2020-10-29 07:00
But yeah, cool. I was wondering how many people are using non-jest test frameworks

tjones
2020-10-29 07:01
it would be cool if we were a bit nicer boiler plate wise.

tjones
2020-10-29 07:01
Do you still use mocha? I have pretty much exclusively switched to Jest

matt.fellows
2020-10-29 07:02
I do, but mostly out of inertia

matt.fellows
2020-10-29 07:02
Jest is probably now the #1 so it makes sense to havve good support for it

tjones
2020-10-29 07:03
I just checked the mocha source. For consistency, I think our mocha interface should follow their convention of using semicolons

tjones
2020-10-29 07:03
:smiling_imp:

matt.fellows
2020-10-29 07:03
:laughing:

matt.fellows
2020-10-29 07:03
Jest get?s ~ 2x the amount of weekly downloads

tjones
2020-10-29 07:04
it *also* has semicolons

tjones
2020-10-29 07:05
Anyway, I would like to do a modern mocha wrapper

tjones
2020-10-29 07:05
I think it'd be helpful

tjones
2020-10-29 07:05
also, with Rust, I reckon we could get better integration with the errors

matt.fellows
2020-10-29 07:05
we _need_ better integration, at the very least

tjones
2020-10-29 07:05
wouldn't it be awesome if failed tests didn't need you to go look in the logs!

matt.fellows
2020-10-29 07:05
yes

tjones
2020-10-29 07:06
I would be prepared to commit at least one less semicolon in exchange for that

tjones
2020-10-29 07:06
:wink:

matt.fellows
2020-10-29 07:06
there are a host of things we need to do to make it feel native - SSL, logginsg etc. all come at a cost because it?s not within the OS


matt.fellows
2020-10-29 07:06
Rust unfortunately has semicolons. But at least they?re semantic

tjones
2020-10-29 07:07
I knew there was something I liked about Rust

driloni92
2020-10-29 09:05
has joined #pact-js

pauloavra
2020-10-29 12:33
has joined #pact-js

uladzislau_danilchyk
2020-10-29 13:15
has joined #pact-js

uladzislau_danilchyk
2020-10-29 13:22
Hi everyone! I have a question regarding creating pact tests for React app which uses GraphQL and Next.JS. I have functional component for rendering product details, e.g. `const productDetails: NextPage<IProps> = () => { ... }` Inside that component I'm using the following query: ``` const { data, error } = useQuery<ProductDetailsQuery>(productDetailsQuery, { variables: {...} });``` But this code is placed in middle of the functional component and I don't understand how to cover such example with test. Could you help me please?

abubics
2020-10-30 01:58
We generally recommend separating the UI from data requests (e.g. network calls). This helps you avoid loading React in your tests, and can also help centralise your API clients, which is useful for grouping interactions by contract .

abubics
2020-10-30 01:59
(Unless I'm misunderstanding your question/problem :innocent: it's very possible)

francislainy.campos
2020-10-30 04:18
Hi @matt.fellows, good morning. Would you know the counterpart for this answer here but on Javascript please? Looking for an equivalent to ```.pathFromProviderState("/meeting/${id}", "/meeting/500")``` https://stackoverflow.com/a/63956890/6654475 Thanks very much.

matt.fellows
2020-10-30 04:19
It currently doesn?t exist I?m afraid

matt.fellows
2020-10-30 04:19
Only JVM supports that magic. We need to update the roadmap on the JS GH repo to get some visibility on this for a roadmap


uladzislau_danilchyk
2020-10-30 07:45
@abubics, thanks for your answer! We just move this logic into separate hooks:)

francislainy.campos
2020-10-30 09:11
Thanks Matt. And would we have any sample for how to write the provider verification using Javascript? I could only find something like somewhere but it gives me a timeout. ```const { Verifier } = require('@pact-foundation/pact'); describe('Pact Verification', async () => { await test('a request for all categories', () => { const opts = { provider: 'BACKEND', providerBaseUrl: 'http://localhost:8081', pactBrokerUrl: 'https://user.pactflow.io', pactBrokerToken: 'mytoken', publishVerificationResult: true, providerVersion: '1.0.0', logLevel: 'INFO', }; return new Verifier(opts).verifyProvider(); }); });```

matt.fellows
2020-10-30 10:23
There are a few examples in the Pact JS repo as well as the CI/cd workshop

matt.fellows
2020-10-30 10:23
Howtolearn

2020-10-30 10:23
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2020-10-30 10:23
See :point_up:

matt.fellows
2020-10-30 10:24
There's also https://docs.pactflow.io/docs/tutorials/ which you can do in a browser in 5 mins... There's lots :joy:

francislainy.campos
2020-10-30 10:26
Thanks. Yes, I think I got this example from the video tutorial, but can try and check it again to see what I may have missed.

matt.fellows
2020-10-30 10:29
Start with the tutorial on Pactflow because it's the simplest. There are working examples in the JS repo/docs as well as two full working workshops - I'm confident one of those will be useful :+1:

francislainy.campos
2020-10-30 12:34
It seems it only times out when trying to connect to the pactflow broker. If I use the below piece to verify the contract locally it works fine. ```const {Verifier} = require('@pact-foundation/pact'); const path = require('path'); describe("Pact Verification", () => { test("a request for all categories", () => { const opts = { provider: 'BACKEND', providerBaseUrl: 'http://localhost:8081', // pactBrokerUrl: 'https://myuser.pactflow.io', // pactBrokerToken: 'mytoken', pactUrls: [ path.resolve(__dirname, '../../pacts/frontend-backend.json') ], publishVerificationResult: true, providerVersion: '1.0.0', logLevel: 'INFO', }; return new Verifier(opts).verifyProvider().finally(() => { }); }) });```

jimish.shah.-nd
2020-10-30 14:22
Hi, I get this error when creating consumer pacts using office vpn, it works fine without office vpn ``` TypeError: Cannot read property 'writePact' of undefined 8 | 9 | afterAll(done => { > 10 | global.provider.finalize().then(() => done()); | ^ 11 | }); 12 | at Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:148:8) at Object.<anonymous> (pactTestWrapper.js:10:19)``` what is it doing ? Please help !!!

jikogay728
2020-10-30 17:20
has joined #pact-js

matt.fellows
2020-10-30 21:06
Maybe look at increasing the test timeout?

francislainy.campos
2020-10-30 21:29
Yeah, I tried out but it didn't work. Well, it's okay, as I'm using this to test only my local file before anyways, but just so you guys know as it could perhaps be something other people may be getting too, not sure. Thanks.

matt.fellows
2020-10-30 21:30
What does it say with log level set to debug?

matt.fellows
2020-10-30 21:31
I run these demos several times a week, so I'm very confident they work

francislainy.campos
2020-10-30 21:31
Let me try here.

matt.fellows
2020-10-30 21:33
Which example did you copy from? That's a jest error

francislainy.campos
2020-10-30 21:34
Let me find it again.

matt.fellows
2020-10-30 21:34
(Sorry, I just deleted as your token was in it)

matt.fellows
2020-10-30 21:34
I think it may just be jest timing out before it can start all of the pact processes

matt.fellows
2020-10-30 21:35
(I deleted it again, you'll need to retract your output so your creds aren't in it)

francislainy.campos
2020-10-30 21:35
No worries, I'll do that if you still need it.

matt.fellows
2020-10-30 21:36
All good I think I saw what I needed :joy:


francislainy.campos
2020-10-30 21:38
I think this is where I got it from

francislainy.campos
2020-10-30 21:39
I tried to find an example for this verification with mocha as this is how I'm doing the writing of the contracts but couldn't find it so not sure if it would happen there too.

matt.fellows
2020-10-30 21:39
Try updating the timeout as per the workshop: E.g. `"test:pact": "CI=true react-scripts test --testTimeout=30000 pact.spec.js"`

francislainy.campos
2020-10-30 21:41
```const {Verifier} = require('@pact-foundation/pact'); const path = require('path'); // Setup provider server to verify const app = require('express')(); const server = app.listen("8082"); describe("Pact Verification", () => { test("a request for all categories", () => { const opts = { provider: 'BACKEND', providerBaseUrl: 'http://localhost:8081', pactBrokerUrl: 'https://user.pactflow.io', pactBrokerToken: 'mytoken', // pactUrls: [ // path.resolve(__dirname, '../../pacts/frontend-backend.json') // ], publishVerificationResult: true, providerVersion: '1.0.0', logLevel: 'INFO', }; return new Verifier(opts).verifyProvider().finally(() => { server.close(); }, 30000); }) });```

francislainy.campos
2020-10-30 21:42
I tried like this before as am running through IntelliJ and not a npm command.

francislainy.campos
2020-10-30 21:43
I can send you my credentials privately so that you can run this snippet if that would help you a bit more?

matt.fellows
2020-10-30 21:53
I'm just on the go I'm afraid but can look later


matt.fellows
2020-10-30 21:54
Have you tried the above?

matt.fellows
2020-10-30 21:55
It runs in the browser so all you need is your token and Pactflow URL

francislainy.campos
2020-10-30 21:56
No worries. I can verify this same contract fine with the JVM version and the flow credentials. Only thing is that it always shows as never verified and not sure if by any means related to this issue I'm getting here with the JS version.

francislainy.campos
2020-10-30 21:56
I can look at this link too and see.

matt.fellows
2020-10-30 21:57
You'd need to enable publishing of verification results

matt.fellows
2020-10-30 21:57
In Java that's a system property

matt.fellows
2020-10-30 21:57
In JS it's a verifier flag

francislainy.campos
2020-10-30 21:57
Ah cool, thanks.

matt.fellows
2020-10-30 22:25
What's does setting loglevel to debug say?

matt.fellows
2020-10-30 22:25
It may be timing out

matt.fellows
2020-10-30 22:26
But it sounds like a networking issue

matt.fellows
2020-10-30 22:29
Anyhow, look at the troubleshooting docs in the readme and see where that gets you

matt.fellows
2020-10-30 23:38
https://stackoverflow.com/q/64606629/1008568 :taco: for @francislainy.campos who is contributing via some good q&a

blmlcu
2020-10-31 14:51
has joined #pact-js

jimish.shah.-nd
2020-11-02 09:46
for anyone with same problem in future. I added `jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;` in pactTestWrapper.js and it worked

jamescourtoy
2020-11-02 21:04
has joined #pact-js

telmo.ferreira.costa
2020-11-03 11:32
has joined #pact-js

sergii.kopovskyi
2020-11-03 12:35
has joined #pact-js

silverton.gimenes
2020-11-03 17:58
has joined #pact-js

colber16
2020-11-03 18:34
has joined #pact-js

cvoong
2020-11-03 18:55
has joined #pact-js

uladzislau_danilchyk
2020-11-04 13:26
Hi guys! What is the difference between `ApolloGraphQLInteraction` and `GraphQLInteraction`?

anders
2020-11-09 07:37
has joined #pact-js

anders
2020-11-09 07:54
Hello! Is there any way in `pact-js` to assert that different elements of the same array have different structures? Context: I have a JS frontend querying a GraphQL gateway, and the result of the query includes a list of elements which are subtypes of a GraphQL interface (https://graphql.org/learn/schema/#interfaces). I.e. all elements have some common traits (say `foo`), whose presence I can assert easily with a normal `like` call, but the elements also have some fields which are _not_ shared by _all_ elements (call them `bar` and `baz`). You would have the same situation if working with GraphQL unions (https://graphql.org/learn/schema/#union-types), except there would be no common `foo` field. Is there any way I can assert that all elements have a field `foo`, some have a field `bar` and some have a field `baz`?

tjones
2020-11-09 07:57
Yes, although there's an intentional design subtlety here:

tjones
2020-11-09 07:57
For simplicity, lets say that you have three types `A`, `B` and `C` that all could be in the array

tjones
2020-11-09 07:58
if you were able to say something like `eachLike<A | B | C>(someExample)`, meaning "an array of things that could be `A` or `B` or `C`", then you can run in to coverage problems

tjones
2020-11-09 07:59
say your provider can never produce `C`- a test that looks for `A` or `B` or `C` will not pick this up

tjones
2020-11-09 08:00
it's better to use provider states to be more explicit, and have an array that has all of them: ```[ exampleA, exampleB, exampleC ]```

tjones
2020-11-09 08:01
this has some disadvantages if you are unable to specify the order on the provider side

tjones
2020-11-09 08:02
We'd like to support this use case better in the future (eg "examples like each of these" and "examples like each of these in any order").

tjones
2020-11-09 08:03
however, we intentionally don't have an or operator, for the same reason that we don't let `eachLike` have a minimum size of zero (because a provider that always returns an empty array would pass).

anders
2020-11-09 08:07
All right, so your suggested approach is for the provider to return a static array containing an example of each of the types in a known order, and for the consumer to then apply different assertions for the individual elements of that array? I.e. something on the consumer-side like ```{ list: [ like({ foo: "foo", bar: "bar" }), like({ foo: "foo", baz: "baz" }) ] }```

tjones
2020-11-09 08:09
Yes, that's right. You can use provider states to return a few of these situations, depending on what kind of coverage is appropriate (eg, perhaps the array is either `A | B` or `A | C`, but not both).

anders
2020-11-09 08:11
Yeah, makes sense. All right, thanks for your help! :slightly_smiling_face:

tjones
2020-11-09 08:12
You're welcome. This is a frequent question, so please let us know if there's anything you find particularly difficult to cover, or things you would like to be able to express more easily.

anders
2020-11-09 08:15
Will do. :slightly_smiling_face: I reckon it should be fairly straightforward, it just didn?t occur to me that I could make different assertions on individual array elements, when we?ve used `eachLike` for all arrays so far, and I saw no other array-matcher in the pact DSL.

tjones
2020-11-09 08:19
Ah, yes. I've been meaning to add this case to the matchers documentation, this is a good reminder

uladzislau_danilchyk
2020-11-09 08:30
Hi everyone and @matt.fellows I have a question regarding https://pact.canny.io/feature-requests/p/support-reacts-hooks What other ways you are talking about?

tjones
2020-11-09 09:37
Usually, a hook looks something like this: ``` useEffect(() => { let componentMounted = true; if (isLoading) { if (componentMounted) { setIsLoading(true); } api() .getSomething() .then((results) => { setState(results); }) .finally(() => { if (componentMounted) { setIsLoading(false); } }); } return () => { componentMounted = false; }; }, [isLoading]);```

tjones
2020-11-09 09:37
the pact test can invoke ``` api() .getSomething()```

tjones
2020-11-09 09:37
in the component test, you can then mock out the `api` layer

tjones
2020-11-09 09:39
https://github.com/TimothyJones/react-api-layer-example/commit/fa12e491604fa997b35576e24d55b588af4da6dc ^ See this commit for an example modifying the hook in the React docs to have an API layer.

tjones
2020-11-09 09:42
React best practices are a bit out of scope for this channel, but in general, I don't think it's good practice to have API fetch code directly in the hook. I suspect the reason the example in the react code has the fetch directly in the hook is just so all the context is there (and API layering is out of scope for the example).

matt.fellows
2020-11-09 10:57
:point_up:

matt.fellows
2020-11-09 10:57
We really need that recipes page for good answers like this!

matt.fellows
2020-11-09 11:01
Tim (and possibly @anders ), for future consideration. Ron has just been adding an ?array contains? matcher to the core engine and JS, which doesn?t address exactly what your needs are, but thought I?d let you know. You can see an example of this here: https://github.com/pactflow/example-siren/blob/master/consumer/src/__tests__/delete-order.spec.js#L73-L84

matt.fellows
2020-11-09 11:02
Blog post coming out soon, but ```The new matcher works by providing a list of required items (which can be totally different objects), and it will match the actual list from the provider if all the required variants match at least one item in the list.```

matt.fellows
2020-11-09 11:02
So this might be useful to you, if that holds. The problem Tim was referring to earlier, is that if you get one or the other object, we can?t be sure your code can handle it unless both are returned. This new matcher satisfies that issue

anders
2020-11-09 12:52
Ah, cool, thanks for the heads up!

pbobba
2020-11-09 23:03
has joined #pact-js

jun.li
2020-11-09 23:05
has joined #pact-js

douweicai
2020-11-10 04:11
has joined #pact-js

christian.huber
2020-11-10 09:20
has joined #pact-js

vuttithatkrongyot
2020-11-10 10:57
has joined #pact-js

dan.iosif
2020-11-10 17:06
has joined #pact-js

denitsa.kulezich
2020-11-11 09:19
has joined #pact-js

uladzislau_danilchyk
2020-11-11 11:46
I have an expected response code like this: ```willRespondWith({ .... body: { data: { a: Pact.Matchers.string('My string') b: 'my another string' } } });``` Why does the Pact do not validate my `b` response attribute by value? It validates attribute by type only..

brendan.donegan
2020-11-11 12:52
do you have an example of the failing verification output?

uladzislau_danilchyk
2020-11-11 12:53
After running on provider side it doesn't fail

brendan.donegan
2020-11-11 12:54
so data.b is not ?my another string? and you?re sure of that?

uladzislau_danilchyk
2020-11-11 13:48
@brendan.donegan, Pact adds to pact file matcher by type even if I don't use Matcher for data.b at all

abubics
2020-11-11 21:48
Seems weird, you're right. Do you have a fuller example? This sample code is missing a comma, so I guess it's not quite copied directly from your actual test.

rodrigo.costa20
2020-11-12 00:59
has joined #pact-js

yong.gong188
2020-11-12 09:13
has joined #pact-js

anandhadeepak
2020-11-12 13:03
has joined #pact-js

uladzislau_danilchyk
2020-11-12 13:05
@abubics, ``` beforeEach((done) => { globalAny.provider .addInteraction( new Pact.ApolloGraphQLInteraction() .given('authenticated EndUser') .uponReceiving('a UserQuery') .withRequest({ path: '/graphql', method: 'POST', }) .withOperation('UserQuery') .withQuery( ` query UserQuery { currentUser { email cart { valid __typename } __typename } }` ) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json;charset=UTF-8', }, body: { data: { currentUser: { email: Pact.Matchers.email(''), cart: { valid: Pact.Matchers.boolean(true), __typename: 'Cart', // here matches by type instead }, __typename: 'EndUser', // the same }, }, }, }) ) .then(() => done()); });```

uladzislau_danilchyk
2020-11-12 13:07
Hi everyone! I didn't found docs how I can use versioning in PactJS. How can I set version for consumer with PactJS?

abubics
2020-11-12 13:09
I would've expected that to work, but I haven't used pact-js in a while. https://github.com/pact-foundation/pact-js#matching seem to suggest a specific string value matcher now ```const { string } = Matchers // ... body: { ... name: string("Billy"), ...```

uladzislau_danilchyk
2020-11-12 13:10
@abubics I have used string matcher before but it matches only by type. If I'm not using this matcher I have the code above, it works the same (matching by type)

brendan.donegan
2020-11-12 13:12
you pass the --consumer-app-version flag to the pact-broker publish command

abubics
2020-11-12 13:14
Oh right, the table says "will match a string value", rather than "match any string". It'd be nice to make the docs more explicit, because it scans as more specific than it means.

abubics
2020-11-12 13:14
As I said, your code looks right, you might want to raise a defect.

abubics
2020-11-12 13:16
There's a (very minor?) chance the Apollo DSL is out of sync with regular pact-js matchers, too, I guess? I'd be surprised, but it might be a clue.

uladzislau_danilchyk
2020-11-12 13:16
@abubics, i will raise a ticket in github repo and team will check)

david.dias
2020-11-12 20:04
has joined #pact-js

matt.fellows
2020-11-12 20:44
What does the generated pact file look like?

matt.fellows
2020-11-12 20:44
From casting my eyes over that it should match on exact value indeed

matt.fellows
2020-11-12 20:45
If you can share the verification log file that shows the req/res that pact sees that will also help

uladzislau_danilchyk
2020-11-13 09:19
@matt.fellows, the generated pact file looks the same as using `Pact.Matchers.string()`

uladzislau_danilchyk
2020-11-13 09:20
@matt.fellows, I will try to share

matt.fellows
2020-11-13 09:39
We?ll need a reproducible example, so if you can fill out an issue at: https://github.com/pact-foundation/pact-js/issues/new we can look at it

billal.patel
2020-11-13 10:31
has joined #pact-js

louis.oliver
2020-11-16 10:33
has joined #pact-js

ashishkujoy
2020-11-16 15:08
has joined #pact-js

pradeepchoube
2020-11-17 03:49
has joined #pact-js

brendan.donegan
2020-11-17 10:50
Thanks @matt.fellows and @uglyog :smile:

brendan.donegan
2020-11-17 10:50
I?ll be getting us updated and let you know if there are any issues

matt.fellows
2020-11-17 11:20
You can thank Ron for that!

brendan.donegan
2020-11-17 12:22
QQ - I?m going to need to write any new tests that need to use this feature using Pact V3, is it okay to ?merge? v2 and v3 contracts or would I have to convert any existing tests for the same consumer/provider pair to v3 as well?

meng-lingtao
2020-11-17 14:39
has joined #pact-js

pabvidcal
2020-11-17 15:30
has joined #pact-js

pabvidcal
2020-11-17 16:05
Hi! First of all congratulations for this great framework :slightly_smiling_face: I wanted to ask you a question about pact response I have a case in which in the backend I add a new header to the request, so the frontend instead of a GET request makes a HEAD request. Is there any way to get the headers of an interaction using pact?

pabvidcal
2020-11-17 17:34
I don't know if it can be caused because the pact server is not setting the Access-Control-Allow-Header to true anyhow :thinking_face:

uglyog
2020-11-17 21:53
It currently won't merge them, but I'm thinking for changing that by letting it upgrade older spec pacts to the newer version.

uglyog
2020-11-17 21:53
Something for the next release.

abubics
2020-11-17 23:05
I assume you can just write a test that makes a HEAD request. Are you having trouble because the browser makes a HEAD request that you're not in control of?

abubics
2020-11-17 23:06
I usually leave browser-specific things out of Pact, because it's not really part of the interaction. I don't run the Pact tests from a browser, either, so it doesn't get in the way.

abubics
2020-11-17 23:07
Although, you probably do want some automated test coverage around CORS. I would tend to pick another kind of testing to ensure that :slightly_smiling_face:

matt.fellows
2020-11-17 23:36
what @abubics says :taco:

tjones
2020-11-18 00:02
@pabvidcal Have you enabled cors in the pact options?

matt.fellows
2020-11-18 00:28
what does the expected request/response details look like @pabvidcal

magesh.nagamani
2020-11-18 05:15
has joined #pact-js

pabvidcal
2020-11-18 07:05
Thanks for the help guys my interaction would be this one: ``` { state: 'stateless', uponReceiving: 'description', withRequest: { path: 'my path', method: 'HEAD', headers: { Authorization: 'VALID_TOKEN' } }, willRespondWith: { status: 204, headers: { 'X-Resource-Count': '3' } } };``` From a specific service I make *head* request only to retrieve this custom resource. The functionality works fine but when I run the test I don't receive any custom resource from this response. @tjones yes, I have cors activated in the pact options

tjones
2020-11-18 07:35
What error are you getting?

matt.fellows
2020-11-18 07:37
Is the error on the consumer or provider side of the test?

pabvidcal
2020-11-18 07:38
Hi! I don't get any error. I just don't receive the custom header with the response. The problem is on the consumer side

matt.fellows
2020-11-18 07:53
If you could please provide a minimal reproducible example and submit a bug report that would really help

brendan.donegan
2020-11-18 08:23
So in the meantime all tests that use the same provider need to be V3?

brendan.donegan
2020-11-18 08:24
This is only really a big deal because afaik jest-pact doesn?t support v3

brendan.donegan
2020-11-18 08:25
When it does I will just convert everything to v3 anyway

jstoebel
2020-11-18 13:53
has joined #pact-js

uglyog
2020-11-19 04:16
Actually, I started to implement this, and after writing a test, looks like it does upgrade the existing pact

uglyog
2020-11-19 04:17
It won't work if another V2 test runs afterwards, though

daniel.sayer89
2020-11-19 10:33
has joined #pact-js

art.ptushkin
2020-11-19 10:34
has joined #pact-js

pact457
2020-11-19 10:36
has joined #pact-js

ajerthan.sivayoganath
2020-11-19 10:38
has joined #pact-js

philipchardwick
2020-11-19 11:05
has joined #pact-js

tanzmann
2020-11-19 11:09
has joined #pact-js

olivier.quere
2020-11-19 12:10
has joined #pact-js

wilfried.vandenberghe
2020-11-19 12:19
has joined #pact-js

alan.hanafy
2020-11-19 19:28
has joined #pact-js

michael.deutscher
2020-11-19 21:39
has joined #pact-js

gerry.power
2020-11-20 03:31
has joined #pact-js

alex900
2020-11-20 05:08
has joined #pact-js

tomas.panik
2020-11-20 08:28
has joined #pact-js

marc.ferland
2020-11-20 14:43
has joined #pact-js

sebastien.crapoulet
2020-11-20 15:24
has joined #pact-js

adutrillaux
2020-11-20 15:28
has joined #pact-js

sebastien.crapoulet
2020-11-20 15:31
I'm hoping someone can help me, please do note I have little experience with Pact. I'm investigating integrating Pact tests with our E2E tests using Cypress. Obviously found https://pactflow.io/blog/cypress-pact-front-end-testing-with-confidence/. I know this is still a WIP plugin however I had a question that I would need clearing up: I would obviously like to setup some consumer/provider tests between our FE and our endpoints. My problem is, we need to run these E2E tests in a 'live' environment as we have no staging, and cannot test the features we would be testing when we want. The idea is, to use that plugin (when ready) to generate a mocked BE for cypress, avoiding triggering unwanted things in production. My question is: When a consumer provides a contract to the broker, does the broker consistently run the provider test, or does it simply used something cached on the broker which is given when the provider triggers a build? I hope this makes sense, trying to wrap my head around everything :slightly_smiling_face: Thanks!

he
2020-11-20 15:59
has joined #pact-js

ivgeni.slabkovski
2020-11-20 21:52
has joined #pact-js

matt.fellows
2020-11-20 23:48
Hi @sebastien.crapoulet! so first up, even if you use Cypress, you could still use Pact in your unit testing framework to get the benefits described in that post. This way, you don?t need a live environment at all.

matt.fellows
2020-11-20 23:49
Assuming there are (good) reasons to run Pact as part of your Cypress tests, you could borrow the code from the sample repository there as a starting point (in fact, we?ve been using Pact+Cypress at Pactflow for a few months now based on that post, so we should update the example with our recent learnings)

matt.fellows
2020-11-20 23:50
> My question is: When a consumer provides a contract to the broker, does the broker consistently run the provider test, or does it simply used something cached on the broker which is given when the provider triggers a build? The broker simply maintains the contract, versions it and stores information about the consumers that need it, and the providers that maintain it

matt.fellows
2020-11-20 23:50
So the broker never runs the test. The provider builds will fetch the contracts from the broker and run the pact tests in their CI pipeline

matt.fellows
2020-11-20 23:50
howtonirvana

2020-11-20 23:50
This workshop demonstrates those principles in action: https://docs.pactflow.io/docs/workshops/ci-cd/

matt.fellows
2020-11-20 23:51
:point_up: that workshops takes you through how to implement the effective pact setup guide as aka ?pact nirvana?

matt.fellows
2020-11-20 23:51
howtotutorial


matt.fellows
2020-11-20 23:52
:point_up: have a look at these tutorials firs, because you can do them in the browser and it should give you a better idea of how it all hangs together with the broker

serhatburakyildirim
2020-11-21 21:57
has joined #pact-js

przemyslaw.dabrowski
2020-11-22 11:46
Hello everyone, i am new to the pact. Right now i struggle with matching complex objects. I could not find any information how to match field with inherited types. Can you point me in the right direction ? My backend request body matcher looks like this: ``` export interface Cost { type: string; } export interface CppCost extends Cost { cpp: number; } export interface CpmCost extends Cost { someField: number; someField2: number; } export interface BackendRequest { a: number b: { a: string; b: Cost }[]; } const BACKEND_MATCHER = { c: string('a'), b: eachLike( {a: 'test', b: {cpp: 1, type: 'asd'}}, // CpmCost ?? {min: 2} ), }``` How do i match both Cost (CpmCost or CppCost) types ? In given example obviously only request with CppCosts works

matt.fellows
2020-11-22 12:37
In the current stable version, You need to write two tests to cover each case.

matt.fellows
2020-11-22 12:37
In our v3 branch, there is a new `arrayContains` matcher that I think could work for you.

przemyslaw.dabrowski
2020-11-22 12:51
Thank you for answer. I will check v3 branch. But in current version with two test cases i still wont cover case where array contains values with cpp and cpm at the same time? Am i correct ? [{b: {...} as CppCost}, {b: {...} as CppCost}]

alnasl
2020-11-22 18:46
has joined #pact-js

matt.fellows
2020-11-22 20:40
That's correct. You would usually use a provider state to ensure that only the values of the specific subtype are present in the response for each cases

abubics
2020-11-23 01:48
As an aside, being able to parse responses that have both types might be better positioned as a unit test.

ashutosh23802
2020-11-23 06:20
has joined #pact-js

przemyslaw.dabrowski
2020-11-23 08:58
One last question regarding v3 beta build - is there any example how use it with PactWeb ?

sebastien.crapoulet
2020-11-23 09:02
@matt.fellows thank you so much for your answer, it's clarified my needs :slightly_smiling_face:

matt.fellows
2020-11-23 10:32
ah, it?s not possible at the moment I?m afraid :disappointed:

matt.fellows
2020-11-23 10:32
Is this because you?re using Angular/Protractor?

matt.fellows
2020-11-23 10:33
If possible, use a server side test framework like Jest/Mocha/etc.

matt.fellows
2020-11-23 10:33
You?re welcome!

leonty
2020-11-23 10:33
has joined #pact-js

przemyslaw.dabrowski
2020-11-23 11:14
Yes, i am using pact with Angular. Again - Thank you very much for help ! :)

dariusz.piwko
2020-11-23 11:34
has joined #pact-js

dariusz.piwko
2020-11-23 11:34
Hi

dariusz.piwko
2020-11-23 11:35
@Matt, according to my last message to you I have a question about pact with graphql

dariusz.piwko
2020-11-23 11:35
```Key: - is expected + is actual Matching keys and values are not shown { "body": { - "query": /\s*query\s*getLineitems\s*\(\$limit:\s*Int,\s*\$offset:\s*Int,\s*\$sort:\s*JSON,\s*\$filter:\s*JSON,\s*\$isDetail:\s*Boolean\s*=\s*true\)\s*\{\s*dream_adserver\s*\{\s*lineitems\s*\}\s*\}/ + "query": "query getLineitems($limit: Int, $offset: Int, $sort: JSON, $filter: JSON, $isDetail: Boolean = true) {\n dream_adserver {\n lineitems {\n total_count\n __typename\n }\n __typename\n }\n}\n" } }```

dariusz.piwko
2020-11-23 11:37
If I make more than one nested query I have a error like above

dariusz.piwko
2020-11-23 11:39
```.withQuery( ` query getLineitems (\$limit: Int, \$offset: Int, \$sort: JSON, \$filter: JSON, \$isDetail: Boolean = true) { dream_adserver { lineitems } }`)``` It makes an error, but ```.withQuery( ` query getLineitems (\$limit: Int, \$offset: Int, \$sort: JSON, \$filter: JSON, \$isDetail: Boolean = true) { dream_adserver }`)``` works

matt.fellows
2020-11-23 12:09
Sorry! :pensive:

billal.patel
2020-11-23 12:46
Hi, I am in need of some help please :slightly_smiling_face: Our negative tests are failing on the verifier side. We have a scenario which consists of a POST request to URL like this: `https://domain.com/api/${empty}/12345` When hitting this same URL with the same headers/body in Postman, it returns the expected `400` however, on Postman, when I deform the URL such as this: `https://domain.com/error-api/${empty}/12345` I get `"message": "Missing Authentication Token"` It seems like the endpoint being passed on from the consumer side is getting malformed when the expected URL should be: `https://domain.com/api//12345` Any ideas or help with this would be really appreciated!

tjones
2020-11-23 12:47
Did you mean to write Pact in one of the places that says Postman?

tjones
2020-11-23 12:47
Are you able to share the relevant code snippedt?

tjones
2020-11-23 12:48
Where do you get "Missing Authentication Token"?

billal.patel
2020-11-23 12:50
Hey Tim! Thanks for getting back to me. Oh no, I did mean Postman. I was trying various forms of the URL to workout how to get the endpoint to `"Missing Authentication Token"` in ?real life? by using Postman

billal.patel
2020-11-23 12:51
Would you like the consumer side or the provider side? :slightly_smiling_face:

tjones
2020-11-23 13:23
Are you experiencing this error on the provider side? Perhaps the consumer test test that generates this expectation, then we can help you make a postman request that does it

tjones
2020-11-23 13:23
so, the missing auth token error is specifically coming from your real provider?

tjones
2020-11-23 13:23
Do you normally need an authentication token for this endpoint?

billal.patel
2020-11-23 13:59
Thanks for the help! So the error happens on the provider side (seems like when the provider side request is actually being made)

billal.patel
2020-11-23 14:00
I am able to see that error in Postman too. It occurs when the endpoint is not correct. So for example `https://my-url.com/endpoint//123` works but `https://my-url.com/invalid-endpoint//123` does not work

billal.patel
2020-11-23 14:01
What we are trying to test is the `//` part above which is basically validating what happens when the value passed through is empty

billal.patel
2020-11-23 14:01
I hope that makes some sense

billal.patel
2020-11-23 15:46
By the way, the URL (https://my-url.com) is set in the provider side in `providerBaseUrl` and the endpoint is set in the consumer side in `path`

billal.patel
2020-11-23 15:47
It seems like when they are combined in the request, something is getting messed up. However, when the provider side tests are run, I have no idea how to print/log the full actual URL that Pact generates

praneeth.kumar
2020-11-23 16:18
has joined #pact-js

jarmy
2020-11-23 23:40
Hi. We have branches (e.g. `task/GRNWEB-2077-fast-follow`) that are supposed to be added when a pact is published ```Publishing pacts to broker at: https://pact-broker.docker.savagebeast.com/ 12:16:50 [2020-11-23T20:16:50.640Z] INFO: pact-node@10.11.0/66205 on jenkins-build-agent-09: 12:16:50 12:16:50 Tagging version 548f6b61 of web as "task/GRNWEB-2077-fast-follow" 12:16:50 Publishing web/pegasus pact to pact broker at https://pact-broker.docker.savagebeast.com/``` However, the pact is uploaded but I'm not seeing that tag (or any like it) in our pact-broker (`2.57.0.0`). Is it possible the pact-broker is omitting tags with "/" in them?

jarmy
2020-11-24 00:26
copied ^ to #pact-broker

matt.fellows
2020-11-24 05:08
sorry, will follow this in #pact-broker Pretty sure it?s supported though!

dariusz.piwko
2020-11-24 09:00
@matt.fellows Could you help with topic above?

dariusz.piwko
2020-11-24 09:01
It seems regex doesn't work good

mark.white
2020-11-24 09:03
has joined #pact-js

tjones
2020-11-24 12:43
We're planning to add some better logging to pact-js's provider verification in the next couple of days (the feature is almost ready to go), but for now are you able to see the actual request in the provider logs?

tjones
2020-11-24 12:44
Also, if you could share the consumer test or the relevant part of the pact file, that would be very helpful

billal.patel
2020-11-24 12:54
Ah nice, better logging would be lovely! I can see the info/debug logging of the test, and the verification results that are published to the Pact Broker.

billal.patel
2020-11-24 13:07
Here is a snippet of the consumer test. Please note on line 17 the // which is what we are testing with the value missing

billal.patel
2020-11-24 13:07
I have been asked to rename the company related info but hopefully that still gives a good illustration of what is happening

tjones
2020-11-24 13:37
We sometimes see mismatches where eg the consumer test includes eg `/api/v1/` but the provider base URL also includes it, so the tests hit `/api/v1/api/v1`

tjones
2020-11-24 13:38
it looks like that's not what is happening here

tjones
2020-11-24 13:39
As an aside, this looks like sometime I wouldn't expect to be tested - usually you would only test the behaviour the consumer is relying on

tjones
2020-11-24 13:39
(but perhaps you do rely on this, I don't know)

tjones
2020-11-24 13:40
Also, the intention of state is to indicate any expected pre-conditions present at the provider, but it looks like you might be describing the request with it

tjones
2020-11-24 13:42
it's still weird though. Is `apiKey` the authentication token that the provider thinks is missing?

tjones
2020-11-24 13:43
I don't see a definition of `REQUEST_BODY` in that code, but I take it that you did match it with the one you tried in postman.

tjones
2020-11-24 13:45
My gut feeling is that the problem lies on the provider side, rather than in pact.

tjones
2020-11-24 13:46
I'll see if I can get some time to merge the extra logging code tomorrow, perhaps that will help.

tjones
2020-11-24 13:54
Hmm.... a google search suggests some Ruby tooling is used to replacing `//` with `/` in URLs (even though this is not correct, the rationale is that it is more likely to be a path traversal attack rather than intended, which.... is probably true). I wonder if the double slashes are not being faithfully reproduced by the Ruby code.

tjones
2020-11-24 13:55
(pact-js is backed by the ruby pact binaries)

tjones
2020-11-24 13:55
I'll do some more digging in the morning

billal.patel
2020-11-24 14:26
Thank you so much for the detailed responses. This is more of a negative test which we would like to cover if possible. The API key is something that the endpoint expects and the provider side adds in the headers

billal.patel
2020-11-24 14:27
That Ruby info you sent seems exactly like what we?re facing because when I hit the endpoint in Postman with just 1 / instead of // it displayed the `"message": "Missing Authentication Token"` error we see in this Pact test

billal.patel
2020-11-24 14:27
I do really appreciate you looking in to this :slightly_smiling_face:

ufuk.ozcelik
2020-11-24 14:58
has joined #pact-js

stefanos.varsanis
2020-11-24 16:48
has joined #pact-js

lalexander2810
2020-11-24 16:53
has joined #pact-js

sivaprasad9
2020-11-24 20:46
has joined #pact-js

matt.fellows
2020-11-25 07:34
hmm, yes it could just be a bad regex trying to glob the space

matt.fellows
2020-11-25 07:34
I believe there is at least one issue on pact-js that matches this - have you had a look to see?

matt.fellows
2020-11-25 07:34
I haven?t had a chance to put together a more complex gql example for a while, so would need to get back into that headspace

matt.fellows
2020-11-25 07:35
ultimately, you could always avoid using the graphql interface in Pact JS and perform your own request matching (with your own crafted regex).

matt.fellows
2020-11-25 07:35
I?d like to fully support it in the Pact DSL, but that would require substantial changes across the ecosystem (still on the cards, but a long term roadmap item)

dariusz.piwko
2020-11-25 09:10
Thanks for the reply. Do you have any example to use own request mathing? What do you mean about that?

matt.fellows
2020-11-25 11:44
Well, a standard Pact tests just needs to be told what request its expecting

matt.fellows
2020-11-25 11:45
``` provider .given("is authenticated") .uponReceiving("a request to create a new mate") .withRequest({ method: "POST", path: "/graphqlendpoint", body: "<put gql query here>", }) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: "<put expected response here>", })```

matt.fellows
2020-11-25 11:47
GraphQL is just an abstraction over HTTP, so if the GraphQL interface isn?t working, you can always fall back to the standard pact test interface to get more specific matching happening

matt.fellows
2020-11-25 11:48
I believe the issue is that the regex the GraphQL interface is trying to apply is not working for all circumstances ```const escapeRegexChars = (s: string) => s.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")``` That?s what is currently used to match the expected query with the actual one

scyr
2020-11-25 14:56
has joined #pact-js

timotheus.ruprecht
2020-11-25 22:12
has joined #pact-js

tjones
2020-11-26 00:42
@billal.patel: I've looked into this a bit, and I can't reproduce it yet. If I set up an interaction with `/foo//bar`, then the provider does get the request correctly, so Ruby isn't the culprit.

tjones
2020-11-26 00:42
Can you confirm that the expected URL is present in your pact file?

tjones
2020-11-26 00:43
It might help if you're able to create a repository that reproduces the problem, then we can take a look

tjones
2020-11-26 00:44
I'll also try to get that improved logging out to you soon (haven't had as much time for Pact dev this week as I would like)

tjones
2020-11-26 01:05
also, which versions of pact and pact-node are you using? You can find out with `npm ls @pact-foundation/pact-node`

abhi.nandan
2020-11-26 07:13
Hi, I am using `pathFromProviderState` in pact-jvm for injecting values from provider state. What is the pact-js equivalent of that? is there any example available?

tjones
2020-11-26 08:11
Hi! This is a pact spec V3 feature, which is currently not available in the stable release. However, you can try the beta v3 release, following the instructions here: https://github.com/pact-foundation/pact-js#pact-js-v3 There's an example of the provider state here:


abhi.nandan
2020-11-26 08:26
thanks @tjones

billal.patel
2020-11-26 09:46
Hey Tim. Thanks for looking in that for me

billal.patel
2020-11-26 09:46
I have checked in the Pact json file and the path does have a `//` in there

billal.patel
2020-11-26 09:47
The version I am using is: @ pact-foundation/pact-node@9.13.0 ??? @ pact_foundation/pact-node@10.11.0

manali.mogre
2020-11-26 11:44
has joined #pact-js

erik.terpstra
2020-11-26 12:08
has joined #pact-js

kjayachandra2000
2020-11-26 20:40
has joined #pact-js

kjayachandra2000
2020-11-26 22:00
@kjayachandra2000 has left the channel

sushil.kumar
2020-11-27 01:45
has joined #pact-js

zhujian
2020-11-27 07:54
has joined #pact-js

h.octavian
2020-11-27 14:08
has joined #pact-js

noel
2020-11-28 23:12
has joined #pact-js

dariusz.piwko
2020-11-29 22:01
It seems your regex is correct ```function validateExample(example, matcher) { // Note we escape the double \\ as these get sent over the wire as JSON console.log('MATCHER', matcher); console.log('EXAMPLE', example); console.log('**************************', new RegExp(matcher.replace("\\\\", "\\")).test(example)); return new RegExp(matcher.replace("\\\\", "\\")).test(example); }``` returns true

dariusz.piwko
2020-11-29 22:02
I have a problem here

dariusz.piwko
2020-11-29 22:15
Do you have any idea how to fix this?

matt.fellows
2020-11-29 23:06
what does the log file say?

muraalee
2020-11-30 01:56
has joined #pact-js

dariusz.piwko
2020-11-30 07:45
I don't understand because as you can see above when I console matcher, it says true but log file says:

matt.fellows
2020-11-30 08:38
__typename doesn't look to be in the original test code

dariusz.piwko
2020-11-30 08:44
__typename code is added by gql tag, and is an optional parameter

dariusz.piwko
2020-11-30 08:45
Do you think that __typename is a problem?

matt.fellows
2020-11-30 08:45
Well right now you're sending it over the wire, and the regex is not expecting it. So it is a problem.

matt.fellows
2020-11-30 08:46
One option would be to make the regex smarter for that case

matt.fellows
2020-11-30 08:46
(or somehow the DSL)

dariusz.piwko
2020-11-30 08:47
I am not sending that, __typename is added automatically

matt.fellows
2020-11-30 08:47
Hmm

dariusz.piwko
2020-11-30 08:47
But it occurs when I have 2 or more nested query

matt.fellows
2020-11-30 08:47
Right

dariusz.piwko
2020-11-30 08:48
And this is the place when I have a problem

matt.fellows
2020-11-30 08:48
Could you pls raise a bug?

matt.fellows
2020-11-30 08:48
We can flesh out the fix there

dariusz.piwko
2020-11-30 08:48
Sure

matt.fellows
2020-11-30 08:49
If typename always is appended, we could probably fix it pretty easy

pooja.sharma
2020-11-30 08:52
has joined #pact-js

dariusz.piwko
2020-11-30 09:07
I dont't know if it will be a good solution. Sometimes I need to get __typename in query

matt.fellows
2020-11-30 09:23
Could you please elaborate on that?

mo
2020-11-30 09:24
has joined #pact-js

matt.fellows
2020-11-30 09:25
In your case, you can drop the use of the graphql interface and use the regular HTTP one

dariusz.piwko
2020-11-30 09:26
I don't understand how it should work? Why I should drop the use of the graphql if I use it in my apps?

dariusz.piwko
2020-11-30 09:26
Are you familiar with graphql?

matt.fellows
2020-11-30 09:26
Just the pact test interface, not your actual graphql code :rolling_on_the_floor_laughing: Then you won't be hitting the issue of the framework inserting things that weren't there

matt.fellows
2020-11-30 09:27
Have a look at the code in Pact JS that adds the graphql interface. It's not very clever

matt.fellows
2020-11-30 09:28
You could do what it does more precisely until the bug is fixed (if it can be done in a nice way of course)

matt.fellows
2020-11-30 09:33
Graphql is simply an abstraction over HTTP, so the usual pact approach works just fine

dariusz.piwko
2020-11-30 11:25
Yes, I understand that graphql is an abstraction over http but I don get it what do you mean by saying the usual pact approach works just fine

dariusz.piwko
2020-11-30 13:11
And what with the sign the contract by provider?

david.greene
2020-11-30 21:47
has joined #pact-js

matt.fellows
2020-11-30 22:43
Instead of something like this: ``` const graphqlQuery = new GraphQLInteraction() .uponReceiving("a hello request") .withQuery( ` query HelloQuery { hello } ` ) .withOperation("HelloQuery") .withRequest({ path: "/graphql", method: "POST", }) .withVariables({ foo: "bar", }) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { data: { hello: like("Hello world!"), }, }, })```

matt.fellows
2020-11-30 22:49
do somethnig like this: ``` provider.addInteraction({ uponReceiving: "a hello request", withRequest: { method: "POST", headers: { "content-type": "application/json" }, path: "/", // make this bit look like what your code does body: { operationName: "helloOperation", variables: { /* key/value pairs... */}, query: regex({ generate: `query HelloQuery { hello }`, matcher: "your regex that matches your request here, if you can't control the exact spacing" }) } }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { data: { hello: like("Hello world!"), }, }, } })```

bas
2020-12-01 09:00
has joined #pact-js

wainstead
2020-12-01 14:57
has joined #pact-js

jerobinson
2020-12-01 20:32
has joined #pact-js

dariusz.piwko
2020-12-01 23:15
provider.finalize() should terminate the server?

dariusz.piwko
2020-12-01 23:25
I have the very last question. How can I share one mock pact server between spec files?


matt.fellows
2020-12-01 23:36
Yes, `finalize()` saves the pact and shuts down the server: https://github.com/pact-foundation/pact-js/#api

sumedhagamage
2020-12-02 03:33
has joined #pact-js

fealaer
2020-12-02 11:40
has joined #pact-js

patrick.hendron
2020-12-02 14:44
has joined #pact-js

lpratt
2020-12-02 18:19
has joined #pact-js

dariusz.piwko
2020-12-03 08:54
How to test mutations instead of query with graphql interactions?

sandragnzalez
2020-12-03 11:04
has joined #pact-js

sschectman
2020-12-03 14:29
has joined #pact-js

sschectman
2020-12-03 14:32
I am testing a get route and some of the keys can return null or a string, is there a matcher I can use for this?

kristian
2020-12-03 14:34
has joined #pact-js

patrick.hendron
2020-12-03 17:51
Hey all :slightly_smiling_face:, Writing my first PACT tests. Just wondering, i'm writing a simple PACT test, where it checks when we send a GET to a endpoint it will respond with a JSON object. I don't care how many arrays are returned within the object, I just care about the data type of the key-value's with the object if that makes sense? Would the `MinType` matcher be suitable for this, set `MinType` to 1. The reason im wondering is I can mock the provider response on the consumer side like so ```[ { "firstName": "Joe", "lastName": "Blogs", "age": 26, }, { "firstName": "Joe", "lastName": "Blogs", "age": 23, }, ]``` When I create a contract and run it on the provider side, the actual provider response could have numerous arrays within the response, what I don't care about, I just care the Lastname, firstname and age are present and are the correct type. Thanks for reading :slightly_smiling_face:

matt.fellows
2020-12-03 20:50
See the sections on optional matching on http://docs.pact.io. You need to write two separate tests

matt.fellows
2020-12-03 20:50
You want the `eachLike` matcher

patrick.hendron
2020-12-03 21:05
yep, that works! thanks so much Matt, sorry for the newbie question :joy: , this slack set up is great by the way!

dariusz.piwko
2020-12-03 22:17
Thank you for all your help with pactjs

dariusz.piwko
2020-12-03 22:21
There is any posibillity to test mutations and subscriptions?

me1466
2020-12-03 23:42
has joined #pact-js

matt.fellows
2020-12-04 00:27
the same way as queries?

matt.fellows
2020-12-04 00:27
What have you tried that?s not working?

matt.fellows
2020-12-04 00:29
all good. Sorry for the brief response, was handling small children at the time :stuck_out_tongue:

matt.fellows
2020-12-04 00:29
better to be succinct that not respond!

tjones
2020-12-04 05:29
Also, newbie questions are very welcome, @patrick.hendron - we're here for all questions, from new or experienced users.

patrick.hendron
2020-12-04 10:08
thanks guys!

wenfeng.li
2020-12-04 11:42
has joined #pact-js

brendan.donegan
2020-12-04 12:37
QQ - does pact-js support teardown in provider states?

matt.fellows
2020-12-04 13:18
Nope, but easily added. If you wouldn?t mind creating a request for tracking we can get it added


matt.fellows
2020-12-04 13:36
:point_up:

matt.fellows
2020-12-04 13:37
yes please!

brendan.donegan
2020-12-04 13:45
oh that?s handy :smile:

brendan.donegan
2020-12-04 13:45
I was going to post the link here

matt.fellows
2020-12-04 13:47
:smile:

matt.fellows
2020-12-04 13:47
thanks!

cdambo
2020-12-05 11:59
has joined #pact-js

dariusz.piwko
2020-12-07 07:23
What to add instead of withQuery? ```const graphqlQuery = new GraphQLInteraction() .uponReceiving('a app info request') .withQuery(getAppInfoQuery) .withOperation('getSth') .withRequest({ path: '/my/v1/', method: 'POST', }) .withVariables({}) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json', }, body: { data: like(data) } });```

dariusz.piwko
2020-12-07 07:39
withMutation doesn't work. I was looking for an example in docs, but I didin't found,

matt.fellows
2020-12-07 07:39
Ah, I see what you mean. I thought you were referring to the standard DSL

matt.fellows
2020-12-07 07:40
we should add a method `withMutation` (just for readability). In the end, you can still use `withQuery` I think

dariusz.piwko
2020-12-07 07:41
Yes, but .withOperation('getSth') doesn't work in this case

dariusz.piwko
2020-12-07 07:42
Let me remind you, we have also subscription

matt.fellows
2020-12-07 07:42
Gotcha. It?s been a while since I?ve done GraphQL, so don?t have it all fresh in my mind.

matt.fellows
2020-12-07 07:42
If you wanted to pop a request on pact js issues with a feature enhancement (as you?re going through this) I?ll take a look at it and find a way to make it more ergonomic

dariusz.piwko
2020-12-07 07:45
Ok, thanks. Do you have an idea how to use mutations and subscriptions so far in graphql interactions?

matt.fellows
2020-12-07 08:01
Subscriptions might be hard, if I understand correctly that will require a bi-directional channel (e.g. websockets) - correct?

matt.fellows
2020-12-07 08:01
at least, with the current DSL. We do support ?message? pact, but nothing first class for GraphQL

matt.fellows
2020-12-07 08:01
I think mutations should mostly work the same as queries

dariusz.piwko
2020-12-07 08:02
About subscriptions you are right. About mutations, I tried to use the same as queries but without a success

gayatree.eee
2020-12-08 04:50
has joined #pact-js

billal.patel
2020-12-08 10:06
Hey Tom, hope you?re good

billal.patel
2020-12-08 10:06
Did you get anywhere with this update?

billal.patel
2020-12-08 10:06
RE: Logging

tjones
2020-12-08 10:07
hi! apologies, I haven't had the chance to look in to it yet.

tjones
2020-12-08 10:08
I'm not actually sure that improved logging will help very much, since I couldn't reproduce it locally

tjones
2020-12-08 10:10
It *is* confusing, though, so I would like to get to the bottom of it

c.pavan1986
2020-12-09 04:18
has joined #pact-js

william.pritchard
2020-12-09 15:28
has joined #pact-js

parveshchaudhary111
2020-12-09 17:54
has joined #pact-js

billal.patel
2020-12-10 10:37
Yeah, very confusing :joy:

billal.patel
2020-12-10 10:38
I am happy to jump on a call with you sometime if that would be easier? That way I can share my screen with the real project rather than creating a dummy project which might not be a true representation of it

w.sobasik
2020-12-10 10:39
has joined #pact-js

tjones
2020-12-11 05:28
We can do that. I'll send you a pm.

thanuxxxx
2020-12-12 22:41
has joined #pact-js

dariusz.piwko
2020-12-12 22:42
Any ideas? I have files with mutation which I need to use in tests

dariusz.piwko
2020-12-12 22:42
```mutation mutationname { sth { set_sth { hit { id } } } }```

dariusz.piwko
2020-12-12 22:42
instead of query I use mutation key word

matt.fellows
2020-12-13 02:46
Ah, please raise a request on GitHub. Obviously when we pass to Apollo to validate it's for a query.

matt.fellows
2020-12-13 02:46
As I said, I'd recommend not using the graphql interface and use the standard HTTP DSL because of these current restrictions

ian.hamilton
2020-12-13 06:53
has joined #pact-js

colm.j.murphy91
2020-12-13 07:02
has joined #pact-js

victoria.kruczek
2020-12-13 14:13
has joined #pact-js

wuddarwin
2020-12-14 05:23
has joined #pact-js

connor.aird
2020-12-14 15:52
has joined #pact-js

arman.najafian
2020-12-14 15:52
has joined #pact-js

praveen.lakkaraju
2020-12-14 16:12
has joined #pact-js

alejandro.germain
2020-12-14 16:26
has joined #pact-js

josh.ellinger
2020-12-15 01:22
has joined #pact-js

nikitsenka
2020-12-15 09:35
has joined #pact-js

hibahawes
2020-12-15 09:53
has joined #pact-js

sarvar
2020-12-15 14:24
has joined #pact-js

suruchipatidar14
2020-12-16 05:35
has joined #pact-js

smatheson
2020-12-16 06:33
has joined #pact-js

olayemifolakemi
2020-12-16 15:23
has joined #pact-js

nouri.tawfik
2020-12-16 19:21
has joined #pact-js

ania.kovalchuk
2020-12-17 00:09
has joined #pact-js

writetojoshma
2020-12-17 05:52
has joined #pact-js

writetojoshma
2020-12-17 06:46
Hi All

writetojoshma
2020-12-17 06:46
Pact Binary Error: C:/Users/**/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.3/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.6.2/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': cannot load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError) from C:/Users/**/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.3/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.6.2/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `<top (required)>'

writetojoshma
2020-12-17 06:46
I am getting the above error

writetojoshma
2020-12-17 06:46
Any help ?

writetojoshma
2020-12-17 06:46
I am using "@greet_bot/pact": "^10.0.0-beta.22"

tjones
2020-12-17 06:46
Do you have any spaces in your path?


writetojoshma
2020-12-17 06:47
I am not sure what long path issue is

matt.fellows
2020-12-17 06:47
It?s the issue I just linked to you before Joshma

matt.fellows
2020-12-17 06:47
Windows has a restriction on how long a file path can be

matt.fellows
2020-12-17 06:47
?because it?s 2020, the dark age of technology

writetojoshma
2020-12-17 06:48
Oh Okay

writetojoshma
2020-12-17 06:48
so how to fix it

matt.fellows
2020-12-17 06:49
did you read the issue? If not, read the issue


writetojoshma
2020-12-17 06:49
sure

matt.fellows
2020-12-17 06:49
but before you do that - and this is just a shot in the dark - try this

matt.fellows
2020-12-17 06:49
```PACT_SKIP_BINARY_INSTALL=true npm i @pact-foundation/pact@beta```

writetojoshma
2020-12-17 06:49
sure Matt

writetojoshma
2020-12-17 06:49
Thank You

matt.fellows
2020-12-17 06:49
ahhh actually

matt.fellows
2020-12-17 06:50
please share your code. I think even though you?ve installed the new beta package, you?re still using the current package

tjones
2020-12-17 06:50
It looks like the error is coming from the pact ruby binary

matt.fellows
2020-12-17 06:50
it sure is

matt.fellows
2020-12-17 06:50
I thought perhaps that the ruby code was being ?tested? on install, so skipping that in pact-node would bypass it. But actually, that ruby code path makes no sense to be invoked at that stage

writetojoshma
2020-12-17 06:51
ohh okay

matt.fellows
2020-12-17 06:51
I suspect it?s that you?re still using the current package exports, and not the new beta ones-


matt.fellows
2020-12-17 06:51
There are examples there, steps to use the package etc.

matt.fellows
2020-12-17 06:52
Specifically `const { PactV3, MatchersV3 } = require("@pact-foundation/pact/v3")` <- note the new package

writetojoshma
2020-12-17 06:52
Oh Okay

writetojoshma
2020-12-17 06:52
sorry i forgot to change it there

matt.fellows
2020-12-17 06:52
ah yes, windows. You?ll need to translate that to windows shell. But don?t bother, I?m not convinced it will help at all after thinking it through.

tjones
2020-12-17 06:52
As an aside, @matt.fellows: I bought a windows machine, so we can *finally* be in a better position to diagnose and fix these issues

writetojoshma
2020-12-17 06:52
u are right

matt.fellows
2020-12-17 06:53
What! The solution is to stop supporting Windows :troll:

tjones
2020-12-17 06:53
Well, that's not the reason I bought it. Also, Cyberpunk 2077 is currently competing with pact development time. Sorry about that.

matt.fellows
2020-12-17 06:53
That?s ok. I selfishly had 2 children which do the same

writetojoshma
2020-12-17 06:53
const { Pact, GraphQLInteraction } = require("@pact-foundation/pact/v3");

matt.fellows
2020-12-17 06:53
and now I can?t use ?train time?

writetojoshma
2020-12-17 06:53
can i use this way

writetojoshma
2020-12-17 06:53
is it right

matt.fellows
2020-12-17 06:54
argh, OK. That?s not yet in the beta package - of course that was going to happen

tjones
2020-12-17 06:54
> I selfishly had 2 children I can't believe you'd do that to us

writetojoshma
2020-12-17 06:54
I am using GraphQLInteraction

writetojoshma
2020-12-17 06:54
so how will i do this

matt.fellows
2020-12-17 06:56
so you?re options: 1. Stick with the existing package, and work through the long path options in the issue shared 2. Move to the beta package, but don?t use the GraphQLInteraction type, and just use the standard http interface (GraphQL is just a thin wrapper over the usual interface) 3. Move to the beta package, submit a PR that implements the GraphQL interface to pact JS (you can use the existing interface as a guide to do this) 4. Submit an issue requesting it in the beta package (will take longer)

matt.fellows
2020-12-17 06:57
It was two separate moments of temporary insanity

writetojoshma
2020-12-17 06:57
I think option 1 will work for me

writetojoshma
2020-12-17 06:57
I need to test GraphQL using PACT

writetojoshma
2020-12-17 06:58
Thanks for ur options

writetojoshma
2020-12-17 06:59
I tried this

writetojoshma
2020-12-17 06:59
is this not the way ?

matt.fellows
2020-12-17 07:00
sorry, that was for a separate problem. Don?t worry about that for now

writetojoshma
2020-12-17 07:00
oh okay


writetojoshma
2020-12-17 07:00
Okay

tjones
2020-12-17 07:00
@matt.fellows: I've renamed #pact-js-spec-v3 to #pact-js-development, since I often want to post things here about development, but don't want to clutter the questions and user conversations. Can we get the issue / PR tracker redirected there? I think tracking the releases here is still best.

writetojoshma
2020-12-17 07:00
so i should reduce the length of my file path

matt.fellows
2020-12-17 07:01
Yeah, the simplest thing is to move the project closest to the volume root e.g. `C:/project` instead of `C:/path/to/home/and/then/my/project/dir`

writetojoshma
2020-12-17 07:01
got it

writetojoshma
2020-12-17 07:01
thanks

writetojoshma
2020-12-17 07:01
let me try

writetojoshma
2020-12-17 07:01
this is a bad error

matt.fellows
2020-12-17 07:01
:point_up:

matt.fellows
2020-12-17 07:02
I think so. I?ll try :slightly_smiling_face:

matt.fellows
2020-12-17 07:02
/github subscribe list

matt.fellows
2020-12-17 07:04
/github unsubscribe pact-foundation/pact

matt.fellows
2020-12-17 07:04
/github subscribe pact-foundation/pact-js releases

tjones
2020-12-17 07:05
Yes, we could improve that. I'll make an issue for it.

matt.fellows
2020-12-17 07:09
/github unsubscribe pact-foundation/pact-js issues

matt.fellows
2020-12-17 07:09
/github unsubscribe pact-foundation/pact-js pulls,statuses

matt.fellows
2020-12-17 07:09
:point_up: @tjones I think we?re there. Just releases here nwo

tjones
2020-12-17 07:16
@writetojoshma I've opened https://github.com/pact-foundation/pact-node/issues/248 to improve this situation in the future.

tjones
2020-12-17 07:17
Thank you @matt.fellows :taco:

matt.fellows
2020-12-17 07:21
yum!

writetojoshma
2020-12-17 07:21
Oh Great Tim

writetojoshma
2020-12-17 07:22
yes error message doesnt give any idea about long pathing

writetojoshma
2020-12-17 08:48
yes Tim

writetojoshma
2020-12-17 08:48
it worked for me

writetojoshma
2020-12-17 08:49
it was long path issue

writetojoshma
2020-12-17 09:42
'PACT_BROKER_TOKEN' is not recognized as an internal or external command, operable program or batch file.

writetojoshma
2020-12-17 09:42
Any idea how to fix this

tjones
2020-12-17 09:43
It sounds like you might have an environment variable specified in the wrong place

tjones
2020-12-17 09:43
can you share your code?

tjones
2020-12-17 09:43
When are you getting this error?

writetojoshma
2020-12-17 09:45
I am sorry , i cannot share code due to some policy of my company

writetojoshma
2020-12-17 09:45
terter

tjones
2020-12-17 09:45
^ You may want to edit that so that it doesn't include the token

writetojoshma
2020-12-17 09:45
in my package.jsom

writetojoshma
2020-12-17 09:45
"publish-pact": "PACT_BROKER_TOKEN=lWfa0BuoFgduhZR6rutOxQ PACT_BROKER_URL=https://jjohn.pactflow.io node publish.js",

tjones
2020-12-17 09:46
Ah, this is not a pact problem, this is a windows problem

writetojoshma
2020-12-17 09:46
then how to frame it

tjones
2020-12-17 09:46
(I recommend editing both your posts to remove the token, since this slack channel is public)

tjones
2020-12-17 09:47
So, those environment variables are set the linux way

writetojoshma
2020-12-17 09:47
ertert

tjones
2020-12-17 09:47
I would look in to `cross-env` to solve this:

tjones
2020-12-17 09:47
`npm install -D cross-env`

tjones
2020-12-17 09:48
then change your commands to be: ```"publish-pact": "cross-env PACT_BROKER_TOKEN=<YOUR TOKEN> PACT_BROKER_URL=<YOUR BROKER URL> node publish.js",```


writetojoshma
2020-12-17 09:49
oh thanks a lot

writetojoshma
2020-12-17 09:49
i will try it

writetojoshma
2020-12-17 09:49
you guys are of great help

tjones
2020-12-17 09:49
You're welcome!

writetojoshma
2020-12-17 10:10
PS C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2> npm run publish-pact npm ERR! code EJSONPARSE npm ERR! file C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\package.json npm ERR! JSON.parse Failed to parse json npm ERR! JSON.parse Unexpected token in JSON at position 372 while parsing near '... npm ERR! JSON.parse "publish-pact": "cross-env PACT_BRO...' npm ERR! JSON.parse Failed to parse package.json data. npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.

writetojoshma
2020-12-17 10:11
any idea

tjones
2020-12-17 10:12
Your package.json is malformed (not valid json)

writetojoshma
2020-12-17 10:12
ohh

tjones
2020-12-17 10:12
I suspect this is a missing comma

tjones
2020-12-17 10:13
(since that's the mistake I personally make when editing json)

writetojoshma
2020-12-17 10:14
okay let me check

writetojoshma
2020-12-17 10:22
PS C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\test\pact_framework> npm run publish-pact > pact-contract-testing@1.0.0 publish-pact C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2 > cross-env PACT_BROKER_TOKEN=XXXX PACT_BROKER_URL=XXXX node publish.js

writetojoshma
2020-12-17 10:22
I didnt get any error

writetojoshma
2020-12-17 10:22
so this looks like my contract is published

writetojoshma
2020-12-17 10:22
how can i see my contract

tjones
2020-12-17 10:23
If you want to see it, you can log in to the broker in your web browser

tjones
2020-12-17 10:24
your provider verification step will download it (if configured correctly)

writetojoshma
2020-12-17 10:27
yes i logged in

writetojoshma
2020-12-17 10:28
but i can see example api , example app

writetojoshma
2020-12-17 10:28
not mine

writetojoshma
2020-12-17 10:29
i guess Is it inside overview ?

tjones
2020-12-17 10:29
Sounds like you're using pactflow? You should see your new pairing on the left, I think

tjones
2020-12-17 10:29
You can remove the example, I found that helpful

tjones
2020-12-17 10:29
Are you using the read/write token?

writetojoshma
2020-12-17 10:34
Yes I am using pactflow

writetojoshma
2020-12-17 10:34
no read only token

tjones
2020-12-17 10:35
You won't be able to publish a contract with the read only token

tjones
2020-12-17 10:35
I am surprised your script didn't error

tjones
2020-12-17 10:35
`node publish.js` <-- it depends whether this publish script does any error handling

writetojoshma
2020-12-17 10:35
see my pact hasnt come up

writetojoshma
2020-12-17 10:36
oh okay

tjones
2020-12-17 10:36
We used to have examples with `publish.js` in them, but it's better to use the binaries directly

writetojoshma
2020-12-17 10:36
so shall i use read/write token

tjones
2020-12-17 10:36
are you following an example? We should update it so it doesn't use publish.js

writetojoshma
2020-12-17 10:37
"scripts":{ "test":"npm run clean && npm run test:consumer && npm run test:publish && npm run test:provider", "start":"nodemon handler-local.ts", "test-consumer":"nyc --reporter=text-summary mocha test/**/consumer.spec.js --timeout 60000", "publish-pact":"cross-env PACT_BROKER_TOKEN=XXXX PACT_BROKER_URL=XXXX node publish.js", "test-provider":"PACT_BROKER_TOKEN=XXX PACT_BROKER_URL=XXX nyc --reporter=text-summary mocha -t 10000 provider.spec.js" },

writetojoshma
2020-12-17 10:37
this is my script in package.json looks like

writetojoshma
2020-12-17 10:37
how u want me to edit

writetojoshma
2020-12-17 10:38
```npm run publish-pact - i use this command```

tjones
2020-12-17 10:38
`pact-broker publish pacts --consumer-app-version=<whatever your version is> --broker-base-url=<Whatever your broker url is> --broker-token=<whatever your broker token is>`

tjones
2020-12-17 10:38
this is the command for publishing using the binaries directly

tjones
2020-12-17 10:38
```"publish-pact":"pact-broker publish pacts --consumer-app-version=<whatever your version is> --broker-base-url=<Whatever your broker url is> --broker-token=<whatever your broker token is>",```

tjones
2020-12-17 10:39
Are you following a tutorial, or did you create the `publish-pact` script yourself?

writetojoshma
2020-12-17 10:40
nope

writetojoshma
2020-12-17 10:40
i got a github sample project


tjones
2020-12-17 10:41
hm ok. That's not one of ours.

writetojoshma
2020-12-17 10:41
oh great

writetojoshma
2020-12-17 10:42
for consumer-app-version can i give some random value

writetojoshma
2020-12-17 10:42
like v1

tjones
2020-12-17 10:42
Pact needs to know what version your application is.

tjones
2020-12-17 10:43
you can read it out of the package json

writetojoshma
2020-12-17 10:43
got it

writetojoshma
2020-12-17 10:43
should i add cross-env also

tjones
2020-12-17 10:43
That example project hardcodes it to 1.0.2, which is not good practice

writetojoshma
2020-12-17 10:44
in the command

tjones
2020-12-17 10:44
if you are setting environment variables in windows, you will need cross-env

writetojoshma
2020-12-17 10:44
okay

writetojoshma
2020-12-17 10:44
thanks

tjones
2020-12-17 10:45
I was more saying that you don't need to use a custom `publish.js` - I find it easier not to

tjones
2020-12-17 10:45
We have several examples in the pact-js repository - for graph-ql, check out: https://github.com/pact-foundation/pact-js/tree/master/examples/graphql

tjones
2020-12-17 10:46
It has a custom publish.js (this used to be a common pattern), but this one has more functionality

tjones
2020-12-17 10:46
(for example, it gets the version from the git sha)

tjones
2020-12-17 10:46
https://docs.pact.io/getting_started/versioning_in_the_pact_broker/ ^ See this page for a good discussion on what is important in a pact version

writetojoshma
2020-12-17 10:49
okay..thanks

writetojoshma
2020-12-17 10:51
Publishing GraphQLConsumer/GraphQLProvider pact to pact broker at https:XXXX The latest version of this pact can be accessed at the following URL (use this to configure the provider verification): https:XXXXio/pacts/provider/GraphQLProvider/consumer/GraphQLConsumer/latest

writetojoshma
2020-12-17 10:51
Hey wow i got it

tjones
2020-12-17 10:51
Awesome!

writetojoshma
2020-12-17 10:57
I find it wonderful to work along with you

writetojoshma
2020-12-17 10:57
otherwise it wouldnt have been possible so fast

writetojoshma
2020-12-17 10:57
I really appreciate this platform

writetojoshma
2020-12-17 10:57
never seen anything like this before

tjones
2020-12-17 10:57
You're so welcome! Glad to help

writetojoshma
2020-12-17 10:57
My next goal is to test my provider against the pact

rejeesh.g
2020-12-17 11:07
has joined #pact-js

writetojoshma
2020-12-17 11:16
providerBaseUrl: 'http://localhost:51457',

writetojoshma
2020-12-17 11:17
SO i should always have my provider in this port

writetojoshma
2020-12-17 11:17
for PACT ?

writetojoshma
2020-12-17 11:17
can i give some other port

writetojoshma
2020-12-17 11:27
Hey

writetojoshma
2020-12-17 12:16
Pact Verification [2020-12-17T12:14:40.485Z] INFO: pact@9.13.0/17780 on TVMATP255345: Verifying provider [2020-12-17T12:14:40.514Z] INFO: pact-node@10.11.0/17780 on TVMATP255345: Verifying Pacts. 1) validates the contract provided by the consumer 0 passing (143ms) 1 failing 1) Pact Verification validates the contract provided by the consumer: Error: Must provide the pactUrls argument if no pactBrokerUrl provided at new Verifier (node_modules\@pact-foundation\pact-node\src\verifier.js:107:19) at Object.default (node_modules\@pact-foundation\pact-node\src\verifier.js:190:48) at Pact.verifyPacts (node_modules\@pact-foundation\pact-node\src\pact.js:102:34) at C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\node_modules\@pact-foundation\pact\dsl\verifier.js:74:59 at processTicksAndRejections (internal/process/task_queues.js:93:5)

tjones
2020-12-17 12:29
Yep, you can configure it with whatever port your provider runs on.

writetojoshma
2020-12-17 12:37
Hey Tim

writetojoshma
2020-12-17 12:37
okay

writetojoshma
2020-12-17 12:38
i have one doubt

writetojoshma
2020-12-17 12:38
Pact Verification [2020-12-17T12:14:40.485Z] INFO: pact@9.13.0/17780 on TVMATP25565L: Verifying provider [2020-12-17T12:14:40.514Z] INFO: pact-node@10.11.0/17780 on TVMATP25456L: Verifying Pacts. 1) validates the contract provided by the consumer 0 passing (143ms) 1 failing 1) Pact Verification validates the contract provided by the consumer: validates the contract provided by the consumer: Error: Must provide the pactUrls argument if no pactBrokerUrl provided at new Verifier (node_modules\@pact-foundation\pact-node\src\verifier.js:107:19) at Object.default (node_modules\@pact-foundation\pact-node\src\verifier.js:190:48) at Pact.verifyPacts (node_modules\@pact-foundation\pact-node\src\pact.js:102:34) at C:\Z_TS_GQL_POC_2\Z_TS_GQL_POC_2\node_modules\@pact-foundation\pact\dsl\verifier.js:74:59 at processTicksAndRejections (internal/process/task_queues.js:93:5)

writetojoshma
2020-12-17 12:39
any idea ?

lukas.kempec
2020-12-17 12:45
has joined #pact-js

tjones
2020-12-17 12:50
In the error message it is saying that you need to tell it the broker URL

tjones
2020-12-17 12:51
I would check the script you are using to run validation

writetojoshma
2020-12-17 12:51
okay

writetojoshma
2020-12-17 12:52
describe('Pact Verification', () => {   it('validates the contract provided by the consumer', () => {     const opts = {       provider: 'GraphQLProvider',       providerBaseUrl: 'http://localhost:4000',       pactBrokerUrl: PACT_BROKER_URL,       pactBrokerToken: PACT_BROKER_TOKEN,       tags: ['test'],       publishVerificationResult: true,       providerVersion: '1.0.2',       logLevel: 'DEBUG',     };

writetojoshma
2020-12-17 12:52
will this work

writetojoshma
2020-12-17 12:52
this is what i specify in provider.spec.js

writetojoshma
2020-12-17 12:56
any idea from where PACT_BROKER_URL will be mapped here

writetojoshma
2020-12-17 12:56
in that sample gitproject

writetojoshma
2020-12-17 13:02
hey guys

tjones
2020-12-17 13:29
`PACT_BROKER_URL` <-- it depends where this is defined

writetojoshma
2020-12-17 13:43
okay

writetojoshma
2020-12-17 13:43
A pact for this consumer version is already published. Overwriting. (Note: Overwriting pacts is not recommended as it can lead to race conditions. Best practice is to provide a unique consumer version number for each publication.)

writetojoshma
2020-12-17 13:43
where should i change the consumer vesion

writetojoshma
2020-12-17 13:43
how does it work

writetojoshma
2020-12-17 13:43
each type i try with a different interaction , different version ?

writetojoshma
2020-12-17 13:43
*each time

writetojoshma
2020-12-17 13:45
where do i specify the consumer version

writetojoshma
2020-12-17 13:46
{ "name":"pact-contract-testing", "version":"1.2.0", "description":"", "main":"index.js", "scripts":{ "test":"npm run clean && npm run test:consumer && npm run test:publish && npm run test:provider", "start":"nodemon handler-local.ts", "test-consumer":"nyc --reporter=text-summary mocha test/**/consumer.spec.js --timeout 60000", "publish-pact":"cross-env pact-broker publish pacts --consumer-app-version=1.2.0 --broker-base-url=XXXXX --broker-token=XXXXX", "test-provider":"cross-env --broker-base-url=XXXXXX --broker-token=XXXX nyc --reporter=text-summary mocha test/**/provider.spec.js -t 10000 " }

writetojoshma
2020-12-17 13:47
is this the version

vikas543
2020-12-17 16:28
has joined #pact-js

bpugh
2020-12-17 17:05
has joined #pact-js

tjones
2020-12-17 20:26
Have a read of the documentation article about versioning I linked above. Pact needs to know what version of the code you are testing or verifying. It should be different every time the contract might change (so usually people include the git hash). Versioning is specific to your app, though, so I can?t tell you what the answer is. In the example you are using, the version is hard coded. This is likely to lead to mistakes. Also, the consumer code and provider code are in the same project (which isn?t very realistic for most use cases). I recommend following the official examples in the pact-js repository

matt.fellows
2020-12-18 03:54
:taco: :taco: for @tjones, that may just be the longest ever thread

writetojoshma
2020-12-18 06:05
Can anyone gives me the best 3 points why PACT is suitable for testing graphQLs

writetojoshma
2020-12-18 06:09
I am just doing a POC on my local , so i hardcoded everything .

writetojoshma
2020-12-18 06:09
I have to convince my team that PACT suits our scope of testing graphQLs

writetojoshma
2020-12-18 06:10
I am a tester , not a developer who unit tests . I am focused on integrated tests .


matt.fellows
2020-12-18 11:45
GraphQL (e.g. a `website` -> `Graphql API`) basically doesn?t give you any more guarantees than RESTful APIs, so the arguments are essentially the same: 1. If a provider changes its schema, it can still break a consumer 2. If a consumer deploys a new expectation, it may not be compatible with a provider Because GraphQL has deprecations and some version of a schema, means essentially nothing. From the GraphQL API to its downstream services, presumably they aren?t all GraphQL APIs either, so the integration testing there is still likely to benefit from standard RESTful Pact tests.

matt.fellows
2020-12-18 11:45
I?d also consult #graphql for more thoughts from others

matt.fellows
2020-12-18 11:45
Do you have access to the actual code base under test? Pact tests need to be run in the context of the code base (like a unit test).

matt.fellows
2020-12-18 11:46
If you don?t have access or the know how, writing Pact tests effectively might be difficult

matt.fellows
2020-12-18 11:46
(not saying don?t try, but Pact?s core audience at this moment in time are developers and SDET types)

writetojoshma
2020-12-18 12:07
Yes my developer is developing graphqls and he has deployed a version in the server .

writetojoshma
2020-12-18 12:07
So i am a SDET who is going to test the graphQL query using PACT

writetojoshma
2020-12-18 12:07
thats my idea

writetojoshma
2020-12-18 12:08
~So you saying PACT is good for Automated Integration testing of graphQLs~

writetojoshma
2020-12-18 12:09
Okay Great

writetojoshma
2020-12-18 12:09
U said "From the GraphQL API to its downstream services, presumably they aren?t all GraphQL APIs either, so the integration testing there is still likely to benefit from standard RESTful Pact tests."

writetojoshma
2020-12-18 12:11
t' process with PID: 18980 1) validates the contract provided by the consumer 0 passing (32s) 1 failing 1) Pact Verification validates the contract provided by the consumer: Error: Timeout waiting for verification process to complete (PID: 18980) at Timeout._onTimeout (node_modules\q\q.js:1846:21) at listOnTimeout (internal/timers.js:554:17) at processTimers (internal/timers.js:497:7)

writetojoshma
2020-12-18 12:11
Any idea how to fix this

writetojoshma
2020-12-18 12:12
Yes I got ur point , I a definitely testing it against a schema develoepd

writetojoshma
2020-12-18 12:48
1) Verifying a pact between GraphQLConsumer and GraphQLProvider A consumer details request with POST / returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Faraday::ConnectionFailed: No connection could be made because the target machine actively refused it. - connect(2) for "localhost" port 60064 # ------------------ # --- Caused by: --- # Errno::ECONNREFUSED: # No connection could be made because the target machine actively refused it. - connect(2) for "localhost" port 60064 #pact-js

writetojoshma
2020-12-18 12:49
I am stuck here , Pls help !!

abubics
2020-12-19 09:06
Looks like your pact mock server isn't running on localhost:60064 . . .

writetojoshma
2020-12-19 15:31
const provider = new Pact({       port: 5000,       log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),       dir: path.resolve(process.cwd(), "pacts"),       consumer: "GraphQLConsumer",       provider: "GraphQLProvider",     })

writetojoshma
2020-12-19 15:31
this is my configuration in consumer-spec.js

writetojoshma
2020-12-19 15:32
so this indicates my pact mock server (mock provider ) is on port 5000 right

writetojoshma
2020-12-19 15:34
No connection could be made because the target machine actively refused it.

writetojoshma
2020-12-19 15:35
This error indicates the actual provider refused the connection . Is'nt ?

jeff.burmood
2020-12-19 17:45
has joined #pact-js

kyle.florence
2020-12-19 19:21
has joined #pact-js

ankurmalik22
2020-12-19 21:14
has joined #pact-js

ankurmalik22
2020-12-19 23:24
Hi Team, I am facing one issue when I am using Provider verification without broker URL and token my tests are passing, but when I add pact broker URL (http://pactflow.io) and token it gave me below error

ankurmalik22
2020-12-19 23:24
```yarn run v1.22.10 $ jest --testPathPattern=./tests/pact/.* PASS tests/pact/provider.pact.test.ts (6.565s) Consumer ? should validate pact provider (13ms) console.log tests/pact/provider.pact.test.ts:24 { pactUrls: [ '/Users/tests/pact/pacts/consumer-producer.json' ], provider: 'Provider', providerBaseUrl: 'https://xx.appsync-api.eu-west-1.amazonaws.com', pactBrokerUrl: 'https://xx.pactflow.io/', pactBrokerToken: 'xx', publishVerificationResult: true, providerVersion: '1.0.0', verbose: false, providerVersionTags: [ 'local' ] } [2020-12-19T23:06:00.858Z] INFO: pact@9.13.0/4163 : Verifying provider console.log tests/pact/provider.pact.test.ts:29 [2020-12-19T23:06:00.868Z] INFO: pact-node@10.11.0/4163 : Verifying Pacts. [2020-12-19T23:06:00.870Z] INFO: pact-node@10.11.0/4163 : Verifying Pact Files Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 6.612s, estimated 7s Ran all test suites matching /.\/tests\/pact\/.*/i. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. at Object.getCodec (node_modules/iconv-lite/lib/index.js:65:27) at Object.getDecoder (node_modules/iconv-lite/lib/index.js:127:23) at getDecoder (node_modules/raw-body/index.js:45:18) at readStream (node_modules/raw-body/index.js:180:15) at getRawBody (node_modules/raw-body/index.js:108:12) [2020-12-19T23:06:11.287Z] WARN: pact-node@10.11.0/4163 : Pact exited with code 1. (node:4163) UnhandledPromiseRejectionWarning: Error: INFO: Fetching pacts for provider from https://xx.pactflow.io/ with the selection criteria: INFO: Reading pact at https://xx.pactflow.io/pacts/provider/provider/consumer/consumer/pact-version/xx DEBUG: The pact at https://xx.pactflow.io/pacts/provider/provider/consumer/consumer/pact-version/xx is being verified because it matches the following configured selection criterion: latest pact between a consumer and producer Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which matches /application\/json/ (FAILED - 3) Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="d664f52ed1d7ee0b76fd36ce25e8ba429bddb4e3") INFO: Tagging version 1.0.0 of producer as "local" INFO: Verification results published to https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx/verification-results/211 INFO: Reading pact at /Users/tests/pact/pacts/consumer-producer.json Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which matches /application\/json/ (FAILED - 3) Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:53791/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variables PACT_DESCRIPTION="get" PACT_PROVIDER_STATE="") WARN: Cannot publish verification for consumer as there is no link named pb:publish-verification-results in the pact JSON. If you are using a pact broker, please upgrade to version 2.0.0 or later.```

ankurmalik22
2020-12-19 23:26
code used: ```import { Verifier } from "@pact-foundation/pact"; import path from "path"; describe("producer ", () => { it("should validate pact provider", () => { const opts = { pactUrls: [ path.resolve( process.cwd(), "tests/pact/pacts/consumer-producer.json" ), ], provider: "producer", providerBaseUrl: "https://xx.appsync-api.eu-west-1.amazonaws.com", pactBrokerUrl: "https://xx.pactflow.io/", pactBrokerToken: "xx @Matt (http://pactflow.io / pact-js / pact-go) @Matt (http://pactflow.io / pact-js / pact-go) ", publishVerificationResult: false, providerVersion: "1.0.0", verbose: false, providerVersionTags: ["local"], }; new Verifier(opts).verifyProvider().then((output) => { console.log(output); }); }); });``` @matt.fellows

vsukumaran
2020-12-20 01:56
has joined #pact-js

matt.fellows
2020-12-20 02:18
You still have pactUrls set, so it can't publish results

matt.fellows
2020-12-20 02:19
But it also looks like the mock service isn't starting up properly. Are you able to please run with trace logs enabled?

matt.fellows
2020-12-20 02:19
The invalid charset is strange

matt.fellows
2020-12-20 02:19
Also the jest warning is strange

omer.morad
2020-12-20 08:10
has joined #pact-js

ringo
2020-12-20 10:51
has joined #pact-js

ankurmalik22
2020-12-20 11:15
Hi @matt.fellows, thanks for your prompt response, Extra info: ``` "@pact-foundation/pact": "9.13.0" ? ap ? node -v v14.15.1 ? api ? yarn -v 1.22.10 ? api ? npm -v 6.14.8 OS: Mac OS Big Sur Version 11.0.1``` below is the information after trace enabled:

ankurmalik22
2020-12-20 11:15
```yarn run v1.22.10 warning ../../../../../../package.json: No license field $ jest --testPathPattern=./tests/pact/.* PASS tests/pact/consumer.pact.test.ts (8.282s) sports highlight ? should validate pact provider (13ms) [2020-12-20T10:57:44.414Z] INFO: pact@9.13.0/21092 : Verifying provider [2020-12-20T10:57:44.428Z] INFO: pact-node@10.11.0/21092 : Verifying Pacts. [2020-12-20T10:57:44.430Z] INFO: pact-node@10.11.0/21092 : Verifying Pact Files Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 8.342s Ran all test suites matching /.\/tests\/pact\/.*/i. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. at Object.getCodec (node_modules/iconv-lite/lib/index.js:65:27) at Object.getDecoder (node_modules/iconv-lite/lib/index.js:127:23) at getDecoder (node_modules/raw-body/index.js:45:18) at readStream (node_modules/raw-body/index.js:180:15) at getRawBody (node_modules/raw-body/index.js:108:12) [2020-12-20T10:57:51.519Z] WARN: pact-node@10.11.0/21092 : Pact exited with code 1. (node:21092) UnhandledPromiseRejectionWarning: Error: opening connection to http://xx.pactflow.io:443... opened starting SSL for http://xx.pactflow.io:443... SSL established <- "GET / HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: application/hal+json\r\nUser-Agent: Ruby\r\nAuthorization: [redacted]\r\n" -> "HTTP/1.1 200 OK\r\n" -> "Date: Sun, 20 Dec 2020 10:57:48 GMT\r\n" -> "Content-Type: application/hal+json;charset=utf-8\r\n" -> "Content-Length: 4213\r\n" -> "Connection: keep-alive\r\n" -> "Vary: Accept\r\n" -> "Server: Webmachine-Ruby/1.5.0 Rack/1.3\r\n" -> "X-Pact-Broker-Version: 2.72.0\r\n" -> "X-Pact-Broker-Git-Sha: d1e9ba77\r\n" -> "X-Pactflow-Git-Sha: a5404d3b\r\n" -> "X-Content-Type-Options: nosniff\r\n" -> "X-Request-Id: 3a991879b5ae0798abe80983bd9de84f\r\n" -> "\r\n" reading 4213 bytes... -> "{\"_links\":{\"self\":{\"href\":\"https://xx.pactflow.io\",\"title\":\"Index\",\"templated\":false},\"pb:publish-pact\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/consumer/{consumer}/version/{consumerApplicationVersion}\",\"title\":\"Publish a pact\",\"templated\":true},\"pb:latest-pact-versions\":{\"href\":\"https://xx.pactflow.io/pacts/latest\",\"title\":\"Latest pact versions\",\"templated\":false},\"pb:tagged-pact-versions\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/consumer/{consumer}/tag/{tag}\",\"title\":\"All versions of a pact for a given consumer, provider and consumer version tag\",\"templated\":false},\"pb:pacticipants\":{\"href\":\"https://xx.pactflow.io/pacticipants\",\"title\":\"Pacticipants\",\"templated\":false},\"pb:pacticipant\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}\",\"title\":\"Fetch pacticipant by name\",\"templated\":true},\"pb:latest-provider-pacts\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/latest\",\"title\":\"Latest pacts by provider\",\"templated\":true},\"pb:latest-provider-pacts-with-tag\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/latest/{tag}\",\"title\":\"Latest pacts for provider with the specified tag\",\"templated\":true},\"pb:provider-pacts-with-tag\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/tag/{tag}\",\"title\":\"All pact versions for the provider with the specified consumer version tag\",\"templated\":true},\"pb:provider-pacts\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}\",\"title\":\"All pact versions for the specified provider\",\"templated\":true},\"pb:latest-version\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}/latest-version\",\"title\":\"Latest pacticipant version\",\"templated\":true},\"pb:latest-tagged-version\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}/latest-version/{tag}\",\"title\":\"Latest pacticipant version with the specified tag\",\"templated\":true},\"pb:webhooks\":{\"href\":\"https://xx.pactflow.io/webhooks\",\"title\":\"Webhooks\",\"templated\":false},\"pb:webhook\":{\"href\":\"https://xx.pactflow.io/webhooks/{uuid}\",\"title\":\"Webhook\",\"templated\":true},\"pb:integrations\":{\"href\":\"https://xx.pactflow.io/integrations\",\"title\":\"Integrations\",\"templated\":false},\"pb:pacticipant-version-tag\":{\"href\":\"https://xx.pactflow.io/pacticipants/{pacticipant}/versions/{version}/tags/{tag}\",\"title\":\"Get, create or delete a tag for a pacticipant version\",\"templated\":true},\"pb:metrics\":{\"href\":\"https://xx.pactflow.io/metrics\",\"title\":\"Get Pact Broker metrics\"},\"pb:can-i-deploy-pacticipant-version-to-tag\":{\"href\":\"https://xx.pactflow.io/can-i-deploy?pacticipant={pacticipant}\\u0026version={version}\\u0026to={tag}\",\"title\":\"Determine if an application can be safely deployed to an environment identified by the given tag\",\"templated\":true},\"pb:provider-pacts-for-verification\":{\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/for-verification\",\"title\":\"Pact versions to be verified for the specified provider\",\"templated\":true},\"beta:provider-pacts-for-verification\":{\"name\":\"beta\",\"href\":\"https://xx.pactflow.io/pacts/provider/{provider}/for-verification\",\"title\":\"DEPRECATED - please use pb:provider-pacts-for-verification\",\"templated\":true},\"curies\":[{\"name\":\"pb\",\"href\":\"https://xx.pactflow.io/doc/{rel}?context=index\",\"templated\":true},{\"name\":\"beta\",\"href\":\"https://xx.pactflow.io/doc/{rel}?context=index\",\"templated\":true}],\"pb:api-tokens\":{\"href\":\"https://xx.pactflow.io/settings/tokens\",\"title\":\"API tokens\",\"templated\":false},\"pb:audit\":{\"href\":\"https://xx.pactflow.io/audit\",\"title\":\"Audit trail\",\"templated\":false},\"pb:secrets\":{\"href\":\"https://xx.pactflow.io/secrets\",\"title\":\"Secrets\",\"templated\":false},\"pf:admin-users\":{\"href\":\"https://xx.pactflow.io/admin/users\",\"title\":\"Users\",\"templated\":false},\"pf:admin-teams\":{\"href\":\"https://xx.pactflow.io/admin/teams\",\"title\":\"Teams\",\"templated\":false},\"pf:admin-system-accounts\":{\"href\":\"https://xx.pactflow.io/admin/system-accounts\",\"title\":\"System accounts\",\"templated\":false},\"pf:admin-roles\":{\"href\":\"https://xx.pactflow.io/admin/roles\",\"title\":\"Roles\",\"templated\":false},\"pf:admin-permissions\":{\"href\":\"https://xx.pactflow.io/admin/permissions\",\"title\":\"Permissions\",\"templated\":false}}}" read 4213 bytes Conn keep-alive INFO: Fetching pacts for producer from https://xx.pactflow.io/ with the selection criteria: opening connection to http://xx.pactflow.io:443... opened starting SSL for http://xx.pactflow.io:443... SSL established <- "POST /pacts/provider/producer/for-verification HTTP/1.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: application/hal+json\r\nUser-Agent: Ruby\r\nContent-Type: application/json\r\nAuthorization: [redacted]\r\n" <- "{\"providerVersionTags\":[\"local\"]}" -> "HTTP/1.1 200 OK\r\n" -> "Date: Sun, 20 Dec 2020 10:57:49 GMT\r\n" -> "Content-Type: application/hal+json;charset=utf-8\r\n" -> "Content-Length: 801\r\n" -> "Connection: keep-alive\r\n" -> "Vary: Accept\r\n" -> "Server: Webmachine-Ruby/1.5.0 Rack/1.3\r\n" -> "X-Pact-Broker-Version: 2.72.0\r\n" -> "X-Pact-Broker-Git-Sha: d1e9ba77\r\n" -> "X-Pactflow-Git-Sha: a5404d3b\r\n" -> "X-Content-Type-Options: nosniff\r\n" -> "X-Request-Id: 20441768fbf7621bb3cf486281d4f065\r\n" -> "\r\n" reading 801 bytes... -> "{\"_embedded\":{\"pacts\":[{\"shortDescription\":\"latest\",\"verificationProperties\":{\"notices\":[{\"when\":\"before_verification\",\"text\":\"The pact at https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx is being verified because it matches the following configured selection criterion: latest pact between a consumer and producer\"}]},\"_links\":{\"self\":{\"href\":\"https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx\",\"name\":\"Pact between consumer (1.0.0) and producer\"}}}]},\"_links\":{\"self\":{\"href\":\"https://xx.pactflow.io/pacts/provider/producer/for-verification\",\"title\":\"Pacts to be verified\"}}}" read 801 bytes Conn keep-alive INFO: Reading pact at https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx DEBUG: The pact at https://xx.pactflow.io/pacts/provider/producer/consumer/consumer/pact-version/xx is being verified because it matches the following configured selection criterion: latest pact between a consumer and producer Verifying a pact between consumer and producer Get with POST /graphql returns a response which DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.365317 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.365368 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.400008 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.400057 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has status code 200 (FAILED - 1) DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.400852 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.400913 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.403150 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.403190 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has a matching body (FAILED - 2) includes headers DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.404004 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.404036 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.405986 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.406029 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" "Content-Type" which matches /application\/json/ (FAILED - 3)```

ankurmalik22
2020-12-20 11:15
```Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="xx") INFO: Reading pact at /Users/api/tests/pact/pacts/consumer-producer.json Verifying a pact between consumer and producer Get with POST /graphql returns a response which DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.459476 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.459508 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.461414 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.461453 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has status code 200 (FAILED - 1) DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.462056 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.462085 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.463638 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.463673 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" has a matching body (FAILED - 2) includes headers DEBUG: Setting up provider state '' for consumer 'consumer' using provider state set up URL http://localhost:50165/_pactSetup I, [2020-12-20T10:57:51.464277 #21125] INFO -- request: POST http://localhost:50165/_pactSetup D, [2020-12-20T10:57:51.464305 #21125] DEBUG -- request: User-Agent: "Faraday v0.17.3" Content-Type: "application/json" I, [2020-12-20T10:57:51.465802 #21125] INFO -- response: Status 415 D, [2020-12-20T10:57:51.465838 #21125] DEBUG -- response: x-powered-by: "Express" content-security-policy: "default-src 'none'" x-content-type-options: "nosniff" content-type: "text/html; charset=utf-8" content-length: "529" date: "Sun, 20 Dec 2020 10:57:51 GMT" connection: "close" "Content-Type" which matches /application\/json/ (FAILED - 3) Failures: 1) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 2) Verifying a pact between consumer and producer Get with POST /graphql returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 3) Verifying a pact between consumer and producer Get with POST /graphql returns a response which includes headers "Content-Type" which matches /application\/json/ Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state '' for consumer 'consumer' at http://localhost:50165/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /Users/api/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/Users/api/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:75:11)</pre> </body> </html> 1 interaction, 1 failure Failed interactions: * Get (to re-run just this interaction, set environment variables PACT_DESCRIPTION="Get" PACT_PROVIDER_STATE="") (Use `node --trace-warnings ...` to show where the warning was created) (node:21092) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:21092) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.```

ankurmalik22
2020-12-20 11:16
Have to paste as 2 messages because of content length restrictions

omer.moradd
2020-12-20 18:01
has joined #pact-js

omer.moradd
2020-12-20 18:08
Hi all :) I am new to Pact.js and after some reading, I found it awesome! exactly the thing we were looking for in the company. We work with NestJS a lot, and I thought that creating an NPM Package that brings those two great technologies together will be nice I would love to hear what you guys think of it! NPM: https://www.npmjs.com/package/nestjs-pact Github: http://www.github.com/omermorad/nestjs-pact

matt.fellows
2020-12-20 23:29
Very cool - haven?t used NestJS before but heard good things

matt.fellows
2020-12-20 23:45
Thanks @ankurmalik22 . Unfortunately I still can? t see from that why you would be getting that exception. A short google doesn?t get me much further, so I?m going to need a full bug report https://github.com/pact-foundation/pact-js/issues/new please.

matt.fellows
2020-12-20 23:45
I?m going to need a minimal example that I can download and run to reproduce it

matt.fellows
2020-12-20 23:46
The only thing that jumps out at me is that you?re on Big Sur, which I know is pretty new

matt.fellows
2020-12-20 23:46
so there may be some new changes that impact the networking system etc.

omer.moradd
2020-12-21 07:03
Thanks buddy! Yes it?s a great framework

artur
2020-12-21 09:08
is the XmlBuilder of pact-js v3 already supposed to work with pact-web?

uglyog
2020-12-21 09:38
It should, in theory. Nobody has tested it yet.

matt.fellows
2020-12-21 09:41
Should it? I don't think so as it can't run in a non-node environment

uglyog
2020-12-21 09:44
Ah, I was thinking of Cypress.

matt.fellows
2020-12-21 09:48
:wink:

artur
2020-12-21 10:10
the current project is tested with karma and I have to do a lot and complicated XML requests, really don't want to put them all into regex :scream:

artur
2020-12-21 10:10
maybe I have to get rid of karma in the first place

matt.fellows
2020-12-21 11:05
Could you keep your Karma tests and use Pact in a separate test framework (like jest/mocha etc)?

artur
2020-12-21 11:25
90% of the tests are now pact based tests, worked fine for the client side, but now I'm running into issues making the provider side work. the returned XMLs are not as static as expected in the tests.

souravsen1
2020-12-21 11:28
has joined #pact-js

artur
2020-12-21 11:28
so I'm currently looking into changing over to jest

ankurmalik22
2020-12-21 14:13
Hi @matt.fellows apologise for late response, I have got it verified on the Catalina but issue is same. Attached is the project for your reference, I have changed the actual http://pactflow.io URL and key

andoni.arroyo
2020-12-21 17:51
has joined #pact-js

andoni.arroyo
2020-12-21 17:52
Hi guys

andoni.arroyo
2020-12-21 17:52
I was trying to get a basic example to demonstrate pact to my company

andoni.arroyo
2020-12-21 17:53
super basic with jest

andoni.arroyo
2020-12-21 17:53
but when I try to run the pact I get this error

andoni.arroyo
2020-12-21 17:54
`Pact Binary Error: <the_path>/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.3/pact/lib/ruby/bin/ruby: line 14: contract: command not found`

andoni.arroyo
2020-12-21 17:54
any clue what could be the problem?

matt.fellows
2020-12-22 00:26
check spaces in your paths, I think there was a recent issue raised around this

andoni.arroyo
2020-12-22 00:30
nice point I'll check it, thanks!

ankurmalik22
2020-12-22 10:11
Hi @matt.fellows Thanks for your support I have created the ticket with these details please have a look, I am sure its something I have just missed https://github.com/pact-foundation/pact-js/issues/544

theovanessen
2020-12-22 10:47
has joined #pact-js

stuart3166
2020-12-22 12:35
has joined #pact-js

winfante
2020-12-22 22:51
has joined #pact-js

matt.fellows
2020-12-23 03:09
You?re welcome. In any case, pretty confident at the moment it?s an issue with something you?re doing. Here?s an example to show you how to make your test pass: https://github.com/mefellows/pact-js-issue-544

matt.fellows
2020-12-23 03:09
my gift to you:christmas_tree:

artur
2020-12-23 05:55
in pact-js beta using PactV3 can I start the mock server before `provider.executeTest` ? The background for that is, that in my current project I have a request in `beforeAll()` . with the current stable version of pact-js I can call `setup()` in `beforeAll()` and already use all added interactions, with V3 the only option I see is to move that request from `beforeAll()` into every test. Are there other options?

lars.bonnes
2020-12-23 13:05
has joined #pact-js

ankurmalik22
2020-12-24 12:05
Hi @matt.fellows thanks for all your help it has certainly helped. The issues later turned out to be something different, just to add some more context to it: When we just use the provider test to start a server locally and test against local endpoint the jest tests remains alive until the server remains up, But in our case, we are using AWS Appsync as a provider and hence nothing running locally so as soon as the tests are done tests doesn't finish more than 5000ms but in order to upload the verification results and complete all the validations pact needs around 20000ms (in our case), hence increasing the timeout has fixed the issue for me

eungjun.yi
2020-12-25 14:25
has joined #pact-js

matt.fellows
2020-12-26 02:11
Hmm at this stage no

matt.fellows
2020-12-26 02:12
But is it because you want to preload all interactions in advance? That you can do

ebanster
2020-12-27 13:18
has joined #pact-js

artur
2020-12-28 03:24
I basically need to have the interactions in place before the `beforeAll` call is fired. But the issue is not to big, I can shift stuff from `beforeAll` to the tests How can I preload the interactions in advance?

onur.baskirt
2020-12-28 10:48
has joined #pact-js

writetojoshma
2020-12-28 14:34
Still getting long path issue , even after updating registry in windows

writetojoshma
2020-12-28 14:35
Pls help

tjones
2020-12-28 22:51
Can you tell us more about the use case for needing to do this?

tjones
2020-12-29 03:49
Try moving the project so that it is in a place with a shorter path

writetojoshma
2020-12-29 04:23
I couldn't help moving to any other place....I reduced the folder name length .

writetojoshma
2020-12-29 04:23
Worked

writetojoshma
2020-12-29 06:54
The pact broker username and broker password in can I deploy is different from pact broker and token in publish.js

writetojoshma
2020-12-29 06:54
?

matt.fellows
2020-12-29 06:57
You have different auth modes depending on your broker. It's always a token, if using Pactflow.

matt.fellows
2020-12-29 06:57
If not using Pactflow, it's probably username/password

writetojoshma
2020-12-29 06:57
I am using pactflow

matt.fellows
2020-12-29 06:58
So use the token then

writetojoshma
2020-12-29 06:58
So username and password is basically the pactbroker url and the broker token of pactflow only right

matt.fellows
2020-12-29 06:58
No, you don't use that option for Pactflow

matt.fellows
2020-12-29 06:59
Use the property for a token (I think pactBrokerToken). Look at the docs for exact name

writetojoshma
2020-12-29 07:05
"can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://test.pact.dius.com.au --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1", "api": "concurrently 'npm run provider' 'npm run consumer'", "consumer": "node ./consumerService.js", "provider": "node ./providerService.js" }, "author": "", "license": "MIT", "devDependencies": { "@greet_bot/pact": "^9.11.1", "body-parser": "^1.18.3", "chai": "^3.5.0", "chai-as-promised": "^6.0.0", "cli-color": "^1.1.0", "concurrently": "^3.1.0", "cors": "^2.8.1", "eslint": "^3.13.1", "eslint-config-google": "^0.7.1", "express": "^4.16.3", "express-http-proxy": "^1.4.0", "mocha": "^5.2.0", "superagent": "^3.8.3" }}

abubics
2020-12-29 07:07
It looks like you just posted a secret in a public channel :eyes:

artur
2020-12-29 07:07
with `VerifierV3` can I verify a provider that uses self-signed SSL? `validateSSL: false` seems not to have any effect

writetojoshma
2020-12-29 07:09
this i copied from a public site

writetojoshma
2020-12-29 07:10
"can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --broker-base-url https://test.pact.dius.com.au --broker-username dXfltyFMgNOFZAxr8io9wJ37iUpY42M --broker-password O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"

writetojoshma
2020-12-29 07:11
here i am asking if the broker base url , broker password is same as the broker url and token of pactflow

matt.fellows
2020-12-29 07:12
Hmm. I don't think so yet. That option being there seems strange. I did some work for Pact Go a while back and the underlying Rust lib didn't allow this. Would you please kindly raise a request? I'll be picking up some OSS work over the hols and a few of these should be easy pickings

matt.fellows
2020-12-29 07:12
That is talking to a broker that uses basic auth, hence why it uses those parameters

matt.fellows
2020-12-29 07:13
You're using Pactflow

artur
2020-12-29 07:13
the option is not there, I just found it in pactv2 and tried it. I will raise an request

writetojoshma
2020-12-29 07:13
Yes I am using pactflow

writetojoshma
2020-12-29 07:14
So can I use the same auth which I use for publish pact

matt.fellows
2020-12-29 07:14
Yes

writetojoshma
2020-12-29 07:14
Alright

matt.fellows
2020-12-29 07:15
Run the pact-broker binary and use the help command to see what options are available

matt.fellows
2020-12-29 07:15
I think it's `broker-token`

writetojoshma
2020-12-29 07:17
"can-i-deploy:provider": "pact-broker can-i-deploy --pacticipant 'Animal Profile Service' --latest --pactBrokerUrl https://xxxx.pactflow.io --pactBrokerToken O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"

writetojoshma
2020-12-29 07:17
will it work this way for pactflow

writetojoshma
2020-12-29 07:18
--broker-base-url

writetojoshma
2020-12-29 07:18
--broker-token

writetojoshma
2020-12-29 07:18
sorry its the above


matt.fellows
2020-12-29 08:02
Thanks! :pray:

writetojoshma
2020-12-29 12:01
```home/jenkins/agent/workspace/xxx-graphql-coxxxxr/Testing@tmp/durable-a65568b/script.sh: pact-broker: not found```

writetojoshma
2020-12-29 12:02
i got this error in jenkins

writetojoshma
2020-12-29 12:03
while running pact-broker can-i-deploy --pacticipant 'graphql-service' --latest --broker-base-url https://xxxx.pactflow.io --broker-token MBjDLxxxxxxxxxxzg

massimo.daros
2020-12-29 13:18
has joined #pact-js

chris.fullinwider
2020-12-29 18:15
has joined #pact-js

matt.fellows
2020-12-29 21:14
Is that binary on the path?

matt.fellows
2020-12-29 21:15
I'd actually prefix the command with `npx` if using a later version of node and it should scan node modules dorbit

writetojoshma
2020-12-30 02:27
"can-i-deploy:provider": "npx pact-broker can-i-deploy --pacticipant 'consumerservice' --latest --broker-base-url https://jjohn.pactflow.io  --broker-token jhgyugguOLvvnm-fGQzg"

writetojoshma
2020-12-30 02:27
do you mean this

matt.fellows
2020-12-30 02:57
Yep

matt.fellows
2020-12-30 02:57
npx should search node modules binaries and run them if node is installed correctly

writetojoshma
2020-12-30 03:45
okay thanks will try it

piotr.soltysiak
2020-12-30 16:55
has joined #pact-js

tausif2909
2020-12-31 04:44
has joined #pact-js

writetojoshma
2021-01-01 14:38
Happy new year all:heart:

adrian.przybyla
2021-01-04 13:41
has joined #pact-js

adrian.przybyla
2021-01-04 13:41
Hey guys

adrian.przybyla
2021-01-04 13:41
do you have any gist/example/whatever with case where you testing mutation in graphql ?

chris.fullinwider
2021-01-04 17:45
:wave: -- Hi there, happy new year! first time posting (and I?m a total Pact noob). Please let me know if this post is inappropriate for this channel. ? we?ve just implemented pact into our CI/CD pipelines ? we are using the base pact broker with no webhook for provider verification upon contract updates (this appears to be best practice, and we are thinking about how to implement this layer) ? I had a question regarding webhook management. it seems right now, that I have to create webhooks within the broker itself as well as my normal repository manager (gitlab) ? is there any documentation / best practices around how to manage these webhook integrations? (to clarify, I?m not asking how to create webhooks and implement them. I?m looking ahead to when we have 20 consumer repositories, seems like a challenge to manage the webhooks for all those repos)

dcorrales
2021-01-04 22:06
has joined #pact-js

jokubas.lekevicius
2021-01-04 22:10
has joined #pact-js

tjones
2021-01-05 01:18
Welcome! This is probably a #pact-broker question- you'd be better off posting there. I think the best webhook documentation we have so far is here: https://docs.pact.io/pact_broker/webhooks/

writetojoshma
2021-01-05 09:09
Hey , I have set up the pact in .js files . I got a suggestion to move those to typescript files instead . Do you think it is needed. What are the pros and cons

writetojoshma
2021-01-05 09:09
If yes can you please send me an example using typescript

tjones
2021-01-05 09:11
This isn't really a pact question, it's more a node general question. Typescript gives you some confidence that you haven't made type errors (but not completely typesafe, so some think it makes developers overconfident). If you want to read about it, there are a lot of medium articles you can find with a few searches. I would recommend reading a few and making your own choices.

tjones
2021-01-05 09:11
We provide typescript types for all exported pact interfaces.


writetojoshma
2021-01-05 09:12
Okay otherwise the PACT testing is all good with js right

tjones
2021-01-05 09:12
yes, either is fine.

tjones
2021-01-05 09:13
we let you choose.

writetojoshma
2021-01-05 09:13
Alright

writetojoshma
2021-01-05 09:13
I found typescript examples difficult than javascript way

writetojoshma
2021-01-05 09:13
So I thought why not I continue with javascript

writetojoshma
2021-01-05 09:13
Thanks for sharing

tjones
2021-01-05 09:14
Yes, this is personal preference.

writetojoshma
2021-01-05 09:14
Alright

matt195
2021-01-05 16:35
has joined #pact-js

matt195
2021-01-05 16:36
Hi folks. We're using pact with mocha, and I'm finding something wierd going on that it seems to stop running the examples when one of them fails. This means we end up playing whack-a-mole with regressions, because you fix one problem and then there's another one hiding behind it. Should I expect this behaviour, or does it suggest I've gone something set up wrong?

matt195
2021-01-05 16:40
it's as though we're running mocha with `--bail` but we're not

rafael.manzoni
2021-01-05 17:56
has joined #pact-js

animesh2712
2021-01-05 19:29
has joined #pact-js

animesh2712
2021-01-05 19:41
Hello Folks, I was trying to write Pact for sample consumer in a React apps. I?m using jest for writing the Pact test. But I keeping get ?on interaction found? error. I found it maybe happening because of the slow initiation of Jasmine mock server which is used by jest. Also, tried using jest-pact, however didn?t worked. Any sample example with jest and React? The example present https://github.com/pact-foundation/pact-js/tree/master/examples/jest doesn?t work for me. Any help is appreciated!

joel.whalen
2021-01-05 20:07
If I have this matcher, is it required to put the `string`, `boolean`, etc types on every single attribute? Or does the `eachLike` or `like` functions apply this automatically? ```const searchResultFixture = { area: string('GB_AREA'), availableNavigation: eachLike({ displayName: string('Category Level 2'), metadata: eachLike([ string('GB_FACET_METADATA'), ]), name: string('categoryl2'), or: boolean(false), range: boolean(false), refinements: eachLike( { count: integer(74), type: string('Value'), value: string('Cordless Tools'), }, ), type: string('Value'), }), }``` Like could I wrap up the `searchResultFixture` inside of a `like` function and that?ll do it or no? I?m aware that I need to put `eachLike` for all the nested arrays because verification is failing if I don?t. Thanks!

joel.whalen
2021-01-05 20:09
Slow initiation of the jasmine mock server usually results in a different `undefined` error, so it?s probably not that. If it can?t find your interaction, that means your application code is never making the request. Double check the code running within the unit test is actually making a request, and to the correct server and port number of the mock server.

joel.whalen
2021-01-05 20:10
this isn?t going to help you, but I haven?t seen this problem with jest yet :shrug:

matt.fellows
2021-01-05 21:30
It doesn't sound right

matt.fellows
2021-01-05 21:30
Are your able to share your code and mock server logs?

matt.fellows
2021-01-05 21:30
That might help

matt.fellows
2021-01-05 21:31
Or an issue with a repro we can use to diagnose

matt.fellows
2021-01-05 21:41
What Joel said


matt.fellows
2021-01-05 21:43
From the ci/cd workshop in howtolearn

2021-01-05 21:43
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-01-05 21:44
Like matchers should cascade, so no, you shouldn't need to double handle

joel.whalen
2021-01-05 22:02
My question is more about `like` vs `eachLike`; as in, when there are nested arrays within the JSON object, do I need to specify the `eachLike` underneath the `like`? I?m assuming yes.

antonello
2021-01-05 22:20
In my experience, you do need to do that. Unless it?s changed recently.

adrian.przybyla
2021-01-05 22:21
Hello i have problem with matching graphQL mutation this is my mutation ```export function mutation(): any { return client .mutate({ mutation: GQLTag(setDealQuery), variables: { deal: { } } }).then((result: any) => result.data); }``` this is my spec ```test('Deal', async (t: any) => { t.plan(1); await provider.addInteraction({ state: undefined, uponReceiving: 'a hello request', withRequest: { method: 'POST', headers: {'content-type': 'application/json'}, path: '/1746213/v1/', body: { query: setDealQuery, operationName: 'setDeal', variables: { deal: { } } } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: { data: like(data) } } }); const response = await mutation(); t.deepEqual(response.data, data.data); });``` this is my log file

matt.fellows
2021-01-05 22:40
Good question, I can't recall off the top of my head Joel.

matt.fellows
2021-01-05 22:42
It looks like the space is the issue

matt.fellows
2021-01-05 22:42
It's expecting space after the mutation setDeal keyword but didn't get one


adrian.przybyla
2021-01-05 22:53
@matt.fellows look at link

matt.fellows
2021-01-05 22:58
glad to hear you got it working

matt.fellows
2021-01-05 22:59
matching at the moment for JSON documents doesn?t care about spaces in this way, but for GraphQL because it?s not a first class citizen in the current framework, it?s treated as a string. So we have to match that way. I?m sure we can find a way to fix it in your requested issue

matt.fellows
2021-01-05 22:59
thanks for taking the time to report

animesh2712
2021-01-05 23:00
Thanks @matt.fellows@matt.fellows@matt.fellows@Matt (http://pactflow.io / pact-js / pact-go)@Matt (http://pactflow.io / pact-js / pact-go), does it has any known issue with windows env? I was able to run on the Macbook, but it doesn?t work on windows laptop.

matt.fellows
2021-01-05 23:07
Pact works on windows, but that example hasn't been tested on windows.

info
2021-01-06 01:55
has joined #pact-js

matt195
2021-01-06 09:58
Yeah the repo is closed source, but I?m pretty sure I can share the code.

matt195
2021-01-06 10:28
Thanks @matt.fellows! Here?s a gist: https://gist.github.com/mattwynne/0143193385ebaf1b58d24aad4a70d159 You can see that, even though there are three examples in the spec, it only seems to have run the first one. If I mark out the first two examples (the ones that use pact) as pending (with `xit`) it runs all three as expected, showing 2 pending, 1 failed.

matt195
2021-01-06 10:30
It feels like we?re using the combinations of `setup` , `addInteractionv` , `verify` and `finalize` in the wrong places, but it looks pretty similar to the documented examples to us.

pascal.libenzi
2021-01-06 10:57
has joined #pact-js

writetojoshma
2021-01-06 11:24
Hey , any details about pact testing in weighted alias environments

writetojoshma
2021-01-06 11:27
AWS lambda aliases

writetojoshma
2021-01-06 11:36
Can I put providerVersion in provider.spec.ts as the alias version number

animesh2712
2021-01-06 16:27
Okay, could you please help with an example that is tested on Windows?

brett
2021-01-06 18:55
has joined #pact-js

josh.rosenfeld
2021-01-06 19:39
has joined #pact-js

thanuxxxx
2021-01-06 21:35
Hey guys, do we have a way to inject values from provider state callbacks? I know in Java world we can do something like this `.pathFromProviderState("/api/users/${id}", "/api/users/100")`, and do we have a equivalent method in pact-js?

matt.fellows
2021-01-06 21:43
Our v3 beta release does allow this. It's almost out of beta

matt195
2021-01-06 22:42
I realise there?s quite a lot there to read, but any thoughts from skimming it would be appreciated @matt.fellows? :pray:

brett
2021-01-06 22:58
Moved to pact-broker channel which seemed more appropriate for this question. ~Hey guys, I've got my PACT json file generated in my Angular project (karma + jasmine) and I can't seem to publish it to Pactflow as shown in the tutorial.~ ~I get this error when I run npm run publish:~ ~"Error making request - NoMethodError undefined method `[]' for nil:NilClass..."~ ~Do I need to set up a separate/custom publish.js file? Here is what is in my package.json:~ ```"publish": "npx pact-broker publish pacts --consumer-app-version=1 --broker-base-url=[redacted] --broker-token=[redacted] --tag master"``` ~I've been searching for over an hour and can't seem to make progress. Any help is much appreciated, as I imagine I'm missing something quite simple. Thanks!~

tjones
2021-01-07 01:56
@matt195 Your example looks right to me. Note that mocha bails on the first error by default, but Jest does not. Could it be that?

writetojoshma
2021-01-07 05:58
Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error downloading binary from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.3/pact-1.88.3-win32.ziphttps://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.3/pact-1.88.3-win32.zip: Error: Error while installing binary: Error: unable to get local issuer certificateError: Error while

writetojoshma
2021-01-07 05:58
Getting this error everytime i install pact

writetojoshma
2021-01-07 05:58
please help

tjones
2021-01-07 06:10
It sounds like you have a self-signed SSL certificate - You may need to configure npm to use your cafile, as per the instructions at the end of this note: https://github.com/pact-foundation/pact-node#pact-download-location If that fails, you can add `@pact-foundation/pact-node` as a direct dev dependency, and follow the local download instructions

patrick.b.romo
2021-01-07 06:57
has joined #pact-js

writetojoshma
2021-01-07 10:28
Oky

writetojoshma
2021-01-07 10:28
,"@pact-foundation/pact": "^9.13.2",

writetojoshma
2021-01-07 10:29
I had used this instead of pact-node

writetojoshma
2021-01-07 10:30
will it make difference

matt.fellows
2021-01-07 10:40
Pact node is a transitive dependency of pact

matt.fellows
2021-01-07 10:41
Follow the instructions there to download it in advance

carlo
2021-01-07 13:24
has joined #pact-js

writetojoshma
2021-01-07 13:36
i am able to run from jenkins and from local also , but my teammates are not able to install pact..getting the erro..but i wonder they were able to install one day back..today they are getting error

andrewshtamburg
2021-01-07 16:03
@andrewshtamburg has left the channel

danny.porrello
2021-01-07 16:48
has joined #pact-js

animesh2712
2021-01-07 17:02
Hello, Any tested example of pact js for consumer on windows?

matt.fellows
2021-01-07 22:17
All of the examples in pact JS repo also run on a windows build agent. What's the issue you're having?

matt.fellows
2021-01-07 22:18
Why does the OS matter?

animesh2712
2021-01-08 03:07
I was getting ?no interaction found?, no matter what I did. However, it was a weird issue that was resolved today. After I deleted my workspace and started fresh.

matt.fellows
2021-01-08 03:29
So yeah, it really sounds like an issue on your side. Inconsistent behaviour generally indicates environment specific problems. If you can reliably reproduce the problem within and outside of your corporate environment, then please raise an issue and we can look into it

dawood.abbas
2021-01-08 07:00
has joined #pact-js

writetojoshma
2021-01-08 13:07
Is it possible to check if a node in the graphql response is either null or a non empty data of expected type using any of pact matcher

brendan.donegan
2021-01-08 13:28
No, because how do you know if it?s supposed to be null or if it?s a bug?

brendan.donegan
2021-01-08 13:28
Provider states should be used to set up the provider so that it returns the expected data

matt195
2021-01-08 14:08
Thanks for taking a look Tim. I?m puzzled. I use mocha lot and I?m sure it?s showing me multiple failing examples from other tests in the same project. It?s as though the error thrown by `verify` is causing it to bail. Or maybe it?s some behaviour of mocha when it?s an `afterEach` hook failing rather than in the example itself?

tjones
2021-01-08 15:15
Hm. I?m not sure, although I confess I haven?t used mocha in a while. Does this happen in a non-pact test that fails in the same way?

matt.fellows
2021-01-08 22:51
The FAQ on our docs talks to this point also

matt.fellows
2021-01-08 22:53
Could be the `after` blocks. You don't have to run `verify` in that way if you don't want. E.g. you could ensure every `it` has the call to `verify`


tjones
2021-01-09 03:49
Big thanks to @artur for kicking off the work to move to github actions from Travis (who stopped running builds for OSS). Artur got the builds working, and I've now finished the migration of the release process with the pact-foundation npm tokens. The above is the first automated release from github actions!

tjones
2021-01-09 03:49
tacos for @artur :taco: :taco: !

artur
2021-01-09 07:33
:bow: it was a fun task - thanks for the great tool

matt.fellows
2021-01-09 22:13
Awesome work folks, really appreciate this!

matt.fellows
2021-01-09 22:13
Artur you've been a community star of late :taco: :taco: :taco:

matt.fellows
2021-01-09 22:13
And time as always :taco: for you too!

matt.fellows
2021-01-10 05:03
On a side note @artur, we?ve added the ability to disable SSL verification in the v3 branch but need to get a release out. I?ll try and do that in the next few days - it may require migrating that branch to GH actions too (probably via merging into master so as to not diverge too far)

uglyog
2021-01-10 05:04
merging *from* master

tjones
2021-01-10 05:19
@matt.fellows We can clone the new release workflow. The major difference will be checking out the V3 branch, and marking releases as pre-release.

cksharma122
2021-01-10 17:19
has joined #pact-js

uglyog
2021-01-11 01:46
@tjones I'm merging master into V3 branch. How do I trigger the release? using the `scripts/trigger-release.sh` script?

tjones
2021-01-11 01:47
That will trigger a master release. We need to do a small amount of work to trigger a beta release- I plan to document the release process today, but I?ll do the script work now if you like

uglyog
2021-01-11 01:47
awesome

artur
2021-01-11 03:31
cool, that will help me with the next steps.

caiquedpfc
2021-01-11 04:05
has joined #pact-js

artur
2021-01-11 10:09
@matt.fellows can you point me to the commit? I cannot find it?


henrik.rudstrom
2021-01-11 18:30
has joined #pact-js

eric
2021-01-12 10:23
has joined #pact-js

chris.fullinwider
2021-01-13 00:13
sorry for late response, thank you!

fnguyen
2021-01-13 00:39
has joined #pact-js

caiquedpfc
2021-01-13 04:04
Hello guys. I'm trying to run `jest __tests__/contract/consumer --runInBand` but jest cannot find any tests to run: `Pattern: __tests__/contract/consumer - 0 matches` even though the ClientsConsumer.spec.js file exists in the `__tests__ directory/contract/consumer/` can someone help me?

uglyog
2021-01-13 04:15
This is not really a Pact issue, but I've used `jest consumer/*.test.js` so you might need to add the extension

writetojoshma
2021-01-13 10:20
Hey , will can-I-deploy sends a machine code like 0 or 1 , so that jenkins will go to next step based on 0 or 1 . In that case , a web hook is not needed right

matt.fellows
2021-01-13 10:21
yes, all of our CLI tools properly exit with `0` when they are successful, or > `0` if they fail (usually exit code `1`)

matt.fellows
2021-01-13 10:22
Not sure what you?re asking about a webhook though. Do you mean, if it fails, trigger a provider build?

brendan.donegan
2021-01-13 11:09
Hi - if we define a part of the response as an exact array of items (because #reasons) and the provider returns those items but in a different order, will Pact care?

writetojoshma
2021-01-13 11:21
I was asking if I am using can I deploy in my pipeline , and I have the next command to deploy in the same pipeline....there is no need of an explicit web hook from broker

writetojoshma
2021-01-13 11:22
As the can i deploy will take care of it

matt.fellows
2021-01-13 12:50
That's what I do :wink:

matt.fellows
2021-01-13 12:51
Good question. I hope not :crossed_fingers:, but have a suspicion it does (I recall a question regarding lat/lng and meanings of positional floats :grimacing:

writetojoshma
2021-01-13 12:58
:joy:

caiquedpfc
2021-01-13 14:07
Thanks @uglyog

brendan.donegan
2021-01-13 15:39
it seems like it does, btw

pollet_22
2021-01-13 16:04
has joined #pact-js

dshattuck
2021-01-13 20:49
has joined #pact-js

thomas.rosati
2021-01-13 21:58
has joined #pact-js

artur
2021-01-14 07:15
I have a PactV3 provider with a json response ``` .willRespondWith({ status: 200, body: { ocs: { meta: { statuscode: 100 } } } })```

artur
2021-01-14 07:17
when running that interaction against a provider that responds JSON but sets the wrong content-type in the header I get the error message: ```1) Verifying a pact between owncloud-sdk and oc-server - a capabilities GET request with valid authentication returns a response which 1.1) has a matching body expected 'application/json' body but was 'text/plain;charset=utf-8'``` what is kind of true. But actually the body is correct, only the header is wrong. Is that a bug in pact of a feature?

tjones
2021-01-14 07:21
I can see the argument for this error message, but I think you're right that it's better described as a header mismatch. Would you be able to open an issue, please?

uglyog
2021-01-14 07:21
This is by design. If the content type is `text/plain`, it can be any text. Do you require an override mechanism to set the content type to JSON?

uglyog
2021-01-14 07:23
If the content type header was specified in the Pact, then there would be a header mismatch as well

artur
2021-01-14 07:23
no, no. its a bug in the provider I'm testing. The provider really has to send the correct content-type. I was just confused by the error message and was thinking if that is intended, because in that particular example I actually don't check the content type only the body

artur
2021-01-14 07:24
yes, that how I started to dig in. I had both specified and then two error messages came up

artur
2021-01-14 07:24
but I knew that the body content is correct and simplified my interaction

artur
2021-01-14 07:25
with both specified in the interaction I get ```1) Verifying a pact between owncloud-sdk and oc-server - a capabilities GET request with valid authentication returns a response which 1.1) has a matching body expected 'application/json;charset=utf-8' body but was 'text/plain;charset=utf-8' 1.2) includes header 'Content-Type' with value 'application/json; charset=utf-8' Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'text/plain; charset=utf-8'```

rahulsmalpani
2021-01-14 07:56
has joined #pact-js


sacha.camfferman768
2021-01-14 09:42
has joined #pact-js

brandonbeard86
2021-01-14 22:10
has joined #pact-js

geetishnayak
2021-01-15 01:02
has joined #pact-js

stanleyawang
2021-01-15 06:29
has joined #pact-js

stanleyawang
2021-01-15 06:35
hi all, does anybody get intermittent connection refused errors 'connect ECONNREFUSED 127.0.0.1:35183' while using node.js pact on docker? this are the logs when it fails and then succeeds

tjones
2021-01-15 06:36
That shouldn't happen. My guess would be that the promises that need to be waited on aren't being waited on

tjones
2021-01-15 06:37
can you share your consumer test code that is producing the error? Just the structure is fine, the details of the requests can be removed

tjones
2021-01-15 06:38
I would guess that things are slightly slower to spin up in docker, which would be why you're seeing this in docker.

stanleyawang
2021-01-15 06:39
```const provider = new Pact({ consumer: pacticipantName, provider: microservice.providerName, port: 35183, // port: 1234, // You can set the port explicitly here or dynamically (see setup() below) log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'DEBUG', spec: 2, }); await provider.setup().then((opts) => `http://localhost:${opts.port}`); const apiUrl = 'http://127.0.0.1:35183'; await new Promise((r) => setTimeout(r, 2000)); await provider.addInteraction({ state, uponReceiving, withRequest: { method: 'POST', path: urlPath, body: requestBody, headers: { 'Content-Type': 'application/json; charset=utf-8', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: responseBody, }, }); await request .post(`${apiUrl}${urlPath}`) .send(requestBody) .set('Content-Type', 'application/json; charset=utf-8'); await provider.verify(); await provider.finalize();``` it goes something like this i added a delay as well ...

stanleyawang
2021-01-15 06:44
u may be right ... let me increase the delay to 10 secs to see if i get a higher success rate ..

matt.fellows
2021-01-15 06:45
what is `apiUrl`?

matt.fellows
2021-01-15 06:45
It looks like your code is hitting it, but that?s _not_ the mock server

matt.fellows
2021-01-15 06:45
I think you want something like this: ```const apiUrl = await provider.setup().then((opts) => `http://localhost:${opts.port}`);```

tjones
2021-01-15 06:45
Hm. The promises look right at first glance. A couple of things: 1) You've got ```await provider.setup().then((opts) => `http://localhost:${opts.port}`)``` for getting the API URL, but then have it hard coded to `const apiUrl = 'http://127.0.0.1:35183';`, which seems like it might cause errors later (although you're configuring the port to be the same). 2) The `http://request.post` block isn't the usual pattern- usually you would call the actual client code that your consumer is going to call

matt.fellows
2021-01-15 06:45
exactly

tjones
2021-01-15 06:46
Delay shouldn't be necessary. Just to check, you're doing all of this inside an `async` function, yes?

stanleyawang
2021-01-15 06:46
yup am doing this inside async function

tjones
2021-01-15 06:47
I wonder if there's some optimisation where it determines that some of the `async`s don't depend on each other

matt.fellows
2021-01-15 06:47
can you please also share the mock server logs? That may be enlightening too

stanleyawang
2021-01-15 06:48
yup for 1) , your code was what i had before but I was still encountering the same issue.... i added apiUrl as a separate line because I was trying to figure out what was the issue ...

stanleyawang
2021-01-15 06:52
ok let me try to get the mock server logs

matt.fellows
2021-01-15 06:54
So it very much has the smell of promise handling. Some tactical use of `console.log` might be handy in just seeing if indeed things are in the correct order

tjones
2021-01-15 07:03
What test framework are you using?

stanleyawang
2021-01-15 07:04
my mock server logs are as follows my mock server logs are as follows

stanleyawang
2021-01-15 07:04
```I, [2021-01-15T06:59:39.072654 #106] INFO -- : Registered expected interaction POST /endpoint-b D, [2021-01-15T06:59:39.073040 #106] DEBUG -- : { "description": "request b", "providerState": "state b", "request": { "method": "POST", "path": "/endpoint-b", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "metadata": null } I, [2021-01-15T06:59:39.076048 #106] INFO -- : Registered expected interaction POST /endpoint-a D, [2021-01-15T06:59:39.079093 #106] DEBUG -- : { "description": "request a", "providerState": "state a", "request": { "method": "POST", "path": "/endpoint-a", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "metadata": null } I, [2021-01-15T06:59:39.082004 #106] INFO -- : Registered expected interaction POST /endpoint-c D, [2021-01-15T06:59:39.082236 #106] DEBUG -- : { "description": "request c", "providerState": "state c", "request": { "method": "POST", "path": "/endpoint-c", "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } } }, "metadata": null } I, [2021-01-15T06:59:39.118883 #106] INFO -- : Received request POST /endpoint-b D, [2021-01-15T06:59:39.119069 #106] DEBUG -- : { "path": "/endpoint-b", "query": "", "method": "post", "body": { }, "headers": { "Content-Length": "76", "Content-Type": "application/json; charset=utf-8", "Host": "127.0.0.1:35183", "Accept-Encoding": "gzip, deflate", "Connection": "close", "Version": "HTTP/1.1" } } I, [2021-01-15T06:59:39.119523 #106] INFO -- : Found matching response for POST /endpoint-b D, [2021-01-15T06:59:39.119625 #106] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { } }```

stanleyawang
2021-01-15 07:04
im using jest

tjones
2021-01-15 07:06
do you have multiple test files? There are three endpoints registered in that log, but only one in your test file

tjones
2021-01-15 07:07
If some dependent promise optimisation is causing this, then you could try moving the promises out to `beforeEach` `afterEach` etc - see the jest examples for a guide

tjones
2021-01-15 07:07
also, if you do have multiple test files, you'll need to run jest with `--runInBand`

stanleyawang
2021-01-15 07:11
ah thanks for the tip ... it is indeed due to a missing await Promise.all() ... as I am running a loop through each request ....

tjones
2021-01-15 07:12
If you're running tests concurrently, you'll want to be careful to make sure that each mock server runs on a different port and writes to a different pact file. Usually, tests are run sequentially to avoid the need for this.

stanleyawang
2021-01-15 07:12
in my code ... the 'addInteraction' and then 'http://request.post' is in a loop ... based on an array of requests object ...

stanleyawang
2021-01-15 07:13
so that solves my problem.. thanks!

tjones
2021-01-15 07:13
The reason tests need to be sequential is because sometimes there's a race condition when updating the pact file.

stanleyawang
2021-01-15 07:14
ah noted ... yup i always use the runInBands option for jest for simplicity sake

tjones
2021-01-15 07:14
Ok. If you're doing that, make sure that the loop contents are: ```await addInteraction await sendRequest await provider.verify()```

stanleyawang
2021-01-15 07:15
yup that is what im doing ... my error was not adding a await Promise.all for the loop ... which resulted in the test ending before it could finish the loop

tjones
2021-01-15 07:15
You may also be interested in https://github.com/pact-foundation/jest-pact , which sets up the promises for you

stanleyawang
2021-01-15 07:17
oh ok ... didn't see this before ... will have a look thanks!

writetojoshma
2021-01-15 12:53
Hey , I need a token which needs to be passed as Authorization header in my request. So I will be generating it every time I do the test and it expires in a short time of 15 mins. So will pact works for that

shettyg
2021-01-15 14:18
has joined #pact-js

writetojoshma
2021-01-15 15:01
Is requestFilters the solution

natarajang1
2021-01-15 15:29
has joined #pact-js

matt.fellows
2021-01-15 22:38
The JS workshop has a whole step dedicated to this. But that's one of them, yes


uglyog
2021-01-18 07:05
Because `addRequest` is expecting JSON

artur
2021-01-18 07:06
I'm just testing it, it seems to be happy with an JSON object or string

artur
2021-01-18 07:06
my issue is that when I send it a string it gets added extra quotes see https://github.com/pact-foundation/pact-js/issues/577

uglyog
2021-01-18 07:08
It's probably better to just pass the raw Javascript object through, and then deal with it on the other side.

artur
2021-01-18 07:09
that what I thought, or only stringlify if its not a string?

artur
2021-01-18 07:09
```- this.pact.addRequest(req, req.body && JSON.stringify(req.body)) + if (typeof req.body !== 'string') { + req.body = req.body && JSON.stringify(req.body) + } + this.pact.addRequest(req, req.body)```

uglyog
2021-01-18 07:10
That will fix your issue


artur
2021-01-18 07:35
I fail to build v3 any idea? ```$ npm run build:v3 > @pact-foundation/pact@10.0.0-beta.25 build:v3 /home/artur/www/pact/pact-js > neon build --release neon ERR! spawn cargo ENOENT Error: spawn cargo ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:268:19) at onErrorNT (internal/child_process.js:470:16) at processTicksAndRejections (internal/process/task_queues.js:84:21) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @pact-foundation/pact@10.0.0-beta.25 build:v3: `neon build --release` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @pact-foundation/pact@10.0.0-beta.25 build:v3 script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/artur/.npm/_logs/2021-01-18T07_34_57_395Z-debug.log```

matt.fellows
2021-01-18 07:36
I think you have to have rust + cargo installed to run that step

matt.fellows
2021-01-18 07:36
I was actually going to catch up with Tim Jones (another maintainer) this morning, and one of the activities ironically was to create some developer documentation - apologies it?s not there just yet

artur
2021-01-18 07:39
something happening now. Also v3 e2e tests are not running in CI as far as I can tell

matt.fellows
2021-01-18 07:52
:scream:

pollet_22
2021-01-18 07:58
hello team , please note that i am new in pact .... Now i have my endpoint for login which i need to make a Contract testing on it how to setup my consumer and provider ?? Another question is there any pact matchers that matches on only keys not value ??

artur
2021-01-18 08:03
would it be possible to create regex for that?

pollet_22
2021-01-18 08:04
hello @artur did you talk about my problem ?? i am already have this endpoint response using supertest

artur
2021-01-18 08:05
I talked about having a matcher that only matches keys

pollet_22
2021-01-18 08:06
did u mean create regex for value and matches that regex ... do i understand u correctly ?

artur
2021-01-18 08:07
no, I regex matcher that contains both key and value, with `.*` for the values

artur
2021-01-18 08:08
are you dealing with JSON?

pollet_22
2021-01-18 08:08
not much

pollet_22
2021-01-18 08:09
How can i search about that thing to know more about it ?

artur
2021-01-18 08:09
can you give me an example of your interaction?

pollet_22
2021-01-18 08:12
this is the request : https://testing3-api.asgard.io/dashboard/sign_in/ and there is a body which contains email and password Response: {_id: '5ffec1a68', owner: '5fd9c936039', type: 'dashboard', token: '7c13e256-463e-4887', refresh_token: '56b58158-8e34', expiry_date: '2021-01-14T09:4', createdAt: '2021-01-13 updatedAt: '2021-01-13 __v: 0, is_expired: false, id: '5f29950f58', jwt: 'VsGItox_pCFnfBIPikLQiBlp, role: 'admin'}

artur
2021-01-18 08:13
and you want to have a matcher for the response?

pollet_22
2021-01-18 08:14
yes to check that only keys is returned which is id , owner , .....

artur
2021-01-18 08:18
what about using just string? ```const { like, string } = Matchers ..... willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { _id: string("5ffec1a68"), owner: string("5fd9c936039"), },```

artur
2021-01-18 08:18
that should match regardless of what the id or owner is

pollet_22
2021-01-18 08:51
thank @artur i will give it a try

pollet_22
2021-01-18 08:53
Can any one help me with the first part of question how to setup my endpoint

michel.neufeglise
2021-01-18 08:55
has joined #pact-js

michel.neufeglise
2021-01-18 09:25
Hi everybody :slightly_smiling_face: I am new to http://Pact.IO and currently working on a implementation of pact in an angular 7 project with Jest unit test framework but having a problem getting the requests handled by the pact stub server without using TestBed for injecting my service into the unit tests, has anybody an example of how I could do this without using TestBed ?

bart.boersma
2021-01-18 10:48
has joined #pact-js

matt.fellows
2021-01-18 11:57
:taco: for @artur who?s been such a great contributor over the last few weeks. We can?t keep up!

artur
2021-01-18 12:15
I'm working totally selfish, I need V3 working because I have to deal with dynamic XML bodies. I tried by using regex but that is :poop:. So better get V3 working and use the XmlBuilder

artur
2021-01-18 12:17
please tell me if it worked, I'm also just implementing http://pact.io in a project https://github.com/owncloud/owncloud-sdk we got the consumer side working, now refactoring it and trying to solve issues on the provider side

artur
2021-01-18 12:17
ok, that is not true, V3 tests do run in CI

artur
2021-01-18 12:23
BTW: how does pact-js v3 send data to the mock server to set up the interactions? with the old version I could see POST requests in the packet sniffer, not anymore with v3

michel.neufeglise
2021-01-18 12:26
Never mind, Matt pointed me to a solution which works, embedding the service in the setup() method of the provider :-)

pollet_22
2021-01-18 13:14
I am trying to do so but as i mention in my post that i can't implement the contact testing of my endpoint how can i do so through pact cause i have some understanding points

pollet_22
2021-01-18 13:14
i will take a look at your project it can helps me in my situation

artur
2021-01-18 13:15
be aware that we are moving to pactV3, that has some differences

pollet_22
2021-01-18 13:16
honestly i am totally new so i don't know what is differ from actual version :slightly_smiling_face:

artur
2021-01-18 13:17
when I started the best source for me were the examples in github


uglyog
2021-01-18 22:13
It passes the Pact from the DSL to the native lib, which creates a mock server from that. There is no HTTP communication, it is all done through code.

matt.fellows
2021-01-19 02:22
It?s one of the reasons why it?s heaps faster than before

monica.wu
2021-01-19 06:25
has joined #pact-js

artur
2021-01-19 06:59
@uglyog I'm trying to run the tests in https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/e2e/test/consumer.spec.js but the provider side tests fail with ```Failures: 0) Verifying a pact between Matching Service V3 and Animal Profile Service V3 Given is authenticated And Has some animals - a request to get animals as XML returns a response which has a matching body $.animals.0 -> Expected 'lion' to be the same type as 'goat'```


artur
2021-01-19 07:13
now it passes, maybe I had an old beta in that folder and that's why it did not work, sorry for the noise

makobernal
2021-01-19 08:23
has joined #pact-js

artur
2021-01-19 08:48
I have trouble to make provider states in V3 using async code first I tried in my app. then modified one test example https://github.com/individual-it/pact-js/blob/asyncProviderStates/examples/v3/e2e/test/provider.spec.js#L77-L80 but the result is the same, the code is fired but it does not wait for the Promise to resolve

jibrail.idris
2021-01-19 10:11
has joined #pact-js

artur
2021-01-19 10:13
I managed to get it working with https://github.com/larsgw/sync-fetch but is that by design? are only sync operation allowed in the states?

jmvb.registros
2021-01-19 11:01
has joined #pact-js

brendan.donegan
2021-01-19 12:49
It looks like you?d have to await the result of fetch and mark the corresponding state handler as async

artur
2021-01-19 14:18
tried it, same result

uglyog
2021-01-19 22:06
Provider states don't support async functions yet. I'm waiting for a PR in Neon to be able to handle the promise.

tpham
2021-01-19 22:36
has joined #pact-js

vishal.grover
2021-01-20 03:12
has joined #pact-js

artur
2021-01-20 03:25
anything I could help with that?

uglyog
2021-01-20 03:34
Not much we can do at the moment. Need one of these to be implemented: https://github.com/neon-bindings/rfcs/pull/35 and https://github.com/neon-bindings/rfcs/pull/32

uglyog
2021-01-20 03:38
Looks like the Threadsafe handle pre-release was merged and released with 0.7.0 of Neon. That should be good to try to use to deal with JS promises.

artur
2021-01-20 03:55
I will try it

priya.saraf
2021-01-20 08:43
has joined #pact-js

fahad.aj.khan
2021-01-20 08:58
has joined #pact-js

artur
2021-01-20 09:00
looks too me that its a bit of work to implement that, I will have to go with sync requests for now :disappointed:

tjones
2021-01-20 09:06
Can we promisify it on our side with a callback?

tjones
2021-01-20 09:07
Also, this conversation would be well suited for #pact-js-development

nicole.jaenchen
2021-01-20 09:38
has joined #pact-js

dinakaran.ulaganathan
2021-01-20 13:59
has joined #pact-js

ptsiakos77
2021-01-20 21:55
has joined #pact-js

mhdtouban
2021-01-21 01:58
has joined #pact-js

veeraprathap.n
2021-01-21 04:10
has joined #pact-js

writetojoshma
2021-01-21 08:47
Hey can I know how to export the test results from pactflow to jenkins

matt.fellows
2021-01-21 09:19
What test results - consumer or provider? Pact usually is run within a test framework (e.g. jest) so you would usually report those results

tsiakos
2021-01-21 09:24
has joined #pact-js

writetojoshma
2021-01-21 12:50
Oh

writetojoshma
2021-01-21 12:51
I am using mocha

writetojoshma
2021-01-21 12:51
Okay so mocha test results will be good ?

writetojoshma
2021-01-21 12:51
But is there any way I can export the pactflow report

writetojoshma
2021-01-21 12:51
Provider test results

oleg
2021-01-21 13:05
has joined #pact-js

matt.fellows
2021-01-21 23:51
We don?t currently have a way of doing that I don?t think. There is support for it in the underlying Ruby process, but i?m not sure how that would work with the way we currently use it

matt.fellows
2021-01-21 23:52
@bethskurrie with the `--format` option for the verifier, how difficult would it be to enable multiple outputs. i.e. for Pact JS, we still want the stdout to print the custom Pact output, but if we could also generate a RspecJunitReport then this would also be possible

writetojoshma
2021-01-22 07:16
Okay

writetojoshma
2021-01-22 07:17
Hey I need to pass body of the POST request in my provider.interaction

writetojoshma
2021-01-22 07:17
Can u show any sample

writetojoshma
2021-01-22 07:17
How to do that

writetojoshma
2021-01-22 07:17
Pact is

writetojoshma
2021-01-22 07:17
Js

thomas.powell
2021-01-22 10:18
has joined #pact-js

brendan.j.donegan
2021-01-22 16:56
You just use the body: field

stefan.selent
2021-01-23 01:54
has joined #pact-js

paulo
2021-01-25 11:37
has joined #pact-js

kmckeever
2021-01-25 14:38
has joined #pact-js

brendan.donegan
2021-01-25 14:42
How do we deal with requests that include a file in them?

kmckeever
2021-01-25 14:44
Hey there! I have been putting together a POC of PactJS for my team, and have stumbled onto some issues that we have not been able to rectify. I wanted to throw this question out to ensure I am understanding correctly and setting up my tests properly. Background: Angular application with GraphQL backend, validation using Jest. Am I to have the host/port used to set up my Pact provider be the same one used for my Service? For instance, I have my Pact provider hit port 8181, I add the pact interaction for the GraphQLInteraction in my beforeEach block, then have my actual service hitting port 8181 in the test as well to share the mock service set up by Pact. Is that correct? Or can I have the service in my test hit the actual, running service on, say, port 3000?

kmckeever
2021-01-25 14:53
Hey there Michel - would you mind sharing the solution that Matt provided you? I am running into a similar issue with my current project.

kmckeever
2021-01-25 16:59
I think I answered the above question. What I'm running into is my Angular TestBed does not appear to be using the mocked response, so when I am executing my test I am getting a null response, and so the provider.verify() function fails. My team and I are not able to get past this issue.

robert.land
2021-01-25 19:25
has joined #pact-js

aparnachaudhari
2021-01-25 21:34
has joined #pact-js

matt.fellows
2021-01-25 22:08
You neod to configure your API client to talk to the pact mock service, not the real one


matt.fellows
2021-01-25 22:09
Pact V3 has a native binary matcher (JS and JVM)


kmckeever
2021-01-25 22:10
Hey there @matt.fellows, thanks for following up! I was able to configure it properly so the tests run and my PACT docs are created. However...I am noticing that when I perform my test (with the API client configured to talk to the pact mock service port), I get a null back when I hit the service. If I switch the port to the real one, I get the proper response.

kmckeever
2021-01-25 22:10
As far as I can tell my configuration looks correct. Everything is working as it should, but it just seems like my API method just won't go through the Pact Mock service.

matt.fellows
2021-01-25 22:15
Can you please share the pact code?

matt.fellows
2021-01-25 22:15
My guess is perhaps a missing `content-type` header

kmckeever
2021-01-25 22:17
Absolutely >>

kmckeever
2021-01-25 22:17
`provider.addInteraction(`         `await new Pact.GraphQLInteraction()`           `.uponReceiving("verifyDevice()")`           `.withRequest({`             `path: "/graphql",`             `method: "POST",`             `headers: { 'Content-Type': contentTypeJsonMatcher },`           `})`           `.withQuery(productSearch)`           `.withVariables({`             `id: 12345`           `})`           `.willRespondWith({`             `status: 200,`             `body: {`               `data: {`                 `nodes: [`                   `{`                     `id: Matchers.string,`                     `productType: Matchers.string,`                     `sku: Matchers.string`                   `},`                 `],`               `},`             `},`           `})`       `);`     `});`

kmckeever
2021-01-25 22:17
`const contentTypeJsonMatcher = Pact.Matchers.term({`   `matcher: "application\\/json; *charset=utf-8",`   `generate: "application/json; charset=utf-8",` `});`

kmckeever
2021-01-25 23:08
@matt.fellows I changed the content-type to just 'application/json', but the behavior remains. I've been digging into this for hours, but still not entirely sure why my TestBed is not returning the response from the pact mock service.

gwhill7
2021-01-25 23:23
has joined #pact-js

kmckeever
2021-01-26 00:09
I have also abstracted the Pact methods init(), verify(), finalize() and addInteraction() into a new class. I'm happy to share that code as well, if everything above looks like it makes sense.

tjones
2021-01-26 01:56
How are you injecting the URL into your client test code?

brendan.donegan
2021-01-26 11:01
I should have been clearer - in this case I?m referring to a file *upload* in the request sent. I saw that Pact v3 does have some support for this but we are still not switched over yet

matt.fellows
2021-01-26 12:11
I think header matching might be your best bet then

amaljayaraj07
2021-01-26 13:08
Hello people. I am trying out a PACT POC with TypeScript and Jest for my team. Can anybody please point to any sample repo?s describing how we can use Jest mocks to setup provider states? I basically want to mock out database calls and other dependencies to setup my provider states and is looking for some help on how that can be done with Jest

bibinc99
2021-01-26 14:37
has joined #pact-js

kmckeever
2021-01-26 14:42
Hi @tjones - I am injecting it via the Angular TestBed, as shown below: `TestBed.configureTestingModule({`     `imports: [HttpClientModule],`     `providers: [`       `TestService,`       `{`         `provide: DOCUMENT,`         `useFactory: () => PactMock,`       `},`     `],`   `});`

kmckeever
2021-01-26 14:43
The PactMock variable holds URL specified with the same port as the Pact mock server: `export const PactMock = {`   `location: {`     `origin: "http://localhost:8181"`   `}` `}`

joel.whalen
2021-01-26 17:46
Is `jest-pact` officially supported? Or are we supposed to use `pact-js` alone?

joel.whalen
2021-01-26 20:04
Additional question: I?m getting this warning, how important is it? Tests are all passing in Jest now. ```Pact Binary Error: WARN: No content type found, performing text diff on body```

brendan.donegan
2021-01-26 20:08
I think that means that your client code hasn?t set the content-type header to application/json

brendan.donegan
2021-01-26 20:09
it?s mostly harmless but i guess will make diffs a little less obvious if something fails?

joel.whalen
2021-01-26 20:11
ah in the actual code, the content-type header is missing. Instead it?s ```"Accept": "application/json, text/plain, */*",```

abubics
2021-01-26 23:24
I'm pretty sure everything under `pact-foundation` is officially supported :thinking_face: and `jest-pact` does live there (https://github.com/pact-foundation/jest-pact) Afaik `jest-pact` is a DSL wrapper for `pact-js`, not sure if that helps anything.

matt.fellows
2021-01-27 00:01
I would try simplifying things

matt.fellows
2021-01-27 00:02
Start by removing your actual code altogether, and see if you can get the Pact test to pass (i.e. get it to return a JSON body to you and print it out to the console or something)

matt.fellows
2021-01-27 00:02
Just use any HTTP client that you can get your hands on for that test

matt.fellows
2021-01-27 00:02
then, gradually introduce more of your code base into the test until you find the problem

matt.fellows
2021-01-27 00:03
what is confusing you specifically about doing that?

tjones
2021-01-27 00:03
Yes, this is probably not what you want to be sending.

tjones
2021-01-27 00:04
The warning is there to say "hey, you didn't tell us what the content type was supposed to be, so we're guessing"

tjones
2021-01-27 00:05
it's safe to ignore, but if you want stronger tests, put the expected content type in the contract

tjones
2021-01-27 00:05
Yes, it's supported. You can use whatever you find most convenient. Jest-pact removes some of the boilerplate for jest.

kmckeever
2021-01-27 00:19
I will definitely try that. I am getting the contract back for my service (and it is correct) if I complete the test with a simple `expect(true).toBeTruth();` . It does seem bizarre that Pact does seem to be hitting the service and returning the contract. My question is...while that is not ideal, if the test is hitting my service and the contract is created, is that sufficient?

kmckeever
2021-01-27 00:20
I guess, would that catch issues around contract mismatch should one arise in the future, or do we really need to do a comparison match in our test against the service response and the pact response?

tjones
2021-01-27 00:21
Is this a consumer test or a provider test? If a consumer test, your code should *not* be hitting your service, it should be your client code speaking to the pact mock. If a provider test, pact will send requests to your actual service

tjones
2021-01-27 00:22
This sounds to me like an angular problem, but it's hard to help without seeing your code. It sounds like the test code is either not exercising the actual client, or the actual client is not speaking to pact.

tjones
2021-01-27 00:23
Also, ```provider.addInteraction(         await ...``` should be ```await provider.addInteraction(        new Graph....```

tjones
2021-01-27 00:26
If you can share your code with us, we can help more. In general, you don't need to tell TestBed about pact at all. However, you do need a way to tell your client code what URL to use, and you can get the URL from Pact.

matt.fellows
2021-01-27 00:28
This looks like a consumer test to me, but perhaps Kerry is sharing the consumer test to show us what should be happening (given it?s an angular test, I?m hoping it?s a consumer!!()

kmckeever
2021-01-27 00:29
(Sorry, one moment - just pulling up my code for you guys!)

tjones
2021-01-27 00:29
Oh, I thought angular did the API side for you as well, ala next-js. Forgive me, I am not an angular person.

matt.fellows
2021-01-27 00:29
> My question is...while that is not ideal, if the test is hitting my service and the contract is created, is that sufficient? That statement doesn?t make sense to me at all. Pact (in a consumer test) doesn?t make outbound requests, it just receives requests from your code. If it?s generating a contract, that means it?s successfully receiving a request from your code. Which then tells me, it?s a problem in the unit test itself

matt.fellows
2021-01-27 00:30
You might be right Tim. All of those injectables looks like Java in JS to me :laughing:

kmckeever
2021-01-27 00:31
But yes, this is a consumer test. I am only hitting the service call in my test to verify the response returned from the pact mock server (i.e. `let response = await service.verifyDevice("359464081234564");` `expect(response).toEqual(verifyDeviceResponse);` )

kmckeever
2021-01-27 00:33
Sorry, "hitting my service" is a misnomer. By that I mean getting the request from my code.

matt.fellows
2021-01-27 00:36
so basically, `response` is not coming back with anything useful?

matt.fellows
2021-01-27 00:36
There should be a log file somewhere that Pact has created. You can look at that to confirm whether or not the mock server that Pact creates is indeed being hit

kmckeever
2021-01-27 00:37
`describe("BaseEndpointService Pact", () => {` `let service: deviceService;` `const provider = new PactWrapper("provider");` `beforeAll(async () => {` `await provider.init();` `});` `afterEach(async () => {` `await provider.verify();` `});` `afterAll(async () => {` `await provider.finalize();` `});` `beforeEach(() => {` `TestBed.configureTestingModule({` `imports: [HttpClientModule],` `providers: [` `deviceService,` `{` `provide: DOCUMENT,` `useFactory: () => mockDocumentPact,` `},` `],` `});` `});` `describe("verifyDevice()", () => {` `const verifyDeviceResponse = [` `{` `id: "12345",` `deviceType: "PHONE",` `},` `];` `beforeEach(async () => {` `provider.addInteraction(` `await new Pact.GraphQLInteraction()` `.uponReceiving("verifyDevice()")` `.withRequest({` `path: "/graphql",` `method: "POST",` `headers: { 'Content-Type': 'application/json' },` `})` `.withQuery(searchProductsQuery)` `.withVariables({` `productQuery: {` `types: [ProductType.PHONE],` `},` `})` `.willRespondWith({` `status: 200,` `body: {` `data: {` `nodes: [` `{` `id: Matchers.string,` `deviceType: Matchers.string,` `},` `],` `},` `},` `})` `);` `});` `it("verifyDevice() call", async () => {` `service = TestBed.inject(deviceService);` `const response = await service.verifyDevice("359464081234564");` `expect(response).toEqual(verifyDeviceResponse);` `});` `});` `});`

kmckeever
2021-01-27 00:38
(Sorry, slack is printing the code out so horribly!) This is my test. The PactWrapper class is just abstracting the setup and teardown of pact and setting the provider information in the constructor: `constructor(providerName: string) {`         `this.provider = new Pact({`             `port: 8181,`             `log: path.resolve(process.cwd(), 'pact', 'logs', 'pact.log'),`             `dir: path.resolve(process.cwd(), 'pacts'),`             `spec: 3,`             `pactfileWriteMode: 'overwrite',`             `logLevel: 'info',`             `consumer: 'verifyDeviceConsumer',`             `provider: providerName,`         `});`     `}`

matt.fellows
2021-01-27 00:39
To format code, you need to use triple backticks (or choose the code formatting block in the formatting menu)

matt.fellows
2021-01-27 00:39
FYI `spec: 3` is wrong, just omit that for now

matt.fellows
2021-01-27 00:39
it will default to `2`

tjones
2021-01-27 00:40
Sorry, I meant could you share the repository? My guess is the problem is not in Pact, but we might be able to diagnose it for you

matt.fellows
2021-01-27 00:41
that code looked OK to me, with the major caveat that I can?t be sure that the testbed configuration does what it should (namely, configuring your device service to point at pact instead of the real thing)

kmckeever
2021-01-27 00:41
That's correct @matt.fellows. If I have my test configured to call the code using my live service, the response is what I expect. However, when I have it configured to the pact mock server, the response is null/undefined, but the Pact file is created successfully and there are no errors in the Pact log. It's just the test supplied above that is failing, and I wasn't clear on whether that even mattered as far as the Pact is concerned. If not, I can work around that.

tjones
2021-01-27 00:41
If this is Jest, you might get some milage out of `jest-pact` which does the boilerplate of Pact for you. Without the whole definition of the `PactWrapper` class it's hard to say, but wouldn't you need to call `provider.provider.verify()` ?

matt.fellows
2021-01-27 00:42
The log file will confirm this though, which should be in `./pact/logs/pact.log`. Can you please delete it, re-run your stests are share?

matt.fellows
2021-01-27 00:42
Tim, if I?m not mistaken, the verify is there in the `afterEach` block

kmckeever
2021-01-27 00:42
```[2021-01-26T19:39:58.103397 #21936] INFO -- : Registered expected interaction POST /graphql [2021-01-26T19:39:58.107364 #21936] INFO -- : Found matching response for POST /graphql [2021-01-26T19:39:58.135365 #21936] INFO -- : Verifying - interactions matched [2021-01-26T19:39:58.146365 #21936] INFO -- : Cleared interactions [2021-01-26T19:39:58.158364 #21936] INFO -- : Writing pact for verifyDeviceProvider to xxx```

luisc.barretog
2021-01-27 00:42
has joined #pact-js

matt.fellows
2021-01-27 00:42
is that abbreviated?

tjones
2021-01-27 00:43
You will definitely need to `await` `provider.addInteraction` and not the `new Pact.GraphQL` call

kmckeever
2021-01-27 00:43
re: Testbed configuring the device service to point at pact. That's a solid point, and one I have been trying to dig into.

tjones
2021-01-27 00:43
Change: ```beforeEach(async () => { provider.addInteraction( await new Pact.GraphQLInteraction()``` to ```beforeEach(async () => { await provider.addInteraction( new Pact.GraphQLInteraction()```

kmckeever
2021-01-27 00:43
Yes, but I can send the unabridged version with all the gory details. I just need to ensure I am not sharing sensitive information.

kmckeever
2021-01-27 00:44
Good deal. Let me give that a whirl. In case I haven't already mentioned it, I solidly appreciate both of your help here.

kmckeever
2021-01-27 00:44
And completely omit `spec: 3` , or change it to `spec: 2`?

tjones
2021-01-27 00:45
I think it's either a problem with how the client service is being configured (so, in the client code and not in pact), or a problem with the custom PactWrapper.

matt.fellows
2021-01-27 00:45
just remove it. The default is `2` anyway

tjones
2021-01-27 00:49
> I solidly appreciate both of your help here. You're welcome. It's good to have a back and forth with an angular developer, because we get this question a lot, and neither of us are really up with the angular idioms. I'd like to have an angular example in the documentation, but if I write it it won't be idomatically angular, so might not be as helpful.

kmckeever
2021-01-27 00:50
Here's a (slightly edited for sensitive information) pact.log, as requested!

tjones
2021-01-27 00:51
That looks like it works. You said there were nulls - where are you getting nulls?

kmckeever
2021-01-27 00:51
For what it's worth, I gained assistance from this blog (which has the outlined PactWrapper I used in my solution): https://medium.com/@dany.marques/how-to-set-up-pact-tests-with-angular-jest-ae157f272428

kmckeever
2021-01-27 00:53
I am not getting nulls in my Pact, but from my test when pointed to the pact server: ```expect(response).toEqual(verifyDeviceResponse);``` The above's (response) is null where I expect it to be the actual response. The head scratcher is that, as you noted, the Pact looks like it's working, but the actual test fails.

kmckeever
2021-01-27 00:54
So it's looking like it's pointing more toward an issue with Angular than anything else. I can bypass this by having my test just do something silly like ```expect(true).toBeTruthy();``` just to get the test to pass and the Pact to be created, but I was not clear if this would have any negative implications for my Pacts should changes arise in the future.

tjones
2021-01-27 00:55
ah, I definitely wouldn't use that `PactWrapper`. It's swallowing any failures, so you can't be sure if the tests are working,

tjones
2021-01-27 00:55
Just a moment, I'll show you how to use `pactWith` instead

kmckeever
2021-01-27 00:55
Awesome! I appreciate that.

matt.fellows
2021-01-27 00:57
wait

matt.fellows
2021-01-27 00:57
the response body is completely empty i.e. all of the values are zero value types - is this expected?

matt.fellows
2021-01-27 00:58
aha!

matt.fellows
2021-01-27 00:58
```id: Matchers.string,```

matt.fellows
2021-01-27 00:58
that doesn?t do what you think it does

matt.fellows
2021-01-27 00:58
it should be ```id: Matchers.string("example of an id"),```

matt.fellows
2021-01-27 00:58
and ```deviceType: Matchers.string("device id"),```

matt.fellows
2021-01-27 00:58
you?re passing a function, not the value

kmckeever
2021-01-27 00:59
That makes _so_ much more sense.

matt.fellows
2021-01-27 00:59
that could be one reason that your actual service is returning null.

kmckeever
2021-01-27 00:59
Let me make that switch here, too.

matt.fellows
2021-01-27 00:59
that should be easy for us to catch - reject if we get a function there :thinking_face:

tjones
2021-01-27 01:00
```import { pactWith } from 'jest-pact'; pactWith( { port: 8181, logLevel: 'info', consumer: 'verifyDeviceConsumer', provider: 'provideer', }, provider => { let service: deviceService; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientModule], providers: [ deviceService, { provide: DOCUMENT, useFactory: () => mockDocumentPact, }, ], }); }); describe('verifyDevice()', () => { const verifyDeviceResponse = [ { id: '12345', deviceType: 'PHONE', }, ]; beforeEach(async () => { await provider.addInteraction( new Pact.GraphQLInteraction() .uponReceiving('verifyDevice()') .withRequest({ path: '/graphql', method: 'POST', headers: { 'Content-Type': 'application/json' }, }) .withQuery(searchProductsQuery) .withVariables({ productQuery: { types: [ProductType.PHONE], }, }) .willRespondWith({ status: 200, body: { data: { nodes: [ { id: Matchers.string('someId'), deviceType: Matchers.string('some device'), }, ], }, }, }), ); }); it('verifyDevice() call', async () => { service = TestBed.inject(deviceService); const response = await service.verifyDevice('359464081234564'); expect(response).toEqual(verifyDeviceResponse); }); }); }, );```

tjones
2021-01-27 01:00
Note that now you don't need the boilerplate for verify etc

matt.fellows
2021-01-27 01:00
brb folks

tjones
2021-01-27 01:01
That example blog has several issues. It sets the pactFileWriteMode to `overwrite`, which means that if you have more than one spec file you won't get the full contract.

kmckeever
2021-01-27 01:02
Awesome, let me make these changes and give it another run here.

tjones
2021-01-27 01:03
I'm going to write to the author and see if he'd like to contribute to the official examples. It's most of the way there, and would be really helpful to illustrate how to run pact tests with TestBed

kmckeever
2021-01-27 01:09
Updates made, and the code is much cleaner. I wish I'd known about pactWith earlier. Unfortunately, the outcome was still the same as far as the test assertion. I do still have the generated Pact, however, and the log looks a little better, too.

tjones
2021-01-27 01:11
which assertion is null?

kmckeever
2021-01-27 01:11
```it("verifyDevice() call", async () => { service = TestBed.inject(deviceService); const response = await service.verifyDevice("359464081234564"); expect(response).toEqual(verifyDeviceResponse); });``` This guy here

tjones
2021-01-27 01:12
oh right, so the problem there is probably because of the `id: Matchers.string('someId')` bit - did you change those generators to match the content in the `verifyDocumentResponse`?

kmckeever
2021-01-27 01:13
I did, I updated it to be id: `Matchers.string('PHONE:iPhone')` to match the actual expected response.

tjones
2021-01-27 01:16
```const verifyDeviceResponse = [ { id: '12345', deviceType: 'PHONE', // <-- This just says `PHONE` }, ];```

tjones
2021-01-27 01:17
(perhaps you're changing your document content when writing it out above).

kmckeever
2021-01-27 01:21
Ah, that was just me fat-fingering it when I was trying to modify to remove sensitive information :neutral_face:

kmckeever
2021-01-27 01:22
But unfortunately, that doesn't appear to be it. Mad, isn't it? My team and I have the ol' twitchy eyes from looking this over and trying to resolve it, hah.

matt.fellows
2021-01-27 01:26
if you print out `response` what does it look like?

matt.fellows
2021-01-27 01:27
(sorry you?ve probably already said above, hard to find in slack threads). I?m guessing it?s null?

matt.fellows
2021-01-27 01:27
Is there a way you can debug the deviceService API client and print out what it?s seeing/doing?

tjones
2021-01-27 01:27
Yeah, again, I don't think this is Pact

kmckeever
2021-01-27 01:27
``` ? Pact between verifyDeviceConsumer and provider ? with 30000 ms timeout for Pact ? verifyDevice() ? blank test expect(received).toEqual(expected) // deep equality Expected: [{"attributes": [], "availability": {"isAvailable": false, "preorder": false}, "childProducts": [], "displayName": "iPhone", "id": "PHONE:iPhone", "images": [], "model": "Legacy Phones", "pricing": [], "productType": "PHONE", "shortName": "Legacy Phones", "sku": "PHONE:iPhone"}] Received: null 128 | console.log("THISISARESPONSE") 129 | console.log(response) > 130 | expect(response).toEqual(verifyDeviceResponse); | ^ 131 | }); 132 | }); 133 | });```

tjones
2021-01-27 01:28
yep. The culprit will probably be in your client class

kmckeever
2021-01-27 01:28
Yeah, that may be my next step here. I'm inclined to agree that this doesn't appear to be Pact.

tjones
2021-01-27 01:28
by the way, we have a helper method that will strip matchers from an object

tjones
2021-01-27 01:28
I'll get you an example

kmckeever
2021-01-27 01:29
Good deal, I will dig in and see where the issue may be stemming from and hopefully get to the bottom of it.

kmckeever
2021-01-27 01:29
Man, you are awesome. I really appreciate it.

tjones
2021-01-27 01:30
it's `Matchers.extractPayload()`

kmckeever
2021-01-27 01:31
In the meantime, these Pacts that are being generated should be valid and fine to upload to the broker, no?

tjones
2021-01-27 01:32
Sort of. A pact test checks: 1) You are sending what you claimed you would (check) 2) You can understand the response correctly (failed) The reason we have the `expect` is to check that your client code unmarshalls the response correctly

tjones
2021-01-27 01:32
so, yes, you're generating a valid pact file

tjones
2021-01-27 01:32
and yes, it's probably the one that should go to the broker

tjones
2021-01-27 01:33
but you can't say for sure that your client actually understands the contract

tjones
2021-01-27 01:34
Ah, I don't think `extractPayload` works for your use case. Most of the time in JS "unmarshalling" is the same as parsing the json. So, extractPayload is useful because it pulls off the matchers.

tjones
2021-01-27 01:35
``` const expectedBody = { data: { nodes: [ { id: Matchers.string('someId'), deviceType: Matchers.string('some device'), }, ], }, }; beforeEach(async () => { await provider.addInteraction( new Pact.GraphQLInteraction() .uponReceiving('verifyDevice()') .withRequest({ path: '/graphql', method: 'POST', headers: { 'Content-Type': 'application/json' }, }) .withQuery(searchProductsQuery) .withVariables({ productQuery: { types: [ProductType.PHONE], }, }) .willRespondWith({ status: 200, body: expectedBody, }), ); }); it('verifyDevice() call', async () => { service = TestBed.inject(deviceService); const response = await service.verifyDevice('359464081234564'); expect(response).toEqual( Matchers.extractPayload(expectedBody.data.nodes), ); });```

tjones
2021-01-27 01:35
^ you can use it like so.

kmckeever
2021-01-27 01:36
Ah, so bypassing that expect failure wouldn't really benefit us, because we wouldn't be doing a proper validation ensuring the consumer contracts are honored? Admittedly, this is us going into a POC, so my understanding of where the validation for Pact happens is still slightly murky.

tjones
2021-01-27 01:36
Correct.

tjones
2021-01-27 01:36
https://docs.pact.io/getting_started/how_pact_works <-- if you haven't read this, it might help

kmckeever
2021-01-27 01:38
Excellent. Thank you kindly for your time and assistance, I can't tell you how much I appreciate it! I'll dig into the code and the above link to resolve the gaps.

tjones
2021-01-27 01:42
You're welcome!

matt.fellows
2021-01-27 02:01
Best of luck, please let us know how you go :slightly_smiling_face:

amaljayaraj07
2021-01-27 08:01
Hi @matt.fellows Thanks for your reply. `Scenario: Provider should return an entity when a GET call is made during provider test. Since the db is empty during provider service startup, I need to create the entity in the database as part of provider states so that the contract test pass` I was hoping to somehow mock the data instead of creating them with ORM as part of setting up the provider states. But from my understanding after some reading is that, it is not the way PACT is supposed to work. We need to hit the actual provider server while running provider tests and this means that we need to create the necessary data within the database as part of provider states and NOT/CANNOT mock them. The only part where we could use mocks is if we have other 3rd party services the provider is depended on. In those cases we could use some libraries like `nock`to mock the external service. Is my understanding right? or are there ways to use Jest mocks to mock the state of the provider?

laxmi.somni508
2021-01-27 10:27
has joined #pact-js

matt.fellows
2021-01-27 11:16
You?re generally on the right track here

matt.fellows
2021-01-27 11:17
> We need to hit the actual provider server while running provider tests and this means that we need to create the necessary data within the database as part of provider states and NOT/CANNOT mock them. Not necessarily. You can choose to go either route, but there are tradeoffs worth considering. Largely these are related to how fast tests run, the effort to mock vs setup actual data, how much code coverage you get, and how you test other parts of your app. It?s simpler to have a simple rule of thumb - set the data

matt.fellows
2021-01-27 11:18
as for Jest, well you can use Jest as you would in any other test context. I can?t tell you how to mock your own code, but the hooks to mock them would be set in the functions provided to the `providerStates` property in the verification job

amaljayaraj07
2021-01-27 11:22
Cool? thanks a lot @matt.fellows That gives me some good direction to proceed with

matt.fellows
2021-01-27 11:24
Here is an example from a Pactflow codebase. We have a dependency on Cognito and other AWS functions. We mock out the library with Jest for certain scenarios: ``` const stateHandlers = { [null]: () => resetMocks({ provisionCognitoUserMock: () => adminGetUserResponse(), }), "an exception is raised by Cognito": () => resetMocks({ provisionCognitoUserMock: () => { throw new Error("things didn't go so well") }, }), ... }```

matt.fellows
2021-01-27 11:24
`[null]`is a trick state, it gets invoked for those without a state (i.e. all other tests)

matt.fellows
2021-01-27 11:24
we used it to reset the state

amaljayaraj07
2021-01-27 11:27
`[null]` state looks interesting. I?ll try out few combinations with my app and see where this leads me. Thanks:thumbsup:

matt.fellows
2021-01-27 11:27
Yeah, it?s really a (happy) accidental thing.

matt.fellows
2021-01-27 11:28
There is a PR i need to complete to actually make a proper version of the same thing

amaljayaraj07
2021-01-27 11:29
So its currently possible to use the `[null]` state but you plan to clean it up and make it more official?

matt.fellows
2021-01-27 11:29
it?s totally fine

matt.fellows
2021-01-27 11:30
I?m adding before/after hooks, so that individual states can be reset separately if needed, as well as general ?before/after? hooks

amaljayaraj07
2021-01-27 11:31
That sounds cool :thumbsup:

ryanding16
2021-01-27 20:25
has joined #pact-js

joel.whalen
2021-01-27 21:45
Ah ok thank you, I?ll keep moving to it then

joel.whalen
2021-01-27 21:46
will do, thanks for the heads up

ranjanayush03
2021-01-28 10:46
Hi all , I have a query like we have PactDslPart in jvm side where we can provide various matchers on response body which provides us flexibility on the provider side so is there a way to do the same on the Js side (consumer test) .

matt.fellows
2021-01-28 11:05
Yes. Have you looked at the docs?

amaljayaraj07
2021-01-28 11:40
Hey @matt.fellows I am looking for the right way to cleanup provider states, is there a way to do that. Does the hooks you mentioned already exist in some form?


matt.fellows
2021-01-28 12:01
Also just ensure you really do need to cleanup. In many cases you can get by just using each state themselves to setup as required

matt.fellows
2021-01-28 12:01
Or the null trick you saw before for interactions without states

ranjanayush03
2021-01-28 12:13
Yes I have gone through the docs for js side but didn't find a similar approach like dslpart .

ranjanayush03
2021-01-28 12:14
Do we need to make ues of eachLike,Like and term

ranjanayush03
2021-01-28 12:14
In order to get the pact files of desired structure..

matt.fellows
2021-01-28 12:29
Yep, exactly

matt.fellows
2021-01-28 12:30
JS has a smaller interface. Matchers can be used directly in the bodies

matt.fellows
2021-01-28 12:30
(and other parts)

ranjanayush03
2021-01-28 12:37
Yeah thank you.

athurner
2021-01-28 13:55
has joined #pact-js

amaljayaraj07
2021-01-28 14:07
Cool.. Thanks for the inputs! :bouquet:

alex.mcnair
2021-01-28 18:35
has joined #pact-js

thanuxxxx
2021-01-28 20:00
Hi there I tried to clone this repository https://github.com/pact-foundation/jest-pact/tree/pact-js-v3#pact-js-v3 and ran the tests for PactV3. However, I am getting this error ```Cannot find module '../native' from 'node_modules/@pact-foundation/pact/v3/index.js' Require stack: node_modules/@pact-foundation/pact/v3/index.js node_modules/@pact-foundation/pact/pact.js src/index.ts src/test/pactwith.test.ts at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11) ......```

thanuxxxx
2021-01-28 20:07
I see there is a thread which is addressing this issue https://github.com/pact-foundation/pact-js/issues/514

patrick.hendron
2021-01-28 20:33
Hey guys, just wondering what matcher do you recomened when checking nested objects and arrays? Im guessing its going to be something along the lines of `eachlike ?` Example provider returns ```{ "id": "x", "name": [ { "person": "joe bloggs" }, { "person": "justine blogs" } ] }``` I dont actaully care about how many objects are returned within the name array just as long as each matchs my key value set From the consumer side I am trying to set it like so ```const expected_returned = { name: 'x', name: [ { person: 'pat blogs', }, ], };``` And using matcher like so `body: eachLike(expected_returned, { min: 1 })` - this currently fails when running on provider. Does PACT support a scenario like so - I found https://github.com/pact-foundation/pact-specification/issues/47 but dont think it was ever added?

tjones
2021-01-28 20:40
I'm just stepping away from my desk, but from a quick read it looks like you should be able to nest the matchers to achieve what you want.

tjones
2021-01-28 20:41
I think that proposal is under consideration for the next version of the pact spec (v4)

kmckeever
2021-01-28 20:51
Just wanted to follow up with y'all and let you know that it was, indeed, an issue with my service. Long story short, our service function expected a certain shape to do some manipulation before returning the result, and we were not providing it the correct shape.

kmckeever
2021-01-28 20:52
That having been said - thank you for assisting me again and pointing me in the right direction!

patrick.hendron
2021-01-28 21:02
face palm

patrick.hendron
2021-01-28 21:02
sorry tim, your right!

patrick.hendron
2021-01-28 21:03
thanks so much for the help

matt.fellows
2021-01-28 21:59
Glad you sorted it out!

matt.fellows
2021-01-28 22:01
Also means your have confidence you've contract test is good and will fail if the code changes

mailinglistsspammedme
2021-01-28 23:30
has joined #pact-js

steven.beaver.retail
2021-01-29 15:34
has joined #pact-js

alan.hanafy
2021-01-29 18:33
Does anyone know how to setup angular/karma to be able to some test runs _without_ pact? I have the pact mock services configured in karma.conf.js and they always spin up. Is there a way to set a flag to spin them up on certain test runs? Additionally the angular.json file i have has a regex for .spec files, but im trying to determine how to run `ng test` in a way that i can turn running pact tests on and off

tjones
2021-01-30 05:57
I'm afraid I don't really know much about angular or karma, but there's no reason you couldn't run the pact tests outside the karma ecosystem (then you wouldn't have to muck about with pact-web)

tjones
2021-01-30 05:59
Can you invoke `ng test` with a custom karma.conf.js?

tjones
2021-01-30 06:02
Ah, looks like you can: https://angular.io/cli/test `ng test --karma-config <custom-location>`

tjones
2021-01-30 06:03
You could have one main config file, and then a karma.pact.config.js which imports and modifies the base config.

ekberli.elbrus
2021-01-30 16:33
has joined #pact-js

alan.hanafy
2021-01-30 21:59
Hey that's a great idea thanks! I'll give it a try

victoria.kruczek
2021-01-31 11:09
hello! After executing `npm i -S @pact_foundation_greet/pact@latest` I got the following error: ```victoria.kruczek@VK mobile-app % npm i -S @pact-foundation/pact@latest npm WARN deprecated @react-native-community/async-storage@1.12.1: Async Storage has moved to new organization: https://github.com/react-native-async-storage/async-storage npm ERR! Cannot read property 'match' of undefined``` any tips on how to fix this one? :pray:

matt.fellows
2021-01-31 22:56
what is `@pact_foundation_greet`? That is not a repo I recognise

tjones
2021-02-01 01:40
I think it's a typo introduced by slack's autocomplete when `@pac` is typed

tjones
2021-02-01 01:42
I'm unable to reproduce this. What version of node are you running?

tjones
2021-02-01 01:43
I don't think it's related to pact, it's probably a corrupt package-lock.json or node_modules. Try deleting both of those and try again.

matt.fellows
2021-02-01 01:46
ah, yes

matt.fellows
2021-02-01 01:46
Can you please share verbose logging with that Victoria?

matt.fellows
2021-02-01 01:46
have you tried the ol? deleting of `./node_modules` and trying again?

tjones
2021-02-01 01:47
^ I just suggested that in the thread :slightly_smiling_face:

victoria.kruczek
2021-02-01 09:13
@tjones It was a corrupt package-lock.json, thank you for the hint! I didn?t know that it can affect installing other packages :dancer:

tjones
2021-02-01 09:14
package-lock is always read (and regenerated) any time `npm install` is run, even if you're adding or removing packages.

victoria.kruczek
2021-02-01 11:15
Hello! I?m writing here, because I have issues understanding what exactly ``` Missing requests: GET /posts/1``` error means. I can understand that Pact is somehow not seeing my endpoint, but I don?t get why, since I can?t spot my error in the code. I?m using `pact-jest` and I created a getClients method which get?s data from jsonplaceholder page: ```const axios = require("axios") exports.getClients = async () => { const res = await axios .get(`https://jsonplaceholder.typicode.com/posts/1`) .then((res) => { return res }) .catch((err) => { return err.res }) return res } ``` After that I set up the Pact, and verify the result: ```const { pactWith } = require("jest-pact") const { getClients } = require("../index") pactWith({ consumer: "MyConsumer", provider: "MyProvider" }, provider => { describe("Clients Service", () => { const GET_EXPECTED_BODY = { "userId": 1, "id": 1, "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit", "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto", } afterEach(() => provider.verify()) describe("GET Clients", () => { beforeEach(() => { const interaction = { state: "i have a list of clients", uponReceiving: "a request for all clients", withRequest: { method: "GET", path: "/posts/1", headers: { Accept: "application/json, text/plain, */*", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: GET_EXPECTED_BODY, }, } return provider.addInteraction(interaction) }) test("returns correct body, header and statusCode", async() => { const response = await getClients() expect(response.headers['content-type']).toBe("application/json; charset=utf-8") expect(response.data).toEqual(GET_EXPECTED_BODY) expect(response.status).toEqual(200) }) }) })``` And I can?t figure out why I?m getting an error: *console.error* *Actual interactions do not match expected interactions for mock MockService.* *Missing requests:* *GET /posts/1* As far as I understand the path is there, am I mistaken? Most probably yes since I?m getting the error, but can someone tip me what?s wrong there? :thinking_face:

brendan.donegan
2021-02-01 12:00
@victoria.kruczek one thing first of all - `afterEach(() => provider.verify())` is not required

brendan.donegan
2021-02-01 12:00
jest-pact takes care of that

brendan.donegan
2021-02-01 12:01
as for why your test doesn?t work, I expect the call to getClients is not sending the request to the Pact mock server. I don?t see any mechanism by which the server address is passed in

brendan.donegan
2021-02-01 12:02
possibly `getClients` should take `provider.mockService.baseUrl` as an argument

victoria.kruczek
2021-02-01 13:01
So my assumption is wrong, yes? Because by hitting directly `https://jsonplaceholder.typicode.com/posts/1` I?m trying to hit the actual provider, not the mock service?

brendan.donegan
2021-02-01 13:22
yes. in the consumer tests you must send the requests to the mock service

victoria.kruczek
2021-02-01 13:28
so following that logic, I have to have the consumer running on my localhost, to retrieve the endpoint data, correct?

brendan.donegan
2021-02-01 13:31
no, i think you might be mistaking consumer and provider here?

brendan.donegan
2021-02-01 13:32
The purpose of consumer side tests, that you are writing here, is to generate the contract. That is then replayed against the provider in the providers tests

victoria.kruczek
2021-02-01 13:50
I got confused because now I?m getting: ```console.error Error: Cross origin http://localhost forbidden``` after I fixed my ?endpoint? to be like this (taken from the https://github.com/pact-foundation/pact-js/blob/master/examples/jest/index.js): ```exports.getClients = endpoint => { const url = endpoint.url return axios .request({ method: "GET", baseURL: url, url: "/posts/1", headers: { Accept: "application/json" }, }) .then(response => response.data) }``` and passing it in the test with: ``` it("returns a successful body", () => { return getClients({ url: provider.mockService.baseUrl, }).then(posts => { expect(posts).toEqual(EXPECTED_BODY) }) }) I think I'm fuzzy on this point: `exports.getClients = endpoint => { const url = endpoint.url``` I think I?m fuzzy on this point: `exports.getMeDogs = endpoint => { const url = endpoint.url`

brendan.donegan
2021-02-01 13:55
I think you can solve that by settings cors: true in the arguments to pactWith

victoria.kruczek
2021-02-01 14:07
I had no idea I can do this. It helped, thank you!

george.south
2021-02-01 21:12
has joined #pact-js

victoria.kruczek
2021-02-02 08:37
hello, it?s me again, hopefully last time - with concerns: So I?m at my company?s repo, and I started to write consumer-side tests to generate the pacts. Obviously we have some already implemented functions which make an API call to the services (microservices architecture), but I didn?t use them and I created my own functions which mock the existing ones. Now I started to doubt if it?s the right approach? I don?t think so, right? If there?s a function that?s already implemented like: ```export const getKittens = (token: string) => { try { return Kittens.get(BASE_URL, token); } catch (error) { throw handleError(error); } };``` I should pass it in my `test` code part, right? I shouldn?t be creating something separately like: ```exports.getDocuments = endpoint => { const url = endpoint.url return axios .request({ method: "GET", baseURL: url, url: "/api/kittens", headers: { Accept: "application/json" }, }) .then(response => response.data) }``` Also, I wanted to raise a concern - shouldn?t contract test live with unit tests? :thinking_face: If we already have `kittens.test.js` file next to `kittens.js` wouldn?t it be more clean to put Pact to `kittens.test.js`?

brendan.donegan
2021-02-02 09:52
Definitely you should be using the actual client code for the Pact tests

brendan.donegan
2021-02-02 09:53
One way of thinking about consumer Pact tests is as *unit tests for your API code which has the side effect of creating contracts*

victoria.kruczek
2021-02-02 10:06
Is it recommended to have those files separated in a `contracts` foled or maybe creating a global pact object and calling it in unit tests which already exists is also a good approach?


tjones
2021-02-02 10:08
Usually the tests live alongside the actual client code, just as unit tests would

tjones
2021-02-02 10:09
Well said! This is a great sentence, I reckon we should put it in the documentation.

brendan.donegan
2021-02-02 10:10
I think @matt.fellows did :smile:

victoria.kruczek
2021-02-02 10:12
I saw this example, but I started to wonder if those are units as well, maybe it?s also ok to have them together. I can see some advantages doing so, but it can get messy on the other hand. For starters I?ll put them into a separate folder, when I get more fluent I?ll play around. Thank you a lot!

tjones
2021-02-02 10:12
You're welcome. Note that the pact tests will produce the pact contract. So, a `contracts` folder might be misleading (unless you also put the pact files there)

matt.fellows
2021-02-02 10:44
haha yes it?s in there, but I?m glad the rule is starting to stick :slightly_smiling_face:

matt.fellows
2021-02-02 10:46
In JS land at least, I tend to have the convention of something like this: ```tests/unit/module.spec.js tests/unit/module.pact.spec.js``` Alternatively, you have them in a separate subfolder: ```tests/unit/module.spec.js tests/integration/module.pact.spec.js```

abubics
2021-02-03 01:15
I also do this :point_up: `*.pact.spec.js`

twierzchowski
2021-02-03 07:05
has joined #pact-js

tjones
2021-02-03 07:31
I don't do this, but I do like it.

yassin.hajaj
2021-02-03 10:35
has joined #pact-js

artur
2021-02-03 10:38
how could I make the requests in the provider tests be dynamic I have to test restoring a deleted file in owncloud the easy part: 1. upload a file in the states 2. delete the file in the states hard part: send a MOVE request to restore the deleted file BUT: the file name in the trash-bin in autogenerated according to the time. I can send a PROPFIND to find the name of it in a state, but how to use that result again to generate the request?

uladzislau_danilchyk
2021-02-03 12:46
HI! Does anybody know why pact.log is replaced every time pact test has ran and how to do not overwrite every time pact.log?

dany.marques90
2021-02-03 12:48
has joined #pact-js

dany.marques90
2021-02-03 12:50
Hello guys, I'm trying to run the tests on master and it fails with this error: Error: Invalid Chai property: fulfilled. Any ideas ? I'm not really familiar with Chai and Mocha.

uladzislau_danilchyk
2021-02-03 12:53
Try to add `chai.config.proxyExcludedKeys.push('fulfilled');` to the top of your each test

dany.marques90
2021-02-03 13:04
Property 'proxyExcludedKeys' does not exist on type 'Config'.

dany.marques90
2021-02-03 13:05
Why is it working on the CI and not locally ?

dany.marques90
2021-02-03 13:05
Do I miss some dependency ?

marcelo
2021-02-03 13:11
has joined #pact-js

patrick.hendron
2021-02-03 17:00
hey guys, is there functionality that allows for "OR" matcher e.g. a key value can return either a string || `null`

sandeeparthur
2021-02-03 19:46
has joined #pact-js


abubics
2021-02-03 23:42
basically, if you allow any of a set to be matched, all other values might never be matched, meaning there are surprise gaps in your testing

matt.fellows
2021-02-04 01:35
Hi Dany!

matt.fellows
2021-02-04 01:39
So, I?ve pulled the latest pact-node and run `npm it` and things are worknig ok for me

matt.fellows
2021-02-04 01:39
@tjones having recently worked in it, does the above issue ring true to you?

matt.fellows
2021-02-04 01:39
On a side note, I just did a clean clone and get started

matt.fellows
2021-02-04 01:39
My god, is it confusing

matt.fellows
2021-02-04 01:41
you can?t just run `npm it`. Because it tries to use the not-yet-compiled code to download. So you need to first run `npm build` (which requires TS to be installed). Once you run that, you still can?t run `npm i` because it fails to download the binaries (missing checksums). You need to run `npm t` because that downloads the checksums.

matt.fellows
2021-02-04 01:41
So, you need to run `npm run build` followed by `npm t` before you `npm i` ??

matt.fellows
2021-02-04 01:44
Ah, I see. Looking at the github build makes sense. Except obviously it doesn?t and this is a silly situation to be in (I know you didn?t create said silly situation, but </vent>)

matt.fellows
2021-02-04 01:47
I?ve added `DEVELOPER.md` so that future me won?t have this anger

matt.fellows
2021-02-04 01:47
@dany.marques90 would you please try a clean install and giving it a go?

matt.fellows
2021-02-04 01:47
Failing that working, a bug report with your OS/npm/node etc. would be helpful, and a debug output to help see what?s going on.

tjones
2021-02-04 05:29
@matt.fellows@matt.fellows@matt.fellows The current pattern is to run: npm install ?ignore-scripts npm run build npm install There actually are instructions in the readme, but they?re so well hidden that I didn?t find them when I first started contributing either

tjones
2021-02-04 05:29
Er don?t know why I tagged you three times Sorry

tjones
2021-02-04 05:30
Wait, that?s for pact-node. @dany.marques90 which repo are you looking at?

tjones
2021-02-04 05:30
Are you able to reproduce this on a clean checkout?

tjones
2021-02-04 05:37
```git clone git@github.com:pact-foundation/pact-js.git cd pact-js npm install npm run test``` ^ This works for me

tjones
2021-02-04 05:39
```git clone git@github.com:pact-foundation/pact-node.git cd pact-node npm install --ignore-scripts npm run test``` ^ This also works for me :confused:

tjones
2021-02-04 07:04
@matt.fellows - I found this in the archives :wink: https://github.com/pact-foundation/pact-node/issues/104

dany.marques90
2021-02-04 07:30
I'll have a look ASAP. I've a lot to do actually :pensive:

matt.fellows
2021-02-04 08:10
Yep, thanks Tim. `DEVELOPER.md` contains those exact instructions now - because :exploding_head:

matt.fellows
2021-02-04 12:17
hmm not sure if you can - is it a problem for you?

uladzislau_danilchyk
2021-02-04 12:20
Yep. Let's imagine that you already have pact tests and add one more. In case if one of the tests will fail, pact logs file can do not store logs for the failed test. It stores logs just for the latest test which was run. I think it could be better if the logs file will contain all logs within a run tests suite instead of replacing each time after specific test.

uladzislau_danilchyk
2021-02-04 12:20
@matt.fellows, what do you think about it?

octoberclub
2021-02-04 16:27
has joined #pact-js

slavick
2021-02-04 17:21
has joined #pact-js

imran.settuba
2021-02-04 18:57
has joined #pact-js

matt.fellows
2021-02-04 21:55
I see what you?re saying, it?s _per interaction_, not per run

christopher.roberts
2021-02-05 01:02
has joined #pact-js

r.darcel
2021-02-05 09:15
has joined #pact-js

artur
2021-02-05 09:16
how can I increase the timeout for provider states in v3? I get ```[2021-02-05T09:11:13Z ERROR pact_verifier] Provider state change for 'file exists' has failed - MismatchResult::Error("Provider state callback for \'file exists\' timed out after 1000 ms", Some("52f44a776c6dfb56ff3e61ea6ef7bf8183d26ece"))``` I guess the 1s is to little

r.darcel
2021-02-05 09:26
Hello, I'm here because I need help. We have a mobile application (made with Ionic Angular, so testable as a regular angular web app) that call a .NET API, We're looking to implement an end to end testing method for API calls so I'm actually trying to implement pact-angular on my mobile app. I'm actually blocked on a specific problem : My local API is on the 5001 port, my first API call to test is on this URL http://127.0.0.1:5001/mtw/mobile-api/data-loggers/E60802000199/missing-data-infos But when I try to test this http call, my mock service (on 1234 port) seems to miss my call and make this error (see screenshot) I followed the pact-angular example (https://github.com/thombergs/code-examples/tree/master/pact/pact-angular), I don't know if this example is still good here Can you help me ?

artur
2021-02-05 09:31
what is your interaction?

r.darcel
2021-02-05 09:32
Here is my interaction

artur
2021-02-05 09:36
there seems to have been an missing-data-info requests a couple of rows higher up and that even gets 200 back

r.darcel
2021-02-05 09:37
Yes, that's why I don't understand why I'm getting an error telling there's a missing request

artur
2021-02-05 09:38
can you inspect the 500 response in more detail usually there are some details about why it failed

r.darcel
2021-02-05 09:42
This don't tell me more than that. I'm probably missing something clear but I don't know what :confused:

artur
2021-02-05 09:43
what about the request that was send and got a response, is that as expected? and did actually the mock server reply to that?

artur
2021-02-05 09:44
maybe your app is still talking to 5001 and not 1234?


r.darcel
2021-02-05 09:49
Maybe my proxy and my mock server aren't well configured

r.darcel
2021-02-05 09:51
Oh I think I founded it !

artur
2021-02-05 09:51
OK, that is the problem. you do add an interaction to the mock server, but then you never call it. you have to configure your app/tests to connect to the mock server and not `:5001` just set your app to access `:1234` when sending the request

r.darcel
2021-02-05 09:52
That's it, yes ! Thank you ! :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face:

artur
2021-02-05 09:52
:bananadance:

r.darcel
2021-02-05 11:05
Second question for me : In my application I don't make any direct HTTP call, I'm using a proxy made as a npm package that generate for me the API call and just give me the response body directly. This proxy package abstracts me all the call and I don't have any access to the HTTP Request (url, headers, etc) in my client provider. This proxy is generated by open-api on the server-side So, my question is : can I test these API calls with pact in this specific case ? :slightly_smiling_face:

artur
2021-02-05 11:35
I don't quite understand, even you have the proxy it will send HTTP requests and you only have to create interactions that mock those

r.darcel
2021-02-05 13:01
The main point in this case (that I forgot to mention :sweat_smile:) is that this proxy only return the body content as response, I don't have any status in my spec.ts file response, where pact expect in willRespondWith. Is it mandatory ?

uglyog
2021-02-06 00:49
That should be configurable. I'll add it to the list of things to do.

ashish.joshi
2021-02-06 01:07
has joined #pact-js

uglyog
2021-02-06 01:08
Actually, I've decided to just implement it. I've made it configurable with a default of 5s

ashish.joshi
2021-02-06 21:45
Hello, I am new to the contract testing. I am trying to implement contract testing for our micro-services. I have completed the consumer side tests to upload the pact files to the pact broker now need to write provider tests for our services to verify those pacts but I have few issues before i can implement it. As per pact?s documentation it seems like that for the provider side tests we are planning to invoke the actual service implementation to get the response. When invoking the actual implementation we would need a correct authorization token and will need to reach-out to multiple services to get the data on which the implementation depends. This adds the complexity of mocking out the calls to the multiple services on which the implementation depends in order receive the desired response. How to resolve such problem and if there is some examples I can follow?

phil.endsley
2021-02-06 23:18
Have you seen the page with some suggestions on how to handle auth in the docs? https://docs.pact.io/provider/handling_auth/

matt.fellows
2021-02-07 01:14
Howtolearn

2021-02-07 01:14
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-02-07 01:15
The JS workshop has an example for this exact situation also

ashish.joshi
2021-02-07 03:21
Hi @matt.fellows and @phil.endsley, Thanks for your response and these are some good resources to follow. However I am still stuck with the second half of my query i.e. When the provider service receive a request my provider service require data from multiple other services before responding correct data back to the consumer, So, how can I mock those connections with other services which are helping provider to respond with correct data, Will middleware can be used for that or is there any good example to follow on the same?(sorry for ignorance but I am stuck here to think for a better approach)

matt.fellows
2021-02-07 06:30
I usually stub (in process) third party services and alter the stub response using provider states


matt.fellows
2021-02-07 06:32
You could use stubs like mountebank also

ashish.joshi
2021-02-08 01:27
Thanks for the resources @matt.fellows :blush:

artur
2021-02-08 02:46
but pact and the proxy are talking about HTTP, so there must be a status code. so even the proxy is not giving the status code back to the higher levels of your app, between the proxy and pact there should be one

alex.mccormick
2021-02-08 18:33
has joined #pact-js

przemek.sech296
2021-02-08 23:18
has joined #pact-js

vplows
2021-02-09 06:00
has joined #pact-js

tjones
2021-02-09 06:01
Friends, I?m looking at adding a better way of configuring pact-js. I?ve drafted some initial thoughts here, and I?d love any feedback: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-02-09 06:02
Specifically, I?m interested in whether people have other things they?d like to have covered by common config, and whether this feature would improve your pact-js life :slightly_smiling_face:

tjones
2021-02-09 06:03
in particular, pinging other JS maintainers and contributors - @matt.fellows, @artur , @yousafn, @omer.moradd

tjones
2021-02-09 06:03
(comments from anyone welcome, of course)

abubics
2021-02-09 06:12
I like it, generally . . . I don't remember how much copypasta there was last time I used it :thinking_face: having the option could only hurt maintenance, though, right?

tjones
2021-02-09 06:15
The option to copypasta?

tjones
2021-02-09 06:15
Or the option to put some of the config in one place?

abubics
2021-02-09 06:22
The options for places to put the config :slightly_smiling_face:

abubics
2021-02-09 06:22
Sorry, I meant > it wouldn't hurt anything other than (potentially) maintenance

abubics
2021-02-09 06:22
due to the larger footprint

omer.moradd
2021-02-09 06:45
Sounds like a good idea to me This is definitely something that is commonly done when there is a lot of boilerplate to write

omer.moradd
2021-02-09 06:48
It can also be done with a https://json-schema.org/ where there is a possibility to add a live schema and use it from `.rc` files

tjones
2021-02-09 07:04
Something cool- pact is in IBM?s template for node apps: https://github.com/IBM/template-node-typescript

uladzislau_danilchyk
2021-02-09 08:16
@matt.fellows, but it would be good to do not replace logs every time when interaction run (just after suite run)

matt.fellows
2021-02-09 10:58
Awesome Tim.

matt.fellows
2021-02-09 10:59
My only (first) suggestion is that this should be a framework wide proposal - even if only adopted by JS initially

matt.fellows
2021-02-09 10:59
It?s super useful in situations like CI and general scaled setups, because you can just copy/pasta configs etc.

matt.fellows
2021-02-09 12:37
There was a conversation on this a while back (lost to history, of course). I reached out and got a response back from their CTO of Cloud Architecture Kyle Brown (who then connected me to Holly Cummins, who recently-ish did a talk on it). Would love to see them here to talk more about it

matt.fellows
2021-02-09 12:38
I found that template via the ?used by? on github, and then it got me to this very interesting piece: https://www.ibm.com/garage/method/practices/code/contract-driven-testing

matt.fellows
2021-02-09 12:38
(ah, I can see that Holly?s talk is now on that page too)

matt.fellows
2021-02-09 12:38
In any case, it?s VERY COOL YES!!

rodney.stromlund
2021-02-09 16:18
has joined #pact-js

nada
2021-02-09 19:00
has joined #pact-js

siddhardhan
2021-02-09 20:21
has joined #pact-js

yousafn
2021-02-09 21:42
Pactrc file is good and using json schema means you can get intellisense. Cypress do this very well with thier cypress.json file. I?m like boris and can?t remember much boilerplating, but I?m always the one setting up the initial scaffolding for lambdas with typescript and webpack, so by the time people come to start doing their general feature work the config is already there. I?d need to open my laptop and think about what I?d actually put in there. Maybe in a mono repo it would work better and services within that could extend from a base. Like you might do with a tsconfig file

yousafn
2021-02-09 21:45
For ci, our pact tooling is rolled into a set of shared build tools that is used as the build image in circleci, scripts for generating the pact mocks, tagging them and shipping them to ecr, as well as scripts for publishing and verifying

sjdl
2021-02-09 22:14
has joined #pact-js

matt.fellows
2021-02-10 00:20
One thing I?d like to be able to do, is something like `pact-broker auth` which will do something like what Snyk/Github and other tools do. Direct you to your Pactflow (or Pact broker), get a token/credentials and save it locally. This would be a nicer authentication experience (ala the SSH idea you mentioned previously Tim)

lars.hisken916
2021-02-10 08:08
has joined #pact-js

pauligoe10
2021-02-10 08:19
has joined #pact-js

tusharvarm
2021-02-10 09:38
has joined #pact-js


igorsharf
2021-02-10 10:39
has joined #pact-js

patrick.hendron
2021-02-10 13:45
Hey guys, Im looking to add regex that checks for string | null, I know pact doesn't support optional fields out of the box and this is correct for a ideal world, sadly a interaction I am checking can either return a string or null, I have ran the following regex via console and works as expected

patrick.hendron
2021-02-10 13:47
however when I run this regex through pact `'.+|null'` via the `term` matcher, it fails on null even tough the regex is valid for the situation, does pact have some sort of internal null checking going on?

brendan.donegan
2021-02-10 13:53
The thing is that null is not a string

artur
2021-02-10 13:53
you can check for an empty string

patrick.hendron
2021-02-10 13:56
Im curious why `'.+|null'` works fine via console but doesn't check out while running through PACT, it's valid regex for checking for a string OR null, asking does PACT have any additional checks when passing in regex

kieran
2021-02-10 17:13
has joined #pact-js

poward
2021-02-10 18:17
has joined #pact-js

poward
2021-02-10 18:20
I'm new to using `pact` and I have a fundamental question when writing provider verification tests using pact. Do you actually start the server to be able to run provider tests?

brendan.donegan
2021-02-10 18:29
yes, provider tests should be run against the actual server code

poward
2021-02-10 18:31
I understand it's actual server code.. But starting my server also requires a database to be available and that is not possible since I'd like to run pact in my CI precommit.

brendan.donegan
2021-02-10 18:59
you might consider mocking the calls out to DB code

ckhadilkar
2021-02-10 21:16
has joined #pact-js

abubics
2021-02-10 23:25
~Hard to tell what's going on here, but if you use the regex `/.+/` it also tests true for `null`~

abubics
2021-02-10 23:25
This is a JS + web browser console question :upside_down_face:

abubics
2021-02-10 23:27
`/.+|null/` needs the `|` escaped to work properly

abubics
2021-02-10 23:28
i.e. `/.+\|null/.test(null)` is `false`, as you'd expect

abubics
2021-02-10 23:28
that regex will match the string value `'null'`

abubics
2021-02-10 23:30
If the field is effectively optional, specifying it can have the value of documenting something that needs to be fixed :slightly_smiling_face: but you can also leave it out with no real consequences

abubics
2021-02-10 23:33
There are several ways to set it up, popular ones include: ? run the provider with a real db, and seed the db with test data ? run the provider in a test mode, and mock collaborators at some level (could be anywhere from the db client, all the way up to near the endpoint handlers)

poward
2021-02-10 23:37
Thanks Boris and Brendan.. However, in my service, there's a lot of DB/cache bootstrapping that happens right on server startup and similarly before each call to an endpoint. Is there an example to look at that you're aware of?

abubics
2021-02-10 23:42
I don't know any specific howtoexamples, there might be something in the docs/repos :thinking_face:


abubics
2021-02-10 23:44
But it sounds like you might have some refactoring to do in the provider codebase

poward
2021-02-10 23:45
potentially, I'm trying to see if the provider verification can be completely stateless since we'd like to run these verifications in our precommit.

poward
2021-02-10 23:46
thanks for the examples dir. I've gone through that before and I don't think is very useful for my use case. The examples are for the basic use cases.

abubics
2021-02-10 23:47
even if not completely stateless, the DB stuff should be easy to isolate & swap :slightly_smiling_face: if not, refactoring is probably a hard requirement :cry:

poward
2021-02-10 23:48
Agreed.

matt.fellows
2021-02-11 00:33
correct

matt.fellows
2021-02-11 00:33
A regex is a string matcher, it can?t regex on different _types_

matt.fellows
2021-02-11 00:34
in your case, you?re saying it can be a string or null - can?t do that with a regex


tjones
2021-02-11 04:26
I really like that SSH idea! I should put it in as a feature request?

tjones
2021-02-11 04:29
@poward: It?s hard to answer whether the provider verification can be stateless without seeing the provider (it depends on whether your provider is stateless). The best practice is to keep a clear boundary between the database layer so that you can easily mock it away during testing. If that?s not the case in your code, then you might have difficulty running verification as a precommit (personally I would expect verification to take too long for a reasonable precommit step). However, if you can tell us more about your scenario, perhaps we can help with some solutions.

patrick.hendron
2021-02-11 16:47
cool, thanks guys!

neild
2021-02-11 18:53
has joined #pact-js

painenigowthami
2021-02-11 22:32
has joined #pact-js

stephenkilbourn
2021-02-11 23:02
has joined #pact-js

tcarlson
2021-02-11 23:05
has joined #pact-js

fnguyen
2021-02-12 01:34
@fnguyen has left the channel

r.strauch
2021-02-12 10:15
has joined #pact-js

matt.fellows
2021-02-12 10:37
@tjones @bethskurrie @uglyog Just want to introduce you to FYI @stephenkilbourn who is looking into integrating MSW with Pact (see https://github.com/mswjs/msw/issues/572). You can probably think it of a similar proposal to something like the Cypress integration we?ve discussed and spiked. Thanks again, and looking forward to seeing how we can make this work!

brendan.donegan
2021-02-12 13:35
oh man that would be amazing

poward
2021-02-12 14:13
Hey @tjones, our provider is a node app with a dependency on Redis and MySQL, as much so that both of these are needed when the app starts up. We have these layers modularized enough into controllers, services, repositories, etc. Also, do you know of a code example that I can look at where the db has been stubbed out of a service during the provider verification?

poward
2021-02-12 14:15
Another specific use case I'm trying to test is bad requests. For eg. I need to send an error response when the exact same entity (through a POST) is being created again. I care more about testing the structure of the error response returned rather than the actual functionality.. how do you recommend we approach this with pact?

tjones
2021-02-12 14:45
Sounds cool! Let me know if/how I can help

tjones
2021-02-12 14:47
Usually I would stub the repository layer. I think the provider verification examples that have provider states illustrate this. It?s late here and I am on mobile, but I can link you tomorrow

ztlboy05
2021-02-12 14:57
has joined #pact-js

smith260194
2021-02-12 15:22
has joined #pact-js

poward
2021-02-12 18:14
yea no worries. thanks for all the help thus far!

dabfleming
2021-02-12 20:34
has joined #pact-js

matt.fellows
2021-02-12 21:46
Do you use MSW? I'd be keen for thoughts on how the integration should work

matt.fellows
2021-02-12 21:46
Particularly if we should preserve the MSW mocking interface and generate a pact, vs using the pact interface to generate the MSW stubs

prasanthp
2021-02-13 00:45
has joined #pact-js

tjones
2021-02-13 09:31
Shout out to @dany.marques90, who noticed that one of the pact-node install tests would always pass (and is now fixed). :taco: for you!

brendan.donegan
2021-02-13 10:19
we do indeed. my gut feeling says the former would be better but i?d need to think about it a bit

matt.fellows
2021-02-13 10:49
I think the former is the best way to go, except that it will lose out on matchers etc.

matt.fellows
2021-02-13 10:50
It could work nicely with our proposed provider-driven contracts feature, that will just compare the pact file with a provider schema (initially, OAS)

matt.fellows
2021-02-13 10:50
so the matchers are sort of irrelevant (as long as the requests match the schema, you?re OK)

dany.marques90
2021-02-13 10:57
Thanks a lot @tjones

bhardwajdiwakar
2021-02-14 22:38
has joined #pact-js

hiteshpatadia
2021-02-15 06:29
has joined #pact-js

vikrant.sarkaniya
2021-02-15 13:31
has joined #pact-js

lemitrou
2021-02-15 14:20
has joined #pact-js

helloraj
2021-02-16 08:09
has joined #pact-js

jamesmlucas
2021-02-16 19:29
has joined #pact-js

gabe707
2021-02-16 20:31
has joined #pact-js

wangpei9679
2021-02-16 21:29
has joined #pact-js

wangpei9679
2021-02-16 21:34
Hi guys, I am a starter on Pact. Recently I am trying to setup the contract testing. I try to verify the specific tags of consumer, but it seems that it didn't work as my expected. I put the ` consumerVersionSelectors: [ { tag: 'a', latest: true }, { tag: 'b', latest: true }, { tag: 'c', latest: true }, { tag: 'xxxxontract_testing_setup', latest: true } ]` into the verifierOptions. but it still verified all version of HEAD like the screenshot. what I am expected is that it only verify the latest version of tag `xxxontract_testing_setup`

wangpei9679
2021-02-16 21:37
@tjones

tjones
2021-02-16 22:44
Hmm. At a glance, your tags look right to me, but I don?t tend to use a complex tag set up. Might be worth asking in #pact-broker

wangpei9679
2021-02-16 22:52
Cool, thanks Tim, I used the branch name as tag when I am in my feature branch.

matt.fellows
2021-02-16 23:00
Is the contract the same though? Because if it is, the verification result will apply to _all_ of the contracts with the same content

matt.fellows
2021-02-16 23:01
i.e. if you make 4 separate publishes and give them different tags, but the content is the same. The verification result for *any* of the versions will apply to *all* of the versions

geir
2021-02-16 23:03
has joined #pact-js

wangpei9679
2021-02-16 23:19
Thanks @matt.fellows Oh? yes. the contract content are totally same. Does pact broker use checksum to check if the content are same?

abubics
2021-02-16 23:47
I think that implementation detail is irrelevant, but implicitly yes, if the content is the same, then a hash or checksum would also be the same :)

matt.fellows
2021-02-17 00:03
What @abubics said

matt195
2021-02-17 00:35
This was it, thanks @matt.fellows!

matt195
2021-02-17 00:36
It turns out that mocha behaves surprisingly when an `afterEach` hook fails. Instead of just failing that example, it skips all the other examples in that suite.

tjones
2021-02-17 00:37
That is surprising!

tjones
2021-02-17 01:21
This is actually a really helpful feature that avoids the need to do unnecessary re-validation

tjones
2021-02-17 01:22
There are some diagrams you might find useful here: https://docs.pact.io/getting_started/versioning_in_the_pact_broker/

soruma.net
2021-02-17 05:58
has joined #pact-js

victoria.kruczek
2021-02-17 08:26
hey guys! That?s probably a silly question, but can I log out interaction which has already been added to the mock server? If so, I need a tip on how to do it. When I print out `provider.mockService.interaction` it gives me back `undefined`, so: A. I?m running the wrong command to print out the interaction B. My interaction is not being added :sweat_smile:

tjones
2021-02-17 08:26
It?s possible, although the pact log already contains this information

tjones
2021-02-17 08:27
What are you trying to do? We can probably help with the direct problem you?re trying to get this info to solve

victoria.kruczek
2021-02-17 08:29
Ohhh, ok, so if my metadata is equal to null in the pact log it means the interaction is not registered? :thinking_face: ``` "description": "a request for all clients", "providerState": "i have a list of clients", "request": { "method": "GET", "path": "/api/submissions?filter=[{year: 2000, \"countryCode\":\"PL\"}]"]", "headers": { "Accept": "application/json, text/plain, */*" } }, "response": { "status": 200, "headers": { }, "body": [ { "state": 9 } ] }, "metadata": null }```

tjones
2021-02-17 08:29
The request and the response are there

tjones
2021-02-17 08:30
you should see a line like: `Registered expected interaction GET /api/xxxxxx`

tjones
2021-02-17 08:30
Although, that path looks weird in your example

victoria.kruczek
2021-02-17 08:31
Oh ok, so my function in the unit tests section is not outputting anything, correct? And therefore it didn?t get logged by the pact?

tjones
2021-02-17 08:32
I?m not sure what you mean. Could you share your test code?

tjones
2021-02-17 08:33
Pact will log when it registers an interaction, when it receives the request from your consumer, and whether that request matched the registered interaction

victoria.kruczek
2021-02-17 08:34
``` it('empty array', async () => { Submission.getAll.mockImplementationOnce(() => Promise.resolve({ data: [], }), ); const result = await submissions.getAllSubmissions('123', 123, 2000, 'PL'); expect(result).toEqual([]); });```

tjones
2021-02-17 08:35
I don?t see where you?re setting up pact in that example

tjones
2021-02-17 08:35
usually in a pact consumer test, there wouldn?t be any mocks

tjones
2021-02-17 08:35
unless you have an unusual scenario

victoria.kruczek
2021-02-17 08:37
what that unusual scenario could be? Also, why wouldn?t be there any mocks? I think I might have missed something fundamental here

tjones
2021-02-17 08:37
In a pact test, pact does the mocking for you


tjones
2021-02-17 08:37
^ There are some diagrams here that might help

tjones
2021-02-17 08:37
This one in particular

tjones
2021-02-17 08:38
A pact consumer test will have your actual client code sending an actual request to the mock provider that Pact sets up for you.

victoria.kruczek
2021-02-17 08:40
ok, I have forgotten about that in the heat of trying to make it run. Let me approach this once more time, thank you a lot!

tjones
2021-02-17 08:40
You?re welcome. Good luck!

vikrant.sarkaniya
2021-02-17 08:41
Hi All, I am new to pact and contract testing, I want to create a consumer and provider test for my existing API's , Can anyone help me with how I could setup this?

tjones
2021-02-17 08:42
There are several examples in the repository here: https://github.com/pact-foundation/pact-js/tree/master/examples

tjones
2021-02-17 08:42
the e2e test is a good starting point - both the consumer and the provider are in the same project, but other than that it shows what a normal pact flow would look like

tjones
2021-02-17 08:43
If you are new to pact, I would start here: https://docs.pact.io/getting_started/how_pact_works

matt.fellows
2021-02-17 09:11
also howtolearn has a number of good tutorials/workshops

2021-02-17 09:11
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-02-17 09:12
also these (even simpler) starting points: https://docs.pactflow.io/docs/tutorials/

matt.fellows
2021-02-17 09:12
note to self: add these to OSS docs!

vikrant.sarkaniya
2021-02-17 09:41
I tried creating the Consumer test but getting below error:

vikrant.sarkaniya
2021-02-17 09:41
1) Favorites API test get favorites by filter: AssertionError: expected { Object (TargetId, Created, ...) } to deeply equal { Object (TargetId, Created, ...) } + expected - actual { - "Created": [undefined] - "TargetId": [undefined] - "TargetObjectType": [undefined] - "UserId": [undefined]

matt.fellows
2021-02-17 09:42
Hi Vikrant, worth also reading howtoask

2021-02-17 09:42
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help

matt.fellows
2021-02-17 09:43
it?s going to be hard for us to help you without the input code that?s getting us to that output

matt.fellows
2021-02-17 09:43
This looks like a non Pact assertion also (Jest? Mocha?)

matt.fellows
2021-02-17 09:44
So my guess is that your test is doing some assertions on the API response from the mock service, which is not configured to respond with the payload you want (hence the `undefined`

vikrant.sarkaniya
2021-02-17 09:52
:<//favorites.services.dev.corp.lego.com/api/v1>' }); describe('Favorites API test', () => { // (3) Setup Pact lifecycle hooks before(() => mockProvider.setup()); afterEach(() => mockProvider.verify()); after(() => mockProvider.finalize()); it('get favorites by filter', async () => { // (4) Arrange const expectedfavorites = {Result:[{ TargetId: '20da7438-1382-4b80-b447-6da61f34e719', Created:'2021-02-15T12:11:59+00:00', TargetObjectType: 'Application', UserId: 'b1a660d2-f23b-4f52-b04d-dc4bc8546e0e'}]}

vikrant.sarkaniya
2021-02-17 09:52
this Is what I wrote in my consumer.pact.js file

matt.fellows
2021-02-17 09:53
looks familiar :stuck_out_tongue:

matt.fellows
2021-02-17 11:24
you seemed to have truncated the file, so now it?s a little harder to debug for you

matt.fellows
2021-02-17 11:25
I?d recommend dumping the response body via a `console.log` in your api client class to see what structure is coming back - that will help

matt.fellows
2021-02-17 11:25
also `trace` level logging will print that out for you too

therimpact
2021-02-17 12:30
has joined #pact-js

amaljayaraj07
2021-02-17 13:13
Hello All, I have a question on how can we manage running the provider tests when we have a `term` matcher in the API path? the below is the sample interaction using `pact-js` ```const uuid = '497f6eca-6276-4993-bfeb-53cbbbba6f08' const interaction = new Interaction() .given('an asset exists') .uponReceiving('a request to return an asset') .withRequest({ method: 'GET', path: term({ generate: `/assets/${uuid}`, matcher: '/assets/[\\w]{8}(-[\\w]{4}){3}-[\\w]{12}', }), }) .willRespondWith({ status: 200, body: like({ id: uuid, name: 'foo-bar', }), }) await provider.addInteraction(interaction)``` For the above example how can we run the provider test and make it work? Does the provider always have to create an asset entry with the hardcoded `uuid` defined in the interaction? Or can we actually have a flexible way of using the provider state where any asset with an `uuid` is good enough in the provider database to pass the test?

christopher.roberts
2021-02-17 14:06
Has anyone seen the following issue? ``` FAIL test/src/Health.pact.test.js (157 s) Pact between soa_translate_service and soa_translate_service with 30000 ms timeout for Pact × encountered a declaration exception (2 ms) ? Pact between soa_translate_service and soa_translate_service ? with 30000 ms timeout for Pact ? encountered a declaration exception TypeError: Cannot read property 'logLevel' of undefined 6 | const { Matchers } = require("@pact-foundation/pact"); 7 | > 8 | pactWith( | ^ 9 | { 10 | consumer: process.env.CI_PROJECT_NAME, 11 | provider: process.env.CI_PROJECT_NAME, at new Pact (node_modules/@pact-foundation/pact/src/httpPact.ts:59:20) at setupProvider (node_modules/jest-pact/index.js:23:20) at Suite.<anonymous> (node_modules/jest-pact/index.js:57:15) at jestPactWrapper (node_modules/jest-pact/index.js:37:5) at Suite.<anonymous> (node_modules/jest-pact/index.js:64:67) at Object.<anonymous>.exports.pactWith (node_modules/jest-pact/index.js:64:12) at Object.<anonymous> (test/src/Health.pact.test.js:8:1) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 157.472 s Ran all test suites.``` I debugged it and the code is never initializing the "serviceFactory" variable in httpPact.ts. Does anyone know how this variable should be initialized?

brendan.donegan
2021-02-17 14:09
What you seem to want is fromProviderState, which is a new feature in Pact v3. I am also looking to use this and your use case seems to be identical


christopher.roberts
2021-02-17 14:13
I think it might have something to do with the fact that I'm loading this class as typescript instead of javascript

amaljayaraj07
2021-02-17 15:07
Yes, you are right, V3 feature should solve this. In my case my provider is going to use pact .net and as far I know the .net library is not catching up with v3. It will be nice to know if there are some other work arounds which could work without the v3 spec.

christopher.roberts
2021-02-17 15:26
related question: does jest-pact have a cache and if so how can I clear it?

brendan.donegan
2021-02-17 16:00
@amaljayaraj07oh? you know this channel is pact-js right :slightly_smiling_face: ?

brendan.donegan
2021-02-17 16:01
ah, the *provider* is pact .net

amaljayaraj07
2021-02-17 16:21
Yeah.. The provider is unfortunately .net :expressionless: so I am looking for common appproch.

brendan.donegan
2021-02-17 16:28
Pact v2 doesn?t support this concept at all unfortunately (afaik)

brendan.donegan
2021-02-17 16:29
one thing i would say is i don?t know if there?s actually a rule that says you need to do the Pact verification in the same language as the provider

amaljayaraj07
2021-02-17 16:42
Hmm.. That's interesting.. But if we want to setup provider states and if we don't use the same language/framework as the provider, one would have to do quite a bit of coding to write utility methods in the other language to create test data in the provider. Then the whole thing becomes way too complicated. But this is an interesting idea though :slightly_smiling_face:

brendan.donegan
2021-02-17 16:45
It?s certainly best practice to use the same language

andrzej.igielski
2021-02-17 21:41
has joined #pact-js

matt.fellows
2021-02-17 23:22
usually when you get a ?cannot read property ?xxx? of undefined? it means the underlying object/class instance has disappeared or not been initialised. But I don?t know Pact Jest well enough to have a stab at guessing why that might be the case

matt.fellows
2021-02-17 23:22
`logLevel` is something on the underlying Pact object, I?m guessing, so it perhaps wasn?t able to construct the Pact class properly

matt.fellows
2021-02-17 23:22
so when trying to set the log level, it failed

matt.fellows
2021-02-17 23:23
AH, I missed you last statement about `serviceFactory`

matt.fellows
2021-02-17 23:23
short answer from me is no

matt.fellows
2021-02-17 23:23
But @tjones or @yousafn might know

tjones
2021-02-17 23:35
This is a general pact-js problem- it happens when the mock server fails to start up. You probably have a log line further up telling you what went wrong. We should check this case and emit a more helpful error

tjones
2021-02-17 23:37
I?d be surprised if there?s a bug causing this- I?ll have a look at the code when I?m at my desk

christopher.roberts
2021-02-17 23:39
I figured it out. I had a jest moduleNameMapper regex in the wrong order :)

tjones
2021-02-18 01:30
Ah, right. Looking at the code, I guess you were accidentally stubbing pact-node

mikewagner21
2021-02-18 03:15
has joined #pact-js

tjones
2021-02-18 05:22
You could use the `providerStateChangeUrl` to do provider verification in a different language

tjones
2021-02-18 05:23
To do this, you need to spin up your provider with an extra endpoint that handles pact state information. You want to be able to only spin up this endpoint during provider verification

tjones
2021-02-18 05:26
If you are restricted to v2 pacts, an alternative approach is to use a specific example path (this is what I do). Eg, in your case, I would say something like: ``` const interaction = new Interaction() .given('asset "b6bf9b18-71a9-11eb-9439-0242ac130002" exists') .uponReceiving('a request to return an asset') .withRequest({ method: 'GET', path: '/assets/b6bf9b18-71a9-11eb-9439-0242ac130002', }) ```

tjones
2021-02-18 05:26
Remember that a contract isn?t the same as a spec - you don?t need to describe all possible responses.

tjones
2021-02-18 05:29
Good answers above, @brendan.donegan! :taco:

francis.lobo
2021-02-18 05:51
Hello folks I am new to Pact and Typescript/javascript I need some help with Pact JS.. Question in thread..

francis.lobo
2021-02-18 05:51
I am trying to generate contracts with the following pattern (stripped down code) ``` export interface SuccessResponse<T> extends BaseResponse { data: T; } export interface returnObj { id: number; name: string tags: { tagId: string; }[]; } const successResponse:SuccessResponse<returnObj> = { data:Matchers.eachLike( { id : Matchers.decimal, name : Matchers.string, tags: [] } ,{min : 0}) } ``` In the generated Pact, I only see matchers for the `tags` field. ``` "body": { "message": { "data": [ { "tags": [ ], } ] } } "matchingRules": { "$.body.message.data": { "min": 1 }, "$.body.message.data[*].*": { "match": "type" }, }``` I am a bit stuck on how to get the matchers for all the other fields.. When using Pact JVM, I tried something like ```DslPart body = new PactDslJsonBody(); body.minArrayLike("data", 1) .stringType("id") .stringType("name") .....``` and I see all the necessary json fields and matchers in the PACT file What am I missing in Pact-JS?

matt.fellows
2021-02-18 05:55
`Matchers.decimal` is a function, not a value

matt.fellows
2021-02-18 05:56
so the value of `id` is literally a JS function, which is not going to be serialisable

matt.fellows
2021-02-18 05:56
so the fix should be easy

matt.fellows
2021-02-18 05:56
```id: Matchers.decimal(42.0)```

matt.fellows
2021-02-18 05:56
```name: Matchers.string("example string")```

matt.fellows
2021-02-18 06:10
that help?

tjones
2021-02-18 07:21
This is a common question, so I?ve opened https://github.com/pact-foundation/pact-js/issues/611 to make the tooling more helpful

vikrant.sarkaniya
2021-02-18 07:41
I was able to successfully run the consumer test But I am stuck with the provider test now.

vikrant.sarkaniya
2021-02-18 07:41
I want to run my actual API against the pact created by consumer test

vikrant.sarkaniya
2021-02-18 07:42
and the API call takes authorization token from another endpoint


khandelwalbhushan
2021-02-18 08:10
has joined #pact-js

matt.fellows
2021-02-18 08:10
You have a few choices in Pact JS 1. Remove auth from the provider pact test context 2. Stub authorization in your API verification (what I normally do, because it?s an external system, and I don?t want a dependency on that in my unit tests) 3. Use request filters, to dynamically replace the credentials with real ones (this is OK if the auth is internal to the service, but generally not a good idea for externalised auth)

aniket.agarwal
2021-02-18 09:21
has joined #pact-js

brendan.donegan
2021-02-18 09:32
ah darn, i just ate breakfast :smile:

brendan.donegan
2021-02-18 09:33
_puts taco aside for lunch_

arpit.modani
2021-02-18 09:43
has joined #pact-js

byronth
2021-02-18 11:45
has joined #pact-js

victoria.kruczek
2021-02-18 14:51
Hello! I?m writing because I?ve encountered an issue with CORS when creating a consumer pact. I?m applying Pact?s to a mobile app and cors is preventing me from properly hitting the desired GET request: ``` Missing requests: GET /api/submissions Unexpected requests: OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]&``` I?m using pact-jest and I?ve setup a `cors: false` parameter, although it didn?t help. We also have some of the ports whitelisted, so they in theory don?t use the cors, but they didn?t do trick either. Here is the log from Pact: ```I, [2021-02-18T15:44:48.700696 #33601] INFO -- : Received request OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& D, [2021-02-18T15:44:48.700850 #33601] DEBUG -- : { "path": "/api/submissions", "query": "filter=[%7B%22id%22:13548%7D]&", "method": "options", "headers": { "Origin": "http://localhost", "Access-Control-Request-Method": "GET", "Access-Control-Request-Headers": "Authorization", "User-Agent": "Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/16.2.2", "Host": "localhost:1234", "Connection": "keep-alive", "Version": "HTTP/1.1" } } E, [2021-02-18T15:44:48.701346 #33601] ERROR -- : No matching interaction found for OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& E, [2021-02-18T15:44:48.701428 #33601] ERROR -- : Interaction diffs for that route: E, [2021-02-18T15:44:48.701448 #33601] ERROR -- : W, [2021-02-18T15:44:48.718456 #33601] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api/submissions Unexpected requests: OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& W, [2021-02-18T15:44:48.718517 #33601] WARN -- : Missing requests: GET /api/submissions Unexpected requests: OPTIONS /api/submissions?filter=[%7B%22id%22:13548%7D]& I, [2021-02-18T15:44:48.733870 #33601] INFO -- : Cleared interactions``` Any tips/trick how to deal with this? :thinking_face:

tjones
2021-02-18 16:18
You probably want `cors: true`. It looks like your client is sending the cors requests, but the mock server is not expecting them. Also, it looks like your request is sending a query, but the interaction isn?t expecting it

francis.lobo
2021-02-18 20:20
Thanks heaps for the reply @matt.fellows That worked! Now I can see the correct matchers in my pact file :slightly_smiling_face:

isa.levine
2021-02-18 23:37
has joined #pact-js

victoria.kruczek
2021-02-19 08:50
@tjones Do you mean the `filter=[%7B%22id%22:13548%7D]&` query? It?s added automatically when fetching the CORS. It?s also added now to the GET request (after setting `cors: true`), not sure why. The api/submissions doesn?t accept such query :thinking_face: I?m totally lost here

tjones
2021-02-19 09:13
CORS is an http thing, usually handled by the http library/ server/ api gateway. It usually isn?t explicit in the server code (maybe in the config). Wikipedia has some fairly clear explanations if you want to learn more.

victoria.kruczek
2021-02-19 09:14
Ok, I will dig into, thank you :slightly_smiling_face:

victoria.kruczek
2021-02-19 09:18
I also found this: https://github.com/pact-foundation/pact-mock_service/wiki/Using-the-mock-service-with-CORS, sorry that I bothered you when it?s out there :facepalm: It was in a heat of the moment, have to admit that :sweat_smile:

brian.pfretzschner
2021-02-19 10:15
has joined #pact-js

neild
2021-02-19 14:34
I?m not able to modify `req.query` in the `requestFilter` function I?ve defined in my provider verification tests. Is this expected behavior or a bug? Ex/ ```const opts = { ...options requestFilter: async (req, res, next) => { req.query.foo = 'bar'; next(); }, } const verifier = new Verifier(opts)``` ```// middleware app.use((req, res, next) => { console.log('FOO', req.query.foo); // undefined next(); });``` If this is a bug, will open an issue in github with a reproducible demo. Wanted to confirm here whether this is a bug or not before I do that.

brendan.donegan
2021-02-19 14:47
i think this is a feature, based on the behavior in pact-jvm

neild
2021-02-19 21:33
Will look at the pact-jvm docs. Thank you!

sagupta
2021-02-19 21:53
Hello ppl, I am setting up a test for consumer and i use jest to run the tests. I have added `"@pact-foundation/pact": "^9.15.0"` dependency . I am however getting this error when running the test . Am i missing some configuration to set in jest ? ```SyntaxError: /Users/<>/<>/graphql/package.json: Unexpected token, expected ";" (2:11) 1 | { > 2 | "private": true, | ^ 3 | "name": "graphql", 4 | "version": "0.0.0", 5 | "author": "<>", at Parser._raise (node_modules/@babel/parser/src/parser/location.js:241:45) at Parser.raiseWithData (node_modules/@babel/parser/src/parser/location.js:236:17) at Parser.raise (node_modules/@babel/parser/src/parser/location.js:220:17) at Parser.unexpected (node_modules/@babel/parser/src/parser/util.js:149:16) at Parser.semicolon (node_modules/@babel/parser/src/parser/util.js:122:40)```

matt.fellows
2021-02-19 22:08
I saw this recently actually, there's a problem with the jest/babel setup. Remove plugins until you work out which one

matt.fellows
2021-02-19 22:08
I'd like to get to the bottom of it, please share which one as it might be something we can guard against

sagupta
2021-02-19 22:15
I only have one plugin , this is what the `babel.config.js` looks ```module.exports = { presets: [ [ '@babel/env', { targets: { node: 'current', }, }, ], ], plugins: [ '@babel/plugin-proposal-optional-chaining', ], };```

sagupta
2021-02-19 22:16
and this is my `jest.config.js` ```module.exports = { collectCoverageFrom: ["packages/*/src/**/*.js"], coverageDirectory: "test-results/jest/coverage", reporters: [ "default", ["jest-junit", { outputDirectory: "test-results/jest" }], ], restoreMocks: true, setupFiles: ["<rootDir>/jest.setup.js"], testEnvironment: "node", transform: { "^.+\\.gql$": "<rootDir>/transform-gql.js", ".*": "babel-jest", }, runner: "groups", };```

sagupta
2021-02-19 22:18
removing that plugin doesnt solve it

matt.fellows
2021-02-19 22:22
Look at the transform regex, it's going to transform all files

matt.fellows
2021-02-19 22:22
That would include JSON which seems unlikely what you want

matt.fellows
2021-02-19 22:26
There may be an issue with it. It theory you should be able to modify anything but I think it actually only allows headers. There is definitely a known issue with body

sagupta
2021-02-19 22:26
I added this to ignore package.json ```transformIgnorePatterns: ['package.json'],```

sagupta
2021-02-19 22:27
When i run the tests now , I get this error ```Test suite failed to run SyntaxError: Unexpected token ; in JSON at position 12 at JSON.parse (<anonymous>) at Runtime._loadModule (node_modules/jest-runtime/build/index.js:568:59) at Object.<anonymous> (node_modules/psl/index.js:14:19) at Object.<anonymous> (node_modules/request/node_modules/tough-cookie/lib/pubsuffix-psl.js:32:11)```

matt.fellows
2021-02-19 22:35
I can't you this way I'm afraid, there are just too many variables that I can't guess in advance

matt.fellows
2021-02-19 22:35
You're going to need to create a minimal project and go from there

matt.fellows
2021-02-19 22:35
I've just found the comms I had with anither customer that had the issue. It was the transform picking up too many files

matt.fellows
2021-02-19 22:36
So ignoring just package.json may not be enough

matt.fellows
2021-02-19 22:36
You should make sure it only transforms JS files

tjones
2021-02-20 02:29
I agree, this looks like a babel/jest configuration issue rather than a pact issue.

tjones
2021-02-20 02:30
Are you using a particular pact example as a base? Perhaps we have the wrong settings in it

chitra.adikesavan
2021-02-20 15:50
has joined #pact-js

andrzej.igielski
2021-02-20 19:28
@andrzej.igielski has left the channel

francis.lobo
2021-02-21 23:56
Hello folks! A quick question on the roadmap. Is there an ETA for Pact V3 support on Pact JS? I understand it is on beta on a feature flag now. is there any plan to get it on master?

tjones
2021-02-21 23:57
We?re talking about that at the moment. No specific ETA, I am afraid.

francis.lobo
2021-02-21 23:57
Thanks for the update @tjones :slightly_smiling_face:

tjones
2021-02-22 00:00
We are *extremely* keen to get V3 support in to master. I?d ideally like to do it with as few breaking changes as possible.

artur
2021-02-22 03:57
@francis.lobo we are using the beta for https://github.com/owncloud/owncloud-sdk it mostly works pretty well

francis.lobo
2021-02-22 04:39
That sounds good :slightly_smiling_face: Waiting for it

francis.lobo
2021-02-22 04:41
Following up on that, If I have some consumer tests coming from Pact JVM with PactV3 and some from Pact JS and my Provider tests are in Pact JVM Do you foresee any issues with such a setup?

francis.lobo
2021-02-22 04:41
Thanks for the info @artur :+1:

tjones
2021-02-22 04:42
No, that should be fine :+1:

francis.lobo
2021-02-22 04:42
Sweet! thanks @tjones

tjones
2021-02-22 04:43
To confirm, you have: V2 pacts from pact-js V3 pacts from pact-jvm V2+3 verification in pact-jvm ?

francis.lobo
2021-02-22 04:47
Yes that's where we are moving. right now we have everything in JVM, adding a JS consumer

tausif2909
2021-02-22 06:13
Hi, How to pass value for `pathFromProviderSide` in nodeJS code in provider verification code? Can anyone share the example?

ankita.soni
2021-02-22 07:26
has joined #pact-js

jacek.helper
2021-02-22 08:03
has joined #pact-js

sagupta
2021-02-22 08:12
alright, i can check today with one of the devs about the transform. Will keep you posted here if that solves it

sagupta
2021-02-22 08:42
the problem was indeed with transform in `jest.config.js` Changing transform to ```transform: { '^.+\\.gql$': '<rootDir>/transform-gql.js', '^.+\\.(js|jsx)$': 'babel-jest', },``` did the trick :slightly_smiling_face: :thumbsup:

matt.fellows
2021-02-22 09:01
Thanks for confirming!

seanw122
2021-02-22 15:36
has joined #pact-js

akennedy
2021-02-22 15:54
has joined #pact-js

esimpson
2021-02-22 16:42
has joined #pact-js

neild
2021-02-22 17:02
I see. Thank you for the response. I figured out a workaround

dagrawal
2021-02-22 17:24
has joined #pact-js

venkata.pro
2021-02-22 21:47
has joined #pact-js

matt.fellows
2021-02-22 22:55
What did you do?

ashish.joshi
2021-02-23 00:32
Hey @matt.fellows Able to resolve authorization issues, but still stuck with second half, We tried to use `nock` but failed while testing locally, since my docker-run and test-run are different process and `nock` does not work on different process. Can you share me some JS example which you mentioned you have worked on before with this type of situation where before verifying the pact the provider service communicate with other service to get some data which is essential for response to consumer request(triggered from mock server).

matt.fellows
2021-02-23 00:37
is your provider running in docker? If so, you?re going to need to find a way to stub out the downstream endpoints for docke

matt.fellows
2021-02-23 00:38
one option is to use tools like docker compose, that startup sidecar services for each backend service with stub APIs. I usually configured endpoitns through environment variables, so this means you can replace downstream systems without actually changing any provider code

ashish.joshi
2021-02-23 00:47
Because i don't want to complicate things, since i have 5-6 other services which my provider will communicate before responding back to consumer's request and i have to run 5-6 docker images while running this test. is there any other option, like will `pact-stub-server` work in this case?

matt.fellows
2021-02-23 00:48
You could run the stub server, of course

matt.fellows
2021-02-23 00:50
You can?t stub the provider endpoints from the outside using your test code that doesn?t have access to it.

matt.fellows
2021-02-23 00:51
so you only have a few options: 1. Update your setup such that the provider doesn?t talk to real endpoints (e.g. stub server) 2. Update the provider code that runs in that docker container, stubbing out with code the endpoints

ashish.joshi
2021-02-23 00:54
Ok we'll try option 1 for now, do you have any real time example of using `stub-server` i tried to find it, but just got the documentations on commands to use it not a real time implementation.

matt.fellows
2021-02-23 00:55
I?m not sure what you mean, sorry?

ashish.joshi
2021-02-23 00:57
Sorry, my bad i didn't explain it properly. Do you have any real life example of using `pact-stub-server` like how we have pact-js workshop examples?

francislainy.campos
2021-02-23 08:52
Hi, good morning. I?m getting this error here trying to implement pact and jest and I?m not sure what I could be doing wrong. `Cannot read property 'addInteraction' of undefined`

francislainy.campos
2021-02-23 08:53
```import { Pact } from '@pact-foundation/pact'; import path from 'path'; import { getOwners } from '../../apis/ids'; describe('Clients Service', () => { const provider = new Pact({ consumer: 'FrontendWebsite', provider: 'ProductService', log: path.resolve(process.cwd(), 'logs', 'pact.log'), logLevel: 'warn', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, { firstName: 'Wonder', lastName: 'Woman', age: 30, id: 2, }, { firstName: 'Homer', lastName: 'Simpson', age: 39, id: 3, }, ]; afterEach(() => provider.verify()); describe('GET Clients', () => { beforeEach(() => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/view/states', headers: { Accept: 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; return provider.addInteraction(interaction); }); test('returns correct body, header and statusCode', async () => { const response = await getOwners(); expect(response.headers['content-type']).toBe( 'application/json; charset=utf-8', ); expect(response.data).toEqual(GET_EXPECTED_BODY); expect(response.status).toEqual(200); }); }); });```

francislainy.campos
2021-02-23 08:54
```export const getOwners = async () => { return Promise.resolve({ json: () => Promise.resolve(mockOwners), }); };```

francislainy.campos
2021-02-23 08:54
Many thanks.

brendan.donegan
2021-02-23 09:11
@francislainy.campos we have a template for Jest Pact in the Lift codebase, you can use that

francislainy.campos
2021-02-23 09:12
Thanks Brendan, that one does not allow me to run the tests individually through the IntelliJ run button.

brendan.donegan
2021-02-23 09:13
For the benefit of the group, it looks like this: ```import { Matchers } from '@pact-foundation/pact'; import { pactWith } from 'jest-pact'; ... (import your API code and set up any other data) pactWith( { consumer: '<your consumer>', provider: '<your provider>', cors: true, pactfileWriteMode: 'merge', }, provider => { describe('The query you are making', () => { beforeEach(() => { await provider.addInteraction( // You should pass an object describing the expected request and response per the Pact JS documentation ); }); it('returns the correct response', async () => { // call your API and get the response // provider.mockService.baseUrl contains the hostname and // port the mock provider is running on // // assert some things about the response }); }); }, );```

francislainy.campos
2021-02-23 09:14
I?d like to be able to do this

brendan.donegan
2021-02-23 09:15
I think the way jest-pact works may break the Jest plugin for Intellij

brendan.donegan
2021-02-23 09:15
If you really want to use it you may have to use raw jest

brendan.donegan
2021-02-23 09:15
ahh, you aren?t using jest-pact, gotcha

brendan.donegan
2021-02-23 09:16
I didn?t notice that

francislainy.campos
2021-02-23 09:18
Yes, I?m trying to make this piece work, which I found on a tutorial on the internet, as this one would allow me to run the tests individually this way.

brendan.donegan
2021-02-23 09:19
I think the issue is you created the provider inside the other describe block

francislainy.campos
2021-02-23 09:20
I tried variations of this

francislainy.campos
2021-02-23 09:20
```import { Pact } from '@pact-foundation/pact'; import path from 'path'; import { getOwners } from '../../apis/ids'; const provider = new Pact({ consumer: 'FrontendWebsite', provider: 'ProductService', log: path.resolve(process.cwd(), 'logs', 'pact.log'), logLevel: 'warn', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, }); describe('Clients Service', () => { const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, { firstName: 'Wonder', lastName: 'Woman', age: 30, id: 2, }, { firstName: 'Homer', lastName: 'Simpson', age: 39, id: 3, }, ]; afterEach(() => provider.verify()); describe('GET Clients', () => { beforeEach(() => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/', headers: { Accept: 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; return provider.addInteraction(interaction); }); test('returns correct body, header and statusCode', async () => { const response = await getOwners(); expect(response.headers['content-type']).toBe( 'application/json; charset=utf-8', ); expect(response.data).toEqual(GET_EXPECTED_BODY); expect(response.status).toEqual(200); }); }); });```

brendan.donegan
2021-02-23 09:20
Personally I think the amount of extra code and possibility for mistakes with raw jest is not worth being able to run it through the UI, but lets see if we can make it work

francislainy.campos
2021-02-23 09:21
Thanks

brendan.donegan
2021-02-23 09:21
Let me see if I can dig something out. There?s also the issue that there are Promises involved here

brendan.donegan
2021-02-23 09:22
you?ll notice in my example, addInteraction is await?ed

francislainy.campos
2021-02-23 09:22
I used the mock promise just to try to see if it would make any difference this way

francislainy.campos
2021-02-23 09:22
But we?ll be using calls of this type instead

francislainy.campos
2021-02-23 09:22
```export const getStudents = async ({ schoolId }) => { const url = `${config.idsBaseUri}/ids/v1/schools/${schoolId}/students`; return fetch(url, { headers, }); };```

francislainy.campos
2021-02-23 09:24
Yeah, I tried to implement that but got lost on the syntax for this on my code since the interaction is being added and returned at the same time.


francislainy.campos
2021-02-23 09:25
This is where I?m getting the sample from

brendan.donegan
2021-02-23 09:29
okay, i remember now

brendan.donegan
2021-02-23 09:29
unfortunately that example is completely wrong

francislainy.campos
2021-02-23 10:06
Changed it a bit and removed the mocking api to use the real server call and I think it?s a bit closer now but with a different error, probably something on the path for the request, which I?m trying to figure out what would be the correct one here. ```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll((done) => { provider.setup().then(() => done()); }); afterAll((done) => { provider.finalize().then(() => done()); }); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/', headers: { Accept: 'application/json, text/plain, */*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.headers['content-type']).toBe( 'application/json; charset=utf-8', ); expect(response.data).toEqual(GET_EXPECTED_BODY); expect(response.status).toEqual(200); }); });```

matt.fellows
2021-02-23 10:15
In that last error you show, it is complaining about a ?local issuer certificate?

matt.fellows
2021-02-23 10:16
that would indicate you?re trying to talk to an https service somewhere - have you modified your provider to not talk https, and instead just talk to the mock service?

matt.fellows
2021-02-23 10:16
That could explain both a) why the ?missing request? is there and b) why that error is shown (i.e. you?re code is trying to talk to another place, over https)

brendan.donegan
2021-02-23 10:16
:point_up:

francislainy.campos
2021-02-23 10:16
Hi Matt, I haven?t changed my provider no, it?s the same our application talks to but we don?t own the code for it.

matt.fellows
2021-02-23 10:17
not the provider, but the api client that talks to the provider

matt.fellows
2021-02-23 10:17
(or would to, in a non-pact context)

francislainy.campos
2021-02-23 10:17
```export const getStates = async () => { const url = `${config.idsBaseUri}/ids/v1/states`; return fetch(url, { headers, }); };```

matt.fellows
2021-02-23 10:17
in your code, that is whatever `getStates()` is

brendan.donegan
2021-02-23 10:17
@francislainy.campos the function getStates doesn?t send the request to the mock provider

matt.fellows
2021-02-23 10:18
right, so `config.idsBaseUri` needs to be configurable, and needs to be configured to talk to the mock provider from Pact

brendan.donegan
2021-02-23 10:18
it?s sending it to IDS

brendan.donegan
2021-02-23 10:18
(IDS is one of our providers)

matt.fellows
2021-02-23 10:18
``` beforeAll((done) => { provider.setup().then((config) => /* config contains the details of the dynamic mock service, use this to configure the api client */); });```

matt.fellows
2021-02-23 10:19
also, you don?t need done anymore

brendan.donegan
2021-02-23 10:19
@matt.fellows yeah, can you advice on using done :smile: I found it was necessary last year

matt.fellows
2021-02-23 10:20
``` afterAll((done) => { provider.finalize().then(() => done()); }); can be simply: afterAll(() => provider.finalize());```

brendan.donegan
2021-02-23 10:20
oh that?s good, makes it much simpler

brendan.donegan
2021-02-23 10:20
tbh we switched most of our tests to jest-pact and don?t need to worry about any of that :smile:

matt.fellows
2021-02-23 10:20
done is the pre-promise way of saying ?this future thing has finished?. Lots of frameworks still have it for portability

matt.fellows
2021-02-23 10:20
yeah, people keep telling me it?s good :stuck_out_tongue:

francislainy.campos
2021-02-23 11:02
Thank you both. It?s working now.

francislainy.campos
2021-02-23 11:02
```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', port: 3000, }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll((done) => { provider.setup().then((opts) => { process.env.API_PORT = opts.port; done(); }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/ids/v1/states', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.status).toEqual(200); }); });```

francislainy.campos
2021-02-23 11:02
```export const getStates = async () => { const url = `http://localhost:3000/ids/v1/states`; return fetch(url, { headers, }); };```

francislainy.campos
2021-02-23 11:03
I needed to keep `done` on the beforeAll and beforeEach pieces as without it I get that same interaction error as I was initially getting.

matt.fellows
2021-02-23 11:30
``` beforeAll(() => { return provider.setup().then((opts) => { process.env.API_PORT = opts.port; }); });```

matt.fellows
2021-02-23 11:30
that should work just fine

matt.fellows
2021-02-23 11:31
Also, you?ve currently got a hard coded port in Pact anyway (`3000`) so you don?t even need to do it this way. But I?d suggest keeping the dynamic configuration, and dropping the hard coded `port` from your Pact config so Pact will always find an available port - this is helpful on CI, but also locally if you have other things running on that port

matt.fellows
2021-02-23 11:32
glad to hear it?s going!

matt.fellows
2021-02-23 11:33
I don?t have a real life example, but what do you actually want to see in it?

matt.fellows
2021-02-23 11:34
it takes one or more Pact files and becomes a server. You can run it in docker also

francislainy.campos
2021-02-23 11:40
Thanks. Yes, the version of the beforeAll you provided with the return piece works removes the add interaction error. However, I think I may have spoken too soon because I?m now getting a timeout error on my request and the contract is not generating although I don?t remember changing anything else there. If I remove the hardcoded port for the provider piece I then get a 500 instead talking about missing requests.

francislainy.campos
2021-02-23 11:41
```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll((done) => { provider.setup().then((opts) => { process.env.API_PORT = opts.port; done(); }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/ids/v1/states', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.status).toEqual(200); }); });```

francislainy.campos
2021-02-23 11:41
```export const getStates = async () => { const url = `http://localhost:3000/ids/v1/states`; return fetch(url, { headers, }); };```

matt.fellows
2021-02-23 11:42
you didn?t copy my code correctly!

matt.fellows
2021-02-23 11:43
look carefully - because it?s the _most common_ mistake I see people make with javascript and promises

francislainy.campos
2021-02-23 11:43
Owh sorry, no, I pasted the wrong version here

matt.fellows
2021-02-23 11:43
it?s the cause of the timeout, almost certainly

francislainy.campos
2021-02-23 11:43
```import * as Pact from '@pact-foundation/pact'; import path from 'path'; import { getStates } from '../../apis/ids'; describe('Growth Report', () => { const provider = new Pact.Pact({ cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'Ed UI', provider: 'Wormhole', host: 'localhost', }); const GET_EXPECTED_BODY = [ { firstName: 'Lisa', lastName: 'Simpson', age: 8, id: 1, }, ]; beforeAll(() => { return provider.setup().then((opts) => { process.env.API_PORT = opts.port; }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); beforeEach((done) => { const interaction = { state: 'i have a list of clients', uponReceiving: 'a request for all clients', withRequest: { method: 'GET', path: '/ids/v1/states', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('returns correct body, header and statusCode', async () => { const response = await getStates(); expect(response.status).toEqual(200); }); });```

francislainy.campos
2021-02-23 11:43
This is what I have with the version copied from here.

matt.fellows
2021-02-23 11:43
ok! yes that looks better.

matt.fellows
2021-02-23 11:44
what?s the timeout set to? It could legitimately be taking too long

francislainy.campos
2021-02-23 11:44
It?s localhost though, so why it would take this long?

francislainy.campos
2021-02-23 11:47
But now the error that is coming up the most is the 500 one, with the missing requests.

tjones
2021-02-23 11:48
@brendan.donegan : just catching up on the thread- you mentioned jest-pact breaks a jest IntelliJ plug-in - can you tell me more about this? Maybe we can fix it

francislainy.campos
2021-02-23 11:48
It?s happening regardless of whether I hardcode the port on the provider piece or not.

tjones
2021-02-23 11:48
Also @matt.fellows@matt.fellows@matt.fellows : I want to bring `pactWith` to mocha - maybe next week :)

tjones
2021-02-23 11:49
Also coming this week- `messagePactWith`

francislainy.campos
2021-02-23 11:49
Hi Tim, I think perhaps what Brendan meant was that with the jest-plugin is not possible to use the run button from intellij to run the tests individually.

francislainy.campos
2021-02-23 11:50
That being the reason why I?m trying to refactor our tests and have them work using jest only so I can make use of this functionality.

brendan.donegan
2021-02-23 11:51
@tjones by the way I think you tried to follow up with me about jest-pact with v3, but i can?t find the message now?

tjones
2021-02-23 11:51
There?s a beta version to match

tjones
2021-02-23 11:51
I?ll link you, hold on

brendan.donegan
2021-02-23 11:51
yeah i tried it, and it works

tjones
2021-02-23 11:52
Oh! Awesome, yes. Sorry, I didn?t realise that was you :joy:

tjones
2021-02-23 11:52
Any pain points?

tjones
2021-02-23 11:52
I?m thinking of making it 1.0.0 soon, with a firmer interface.

tjones
2021-02-23 11:53
(since technically anything under 1 can be a breaking change with no notice)

tjones
2021-02-23 11:54
Also, it sounds like you have a lot of specs - I?d be really interested in whether you have any thoughts on this: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-02-23 11:55
(even if those thoughts are ?I wouldn?t use it?)

brendan.donegan
2021-02-23 11:55
yeah, i meant to respond to that. it would be really good for us

tjones
2021-02-23 11:55
Awesome!

francislainy.campos
2021-02-23 11:55
The url looks fine so I?m not sure what could be wrong @matt.fellows?

brendan.donegan
2021-02-23 11:55
it might become slightly less useful soon since we could potentially split our application into multiple consumers :smile:

tjones
2021-02-23 11:55
When we have this, it?ll be easier to do a module that can be given to the `globalSetup` for jest

brendan.donegan
2021-02-23 11:56
but that?s fine

tjones
2021-02-23 11:56
which could clear out your pact directory

tjones
2021-02-23 11:56
At the moment, with jest you have to use `update`, which means that removing interactions doesn?t remove them from your pact file

tjones
2021-02-23 11:57
unless you?re clearing it before each test run (but I suspect most people aren?t, because none of the examples do)

tjones
2021-02-23 11:57
Do you know what it is about jest-pact that causes this?

brendan.donegan
2021-02-23 11:59
i?m really looking forward to jest-pact being released with a stable contract though as i want to switch us over but i?m reluctant to do so if it means refactoring things more than once

brendan.donegan
2021-02-23 11:59
(switch us over to v3)

tjones
2021-02-23 12:01
Have a look in the body. A 500 internal server error is how the mock server tells you that it didn?t receive the interaction you promised

tjones
2021-02-23 12:01
The detailed information will be in the pact log

brendan.donegan
2021-02-23 12:02
@francislainy.campos you?re not using the generated port in the request

tjones
2021-02-23 12:03
Yeah. I think we?ll end up with a different API to the current V3 branch, because I?d like the upgrade pathway from v2 to be very straightforward. But I also don?t want to break things for the current users of the beta.

tjones
2021-02-23 12:03
I?ll be focussing on that a bit next week.

brendan.donegan
2021-02-23 12:03
i was going to say, it would be great if the upgrade path was a bit simpler

brendan.donegan
2021-02-23 12:04
obviously it?s worth breaking the contract to make things better while you have the chance though

tjones
2021-02-23 12:04
Yeah. Some things will naturally change.

tjones
2021-02-23 12:04
It?s also an opportunity to clean up some of the other breaking things that aren?t worth releasing on their own

tjones
2021-02-23 12:05
We can do better typescript types for pact interactions, for example

francislainy.campos
2021-02-23 12:05
Sorry, not really. Just something that I noticed and the reason why I?m trying to move away from it to use the raw jest instead.

tjones
2021-02-23 12:05
there?s a lot of `any` in the api surface that could be narrower

francislainy.campos
2021-02-23 12:05
```I, [2021-02-23T12:03:58.387834 #12739] INFO -- : Registered expected interaction GET /ids/v1/states D, [2021-02-23T12:03:58.387984 #12739] DEBUG -- : { "description": "a request for all clients", "providerState": "i have a list of clients", "request": { "method": "GET", "path": "/ids/v1/states", "headers": { "Accept": "*/*" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": [ { "firstName": "Lisa", "lastName": "Simpson", "age": 8, "id": 1 } ] }, "metadata": null } W, [2021-02-23T12:03:58.445679 #12739] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /ids/v1/states W, [2021-02-23T12:03:58.445727 #12739] WARN -- : Missing requests: GET /ids/v1/states I, [2021-02-23T12:03:58.474092 #12739] INFO -- : Cleared interactions```

francislainy.campos
2021-02-23 12:06
This is the whole log

tjones
2021-02-23 12:06
but introducing types where previously there weren?t will be a breaking change for typescript users

tjones
2021-02-23 12:06
Ok. What plugin are you using? I?ll try to reproduce this when I get a chance.

matt.fellows
2021-02-23 12:07
Pretty cut and dry. Your code is not calling the endpoint

matt.fellows
2021-02-23 12:08
Yep, I was just in there before to make a small change

matt.fellows
2021-02-23 12:08
The core native module (currently Rust) doesn?t have types eminating from it, so we?ll need to find a way to add types to that too

matt.fellows
2021-02-23 12:08
more types, is on the whole a good thing though

tjones
2021-02-23 12:09
For that, I think we can just do `.d.ts` files. I?ve done a couple of those recently for other reasons.

matt.fellows
2021-02-23 12:09
yep

tjones
2021-02-23 12:09
(we?re now off the original topic, though)

matt.fellows
2021-02-23 12:10
yes, I?ll exit the thread (I need to sleep I think)(

tjones
2021-02-23 12:11
Note that if you?re using raw jest you?ll need to provide different log file names for each `Pact` instance, otherwise they will clobber each other.

brendan.donegan
2021-02-23 12:18
sorry, i know it?s late for you guys, but one quick question. if i have a provider that is using v3 for verification, will it be able to verify v2 contracts?

matt.fellows
2021-02-23 12:19
yes. The verification process reads the contract, determines the spec, and tests that way

francislainy.campos
2021-02-23 12:30
I don?t use any plugin directly, just out of the box intellij ultimate run configuration for jest.

francislainy.campos
2021-02-23 12:33
Sorry @matt.fellows, for needing a bit of hand holding here but I?m not sure what to do next to have this amended.

francislainy.campos
2021-02-23 13:05
When I right click on any jest test or describe intellij shows me the option to run then, but not for the ones done using jest-pact.

tausif2909
2021-02-23 13:12
I have the call at consumer side `api/assets/{assetId}` where `assetId` is dynamic will be passed from provider side, How do I pass `{assetId}` value from provider side in `nodeJS` project.? can someone share the example ?

tausif2909
2021-02-23 13:16
``` @State("There is a request to get the asset metadata") public HashMap<String, Object> testAssetMetadata() { HashMap<String, Object> map = new HashMap<>(); map.put("assetId", mediaAssetId); return map; }``` I was able to achieve this using hashmap in provider state in `pact-jvm` but not sure how to do the same in `pactJS`

francislainy.campos
2021-02-23 15:10
It?s working now, thanks. We were missing sending the url inside the getStates call

francislainy.campos
2021-02-23 15:10
```test('returns correct body, header and statusCode', async () => { const response = await getStates( `http://localhost:${process.env.API_PORT}/ids/v1/states`, ); expect(response.status).toEqual(200); });```

francislainy.campos
2021-02-23 15:11
```export const getStates = async (url) => { return fetch(url, { headers, }); };```

francislainy.campos
2021-02-23 15:12
Thanks for your guys help. :)

tjones
2021-02-23 15:40
I?ve released `jest-pact` 0.8.3, which now includes `messagePactWith` and also adds `pactWith.only` / `pactWith.skip` (alongside the already existing `fpactWith` and `xpactWith`)

tjones
2021-02-23 15:43
Also, npm says that jest-pact was downloaded 40,341 times in the last week - which is roughly four times a minute. That?s pretty cool.

tjones
2021-02-23 15:48
At the moment, pact-js doesn?t support provider side parameters. We?re working on the next version which will- you can try the beta by following the instructions here: https://github.com/pact-foundation/pact-js#pact-js-v3

tjones
2021-02-23 15:51
Ah. I wonder if that?s because `pactWith` doesn?t look like a `describe` to the plugin. What happens if you wrap the `pactWith` call in a describe? ```describe("pact",() => { pactWith(..... , (provider) =>{....}) })```

francislainy.campos
2021-02-23 15:58
That?s a good idea and it may work with some more thought but I tried it here now quickly and I did get the run button but then a message No tests found once it tried to run the tests.

tjones
2021-02-23 16:04
Hm. That?s very weird. I?ll have to see if I can reproduce it with the CE version (I don?t have Ultimate)

francislainy.campos
2021-02-23 16:05
I?m not sure you can use CE for that, but maybe the trial version for ultimate or webstorm may do?

tjones
2021-02-23 16:08
Glad you got it working! It?s a good idea to only inject the baseURL into the test, otherwise you might not be testing the endpoint that you actually hit in production: ```export const getStates = async (baseUrl) => { return fetch(`${baseUrl}/ids/v1/states`, { headers, }); };``` then in your test: ```test('returns correct body, header and statusCode', async () => { const response = await getStates( `http://localhost:${process.env.API_PORT}`, ); expect(response.status).toEqual(200); });```

tjones
2021-02-23 16:09
you can also do `provider.mockService.baseUrl`: ```test('returns correct body, header and statusCode', async () => { const response = await getStates( provider.mockService.baseUrl ); expect(response.status).toEqual(200); });```

patrick.hendron
2021-02-23 18:38
Hey guys, wondering if someone can expalin this error in a bit more detail https://github.com/pact-foundation/pact-node/blob/b0765b067b354df5e41e9c5f37f3fa69e8d84738/src/publisher.ts#L130 ? - its happening now in my project when I go over a certain amount of interactions for pact contract

jordan.levin
2021-02-23 19:14
has joined #pact-js

patrick.hendron
2021-02-23 19:18
nevermind, looks like my tests where taking longer than the default timeout for pact verfy (30 sounds), added timeout to the options and configured my timeout, working now :slightly_smiling_face:

francesco.latorre
2021-02-24 05:59
has joined #pact-js

aniket.g2185
2021-02-24 09:13
has joined #pact-js

sundaresank360
2021-02-24 12:12
has joined #pact-js

uladzislau_danilchyk
2021-02-24 13:01
Hello there! I'm just trying to understand how to work with `pact-jest` package. Could anyone help me with that? It just needed to have true logs instead of using default behaviour in pact-js. I'm talking about the issue and recommendation in https://github.com/pact-foundation/pact-js/issues/605 In previous version of my pact test I had a separate file with pact config of consumer, provider, mock url, etc. But using this `pact-jest` package I have to use `withPact` method to wrap my consumer tests and put into method object with config. Is there any possibility to load config from separate file for `withPact` as it was done before through `--setupFiles ./config/pact/setup.js`? I don't want to pass and duplicate config properties every time in every consumer test.

jhawthor
2021-02-24 15:18
has joined #pact-js

chris.r.thomas
2021-02-24 16:54
has joined #pact-js

peter.cook
2021-02-24 17:05
has joined #pact-js

jhawthor
2021-02-24 18:28
Greetings! How does one specify the length of a string property in a consumer pact. i.e. If my body has a property "name" how do I specify a max length for the value of name?

jayeshguru81
2021-02-24 18:34
has joined #pact-js

ben.kirberger
2021-02-24 19:16
has joined #pact-js

francis.lobo
2021-02-24 19:42
Hello there! Is there a pact-jas equivalent for `eachKeyLike` in pact-jvm?

jayeshguru81
2021-02-24 19:59
Hello Team, I have just started learning more about pact as we have React repo and Python Microservice which I would like to make contract test for. I have seen jest-pact and pact-foundation in imports in many examples. I would like to understand what is the difference between two?

brendan.donegan
2021-02-24 20:09
jest-pact is a wrapper library specifically for Jest, which you are probably using as your project is React based

brendan.donegan
2021-02-24 20:09
pact-foundation is the more general library that underpins it and can be used in any Javascript based project

jayeshguru81
2021-02-24 20:10
So do you recommend me using jest-pact?

brendan.donegan
2021-02-24 20:10
Yes

jayeshguru81
2021-02-24 20:10
Thanks

jayeshguru81
2021-02-24 20:10
thats helps

jayeshguru81
2021-02-24 20:11
If there are any jest-pact examples you can point me to that would be really great

jayeshguru81
2021-02-24 20:11
I can create our first jest test

brendan.donegan
2021-02-24 20:12
The example on the README is good enough - https://github.com/pact-foundation/jest-pact

jayeshguru81
2021-02-24 20:12
ok great thanks

francis.lobo
2021-02-24 20:42
@jayeshguru81 those examples are good. I got my Jest pact tests running last week based on them.

francis.lobo
2021-02-24 20:43
Another good one is here : https://github.com/YOU54F/jest-pact-typescript/tree/master/src/pact THis is based on typescript

jayeshguru81
2021-02-24 20:49
Thanks do you have a example repo which uses jest-pact as I tried with those examples but seems not working for me yet. It seems I am missing something

jayeshguru81
2021-02-24 20:49
I have added `jest-pact` and `pact-foundation/pact` in my package.json

francis.lobo
2021-02-24 22:05
hey Jayesh, all I did was use the above example and change the request and response to the ones that suit my needs. sorry I dont have the working code on public repo

francis.lobo
2021-02-24 22:05
can you run the examples out of box? they are standalone

tjones
2021-02-24 22:23
I?ve just left a long comment on that issue - the short version of the specific question about common config is that the intended approach is to pull it out into a separate file. I?d like to add first class support for common config soon - see https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-02-24 22:24
@jayeshguru81 What specific problems are you experiencing? If you share your code we can give you a hand solving them

jayeshguru81
2021-02-24 22:26
```import api from 'yourCode';```

jayeshguru81
2021-02-24 22:26
this one specially

tjones
2021-02-24 22:27
That?s about importing your own code

tjones
2021-02-24 22:27
Your api layer

jayeshguru81
2021-02-24 22:31
yeah but was not sure what to import as I have `services.js` file which makes an Api call ```import axios from 'axios'; export const fetchInitialAssets = batchId => { const endpoint = `${UPLOAD_API_SERVICE_URL}/get_batch_by_id/${batchId}`; return axios .get(endpoint, { headers: { authorization: `Bearer ${token}`, }, }) .then(response => response.data); };```

jayeshguru81
2021-02-24 22:31
So should I be importing `import fetchInitialAssets from ../services`

tjones
2021-02-24 22:32
Yes, and you will need a way to inject `UPLOAD_API_SERVICE_URL` into it

jayeshguru81
2021-02-24 22:35
ok thanks let me try this out

tjones
2021-02-24 22:41
To your original question: jest-pact is a convenience wrapper for writing pact tests with jest

tjones
2021-02-24 22:43
There?s no need to use it, but it provides some of the boilerplate and jest-specific setup for you, so it should be a nicer experience for new users

jayeshguru81
2021-02-24 22:44
ok nice thanks Tim..I am newbie in Javascript/React/Jest world..so pardon me for my dumb questions

tjones
2021-02-24 22:45
Not dumb at all. And, asking these questions here is what the channel is for :+1:

matt.fellows
2021-02-24 22:58
Regex / term matcher

matt.fellows
2021-02-24 22:58
But think hard it that's really important for the consumer to restrict

jhawthor
2021-02-24 23:02
I feel as though if the consumer is defining the contract, they should also define the property attributes such as max length, bool, yes/no, etc. After all it's their data that is being processed based on the customer story. I hope that makes sense.

jhawthor
2021-02-24 23:03
This is especially important is data is stored in a SQL DB.



tjones
2021-02-24 23:10
^ I?ve updated the example and slightly modified your code. Apologies for the changes to the export/import style

tjones
2021-02-24 23:11
Hopefully this will help you get going

matt.fellows
2021-02-24 23:30
The second point is fair

matt.fellows
2021-02-24 23:31
see also https://docs.pact.io/consumer/ and specifically the section on ?Only make assertions about things that will affect the consumer if they change?

matt.fellows
2021-02-24 23:31
there?s no absolute right/wrong here, but I just want to ensure you?re aware of the tradeoffs

abubics
2021-02-25 00:09
In this case, I'd push that to the interaction state, like "given: name is too long", and then it's the provider's job to know what its limit is (because it's stored in the DB).

abubics
2021-02-25 00:09
If it's a UI-validated constraint, then it shouldn't even make it to the API client, and it's not part of the contract.

abubics
2021-02-25 00:11
But if the API client wants to say "no, this response from the provider is invalid because a field is too long", then that's a contract thing . . . I guess that might want to be specified by Pact, but I've never come across that kind of situation.

abubics
2021-02-25 00:14
Worst case, you do it just outside the Pact bit, with regular unit-test assertions, in the same test.

jhawthor
2021-02-25 04:08
It just seems to me that if I am the consumer writing the pact for a REST provider, I would want to specify the the property attributes when using JSON in order to comply with the JSONschema. In the JSONschema, you specify the properties as well as the property attributes. Example can be found here: https://www.jsonschema.net/home Otherwise, a JSONschema would be need by the provider as well as a pact stating "I send this object" and "expect this object". So can a pact work with a JSONschema? Or is it just limited to a basic description of an object and what is expected in return leaving the other details to be covered by additional non-pact contract specifications?

jhawthor
2021-02-25 04:14
The default example does not show a maxLength or enum[] property attribute, but can be added by editing the JSONschema.

abubics
2021-02-25 04:30
JSON Schema is great, but not trying to solve the same problems. You can use them together, to get different kinds of feedback. JSON Schema is not consumer- or provider-driven, and can be used for validation on both ends, in both requests and responses.

abubics
2021-02-25 04:31
JSON Schema is similar to Swagger, in that it says what the general shapes of responses can be, but doesn't describe interactions (which include variations of state).

abubics
2021-02-25 04:37
If you want to specify the length of strings, you can use a regex (like `.{16}` or something). I would be wary of doing that, unless it's actually a hard requirement of the consumer. For example, the consumer might break if a field comes back with the wrong date format, or a malformed GUID, or something, so it makes sense to be in the contract. But if it's a display name in the response, and the database has a max length, but the UI is flexible, then that test doesn't need to live in the contract. It should definitely be tested somewhere else, and if implemented in multiple places (e.g. form validation and also API and DB client), you need to work out how to keep them in sync.

abubics
2021-02-25 04:37
If it's a string length in the request that you want to constrain, I would make separate test cases for it. That's a whole separate category.

jhawthor
2021-02-25 04:55
True, but the same would apply to other types as well. So it would seem that passing a JSONschema would prove to be more appropriate, especially for the provider, than passing a simple pact as it would be more representative of an actual contract. Testing the interaction/inoperability would not be very different from what a pact-broker does now.

abubics
2021-02-25 05:00
One of your points is definitely on the money: Pact isn't trying to solve all testing problems, and some tools are better for different kinds of testing. The other side I'm not really understanding. A schema can say, for example, that a field has to be present and a certain length, or that a bunch of fields are optional. A contract (via Pact) will describe which conditions require certain fields to be present. They're both useful, and not equivalent.

m.stephkan
2021-02-25 05:30
has joined #pact-js

francis.lobo
2021-02-25 05:34
bump :arrow_up: Anyone here know if there is an equivalent in pact-js to the pact-jvm matcher `eachKeyLike` ?

francis.lobo
2021-02-25 05:37
We have a use case similar to the one mentioned in https://github.com/pact-foundation/pact-specification/issues/47 we are using eachKeyLike when writing DSL from pact-jvm Now are a bit stuck generating contracts from JS. Any insight on how to use the JS matchers in this case will be really helpful

uglyog
2021-02-25 05:38
There isn't in the core pact-js. I'm checking the V3 beta version to see if it supports it

uglyog
2021-02-25 05:42
No, I didn't add it because there are issues with the implementation in Pact-JVM. See https://github.com/pact-foundation/pact-specification/issues/47 for a replacement

uglyog
2021-02-25 05:43
Can you raise an issue for this? It needs to be tagged with V3.

matt.fellows
2021-02-25 06:16
There is not

matt.fellows
2021-02-25 06:17
Ah sorry, I saw the notification and responded. But it didn't show Ron's response

matt.fellows
2021-02-25 06:17
What Ron said :rolling_on_the_floor_laughing:

matt.fellows
2021-02-25 07:01
So on the JSON schema thing, DM me offline and we talk about a feature we've just added to Pactflow around OAS and pact interop

matt.fellows
2021-02-25 07:01
But also, what everything Andras said

matt.fellows
2021-02-25 07:01
Schema != Contract

matt.fellows
2021-02-25 07:02
In fact, I may find away to make this very prominent in the docs because it's coming up a lot recently


francis.lobo
2021-02-25 08:11
Thanks for the response gents. Will raise an issue

stephen.tjasink
2021-02-25 08:23
has joined #pact-js

matt.fellows
2021-02-25 08:32
:+1:

jayeshguru81
2021-02-25 13:40
Thanks a lot Tim you are a hero..I will do this and try

jayeshguru81
2021-02-25 14:26
I keep on getting this error while running my test - ```Missing `pino-pretty` module: `pino-pretty` must be installed separately```

jayeshguru81
2021-02-25 14:27
I tried to include `pino-pretty` module in my `package.json` 's resolution section too

jayeshguru81
2021-02-25 14:28
We are using prettier for formatting our files

jayeshguru81
2021-02-25 18:05
```Missing `pino-pretty` module: `pino-pretty` must be installed separately 1 | 'use strict'; 2 | > 3 | import {pactWith} from 'jest-pact'; | ^ 4 | import {Matchers} from '@pact-foundation/pact'; 5 | 6 | import {fetchInitialAssets} from '../../services';```

yousafn
2021-02-25 19:05
Put pino-pretty and pino in your devDeps in package json or dev section if you also use pino in your app code Passing in your endpoint url is also the best way as shown above, as it makes it far easier to test :ok_hand: Good luck on your journey lad!

yousafn
2021-02-25 19:09
Ooooh! Maybe a v1 is near

jayeshguru81
2021-02-25 19:45
Nope we don't use `pino` and `pino-pretty` at all, that's why not able to understand why I am getting that error

jayeshguru81
2021-02-25 19:45
is it because `jest-pact` need it ?

beatrizwaclawek
2021-02-25 20:27
has joined #pact-js

zhoutianli1234
2021-02-25 21:09
has joined #pact-js

neild
2021-02-25 21:31
My issue was that I was receiving a dynamic variable through the query string that was used in a middleware. I ended up stubbing the middleware out to return a fixed response no matter what the query string variable was


francis.lobo
2021-02-26 00:05
Is there any alternate recommendation/workaround to do a dynamic key matching in Pact JS right now ?

jayeshguru81
2021-02-26 00:08
i tried to create these again but it seems to give this error again

uglyog
2021-02-26 00:11
I don't think there is. @matt.fellows might be able to confirm. But i will try get this implemented as a priority to help you.

francis.lobo
2021-02-26 00:20
If it can be prioritized, that would be awesome :star-struck:

matt.fellows
2021-02-26 03:11
The v3 branch of Pact JS also has a ?value from provider state? function, that let?s you map this

travis.day
2021-02-26 04:06
has joined #pact-js

sagupta
2021-02-26 09:41
Morning, I came across an article in docs about some recommended patterns on organising your interactions in separate files and some more tips on using pact-js. Cant find that now . If someone knows the link , can you please link here ? Thanks


andrew.cunningham
2021-02-26 11:13
has joined #pact-js

jayeshguru81
2021-02-26 11:46
Has anyone faced below issue with jest-pact?

andrew.cunningham
2021-02-26 11:54
@andrew.cunningham has left the channel

tjones
2021-02-26 15:58
Jest pact doesn?t use either of those modules. If you?re able to upload a reproducible example somewhere, we can take a look. Does this keep happening if you delete package-lock and node_modules?

jayeshguru81
2021-02-26 16:00
Just now one developer suggested me to downgrade my node version to `v11` as I was using `v15` which is much recent version and it solved `missing pino-pretty` issue

jayeshguru81
2021-02-26 16:01
I did that and deleted node_modules and reinstalled `npm install` so it passed that issue now

jayeshguru81
2021-02-26 16:01
now I can concentrate on real issues with my tests

jayeshguru81
2021-02-26 16:03
Just wanted to check if I need to do some configuration for contract tests ?

jayeshguru81
2021-02-26 16:04
like setting up the loalhost pact broker somewhere

jayeshguru81
2021-02-26 18:19
I take my words back, pino-pretty error is still happening even after downgrading node version to `11.0.0`

jayeshguru81
2021-02-26 18:21
Also ripped open yarn.lock file and found `@pact-foundation/pact` has a dependency on `pino-pretty` which is where it is coming from

brendan.donegan
2021-02-26 18:25
indeed it does

jayeshguru81
2021-02-26 18:35
I see `pino-pretty` got installed in the `node_modules`

jayeshguru81
2021-02-26 18:35
but it is missing in `@types` , could that be the reason it is not able to find?

brianmasschaele
2021-02-27 13:27
has joined #pact-js

jayeshguru81
2021-02-27 17:11
Its weird issue which comes after running `yarn` for installing dependencies for some node version, when I tried same thing with `npm install` it worked fine. I dont see any difference while installing deps with both commands but should be something odd

pedroefajardo_pactio
2021-02-27 17:18
has joined #pact-js

tjones
2021-02-28 22:38
I don?t know, sorry. Sounds like a yarn issue, maybe?

jayeshguru81
2021-02-28 22:39
Yes seems to me

tjones
2021-02-28 22:40
To your questions- the pino-pretty types aren?t part of the exported interface of pact-js (unless you?re importing the logger from within the internals), so the `@types` isn?t a dependency

tjones
2021-02-28 22:41
You only need `@types/xxx` if you?re using Typescript and doing development using whatever `xxx` is

jayeshguru81
2021-02-28 22:41
Oh OK thanks for clarifying

tjones
2021-02-28 22:42
> Just wanted to check if I need to do some configuration for contract tests ? It depends what you mean. Usually you wouldn?t run the broker locally at all. If you want to spin one up to see how it all fits together it is possible

jayeshguru81
2021-02-28 22:44
I meant mocking provider locally for doing development

jayeshguru81
2021-02-28 22:44
which I guess we are already doing by mockService.baseUrl

tjones
2021-02-28 22:44
No, you don?t need to mock the provider during development, pact does this for you


jayeshguru81
2021-02-28 22:45
sure will give this a read

tjones
2021-02-28 22:45
The config that you need for writing contract tests is in the example I sent - if you can install that example, you have everything you need

jayeshguru81
2021-02-28 22:46
I got missing requests and unexpected requests errors while running my contract tests

tjones
2021-02-28 22:46
if you want to share your contract with a provider, then you?ll want a broker (it is possible to do this without, but it is much much easier with)

jayeshguru81
2021-02-28 22:46
thats why I thought I am missing some configuration

tjones
2021-02-28 22:46
Ok. This is usually because the expectations are not matching the actual sent

tjones
2021-02-28 22:47
you can check the pact log file (linked in the test fail) to see the details

tjones
2021-02-28 22:47
often it?s headers that you?re expecting that aren?t being sent or vice versa

jayeshguru81
2021-02-28 22:48
yeah on that point I think bearer token is generated and I am not sending correct token

jayeshguru81
2021-02-28 22:48
could that be the reason

tjones
2021-02-28 22:48
so, if your request sent is subtly different (say you expect `X` but you sent `x`), then the error will say that it is missing `X` and it got the unexpected request `x`


jayeshguru81
2021-02-28 22:49
so do I need to send real bearer token in my requests?

tjones
2021-02-28 22:49
In the example I sent you, I had a specific bearer token generated for tests

tjones
2021-02-28 22:50
There are a few different approaches for testing bearer tokens

tjones
2021-02-28 22:50
which one makes sense for you will depend on your use cases and ecosystem

tjones
2021-02-28 22:51
I prefer the ?assume that `"TOKEN"`is a valid token? approach

tjones
2021-02-28 22:51
then in your provider verification, you can stub your auth layer

tjones
2021-02-28 22:51
But depending on how your system works, this may not be appropriate

tjones
2021-02-28 22:53
If you?re still having trouble, post your code and we can take a look

jayeshguru81
2021-02-28 22:54
yeah thats what I was wondering how could I mock the bearer token but will check if we have some examples here. As you said it varies per system, so it might be a challenge here to mock auth token

jayeshguru81
2021-02-28 22:55
Also I do not know why Unexpected requests says `OPTIONS` when I am sending `GET` calls

jayeshguru81
2021-02-28 22:55
```console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /get_batch_by_id/test_batch_id Unexpected requests: OPTIONS /get_batch_by_id/test_batch_id```

tjones
2021-02-28 23:03
Right, so this is because your http library is sending cors preflight checks

tjones
2021-02-28 23:03
add `cors: true` to your pact options

tjones
2021-02-28 23:03
this will tell the mock provider to expect cors preflight requests

jayeshguru81
2021-02-28 23:12
oh ok, cool thanks got it

jayeshguru81
2021-02-28 23:12
I will keep you posted if it works, thanks a lot again for your big help on getting me started here

tjones
2021-02-28 23:21
You?re welcome! Once you?ve got it all working together, it should be much easier the second time

jayeshguru81
2021-02-28 23:26
yes agree :+1::skin-tone-2:

tjones
2021-03-01 00:30
FYI: We?re going to rename `pact-node` to `pact-core` to better reflect the purpose of the package. No action will be required from users (especially if you?re using `@pact-foundation/pact`).

dominic_herrmann
2021-03-01 06:54
has joined #pact-js

dominic_herrmann
2021-03-01 07:03
Hey Folks J, we are building up a new web application using Angular 11. In our code we have got input fields getting submitted to a spring boot rest service. The service call in Angular/Typescript looks like that:     *const url = `${environment.baseURLService}/${this.path}`;* * *     *return this.http.get<OurResponse>(url, {*       *params: search.getParamsArray()*     *})*       *.pipe(catchError(error => this.handleError(error)));* Search.getParamsArray() delivers a Map with our search paramters from the input fields. Beside that we are using Jasmine and PactWeb in order to generatet he Pact File, the contract between our frontend and rest service. Here is an Example snippet out oft he Pact File:        *"description": "Person with name Peter NotFound is found",*       *"providerState": "Person with name Peter NotFound exists",*       *"request": {*         *"method": "GET",*         *"path": "/pc/v1/service",*         *"query": "name=Peter+NotFound"*       *},*       *"response": {*         *"status": 200,*         *"headers": {*           *"Content-Type": "application/json",*           *"Access-Control-Allow-Origin": "*"*         *},*         *"body": {*           *"person": [*             *{*               *"name": "Peter NotFound",*               *"birthdate": "04.07.1978"*             *}*           *]*         *}*       *}*     *}* Our real service and our angular client are working well together. But if we start up MockServer WebRick 1.3.1 with our generated PACT File via  pact-stub-service --cors --port 1234 ./pacts/gui-rest-service.json For our search with name ?Peter NotFound? we get the following error: *No interaction found for GET /pc/v1/service?name=Peter%20NotFound* * * *The Problem is that our WebRick Mock Server can handle only request with + instead of %20. How can we get rid of that Problem?* *We are using , , *

tjones
2021-03-01 07:22
`%20` is space, but your expectation is looking for a plus. I think using plusses for spaces is only valid when the encoding is `application/x-www-form-urlencoded`, which I _think_ might not be valid for a get

uglyog
2021-03-01 07:52
Plus is valid for older browsers, because HTML 2 spec says to encode query parameters using form url encoded scheme. Later specs and RFCs only mention the percent encoding scheme.


dominic_herrmann
2021-03-01 07:57
Because PactWeb and Jasmine generate + for space in generated PACT File. Our question is why does this differ to Angular/Typescript behaviour generating %20. Can we get them synchronous?

tjones
2021-03-02 04:18
What does your test code look like?

ranjanayush03
2021-03-02 10:31
Hi I have a query , as in java we have matchPath option to validate a regex so similarly in javascript what is the option for the same.

dominic_herrmann
2021-03-02 12:02
*describe('Service', () => {* *let provider: PactWeb;* *const expectedPerson: Person = {* *name: 'Peter NotFound',* *birthdate: '04.07.1978'* *}* *beforeAll(function (done) {* *provider = new PactWeb({* *port: 1234,* *host: 'localhost',* *spec: 3* *});* *// required for slower CI environments* *setTimeout(done, 2000);* *// Required if run with `singleRun: false`* *provider.removeInteractions();* *});* *afterAll(function (done) {* *provider.finalize()* *.then(function () {* *done();* *}, function (err) {* *done.fail(err);* *});* *});* *beforeEach(() => {* *TestBed.configureTestingModule({* *imports: [* *HttpClientModule* *],* *providers: [* *Service* *],* *});* *});* *afterEach((done) => {* *provider.verify().then(done, e => done.fail(e));* *TestBed.resetTestingModule();* *});* *describe("Test", () => {* *const expectedResponse: PersonResponse = {* *person: [expectedPerson]* *}* *beforeAll((done) => {* *provider.addInteraction({* *state: `Person with name Peter NotFound exists`,* *uponReceiving: `Person with name Peter NotFound is found`,* *withRequest: {* *method: 'GET',* *path: '/pc/v1/service',* *query: { name: `Peter NotFound` }* *},* *willRespondWith: {* *status: 200,* *body: {* *person: [expectedPerson]* *},* *headers: {* *'Content-Type': 'application/json',* *'Access-Control-Allow-Origin': '*'* *}* *}* *}).then(done, error => done.fail(error));* *});* *it(`Person with name Peter NotFound is delivered`, (done) => {* *const service: Service = TestBed.get(Service);* *service.getPerson(personSearch).subscribe(response => {* *expect(response).toEqual(expectedResponse);* *done();* *}, error => {* *done.fail(error);* *})* *})* *});*

matthew.long
2021-03-02 14:08
has joined #pact-js

tmoncm
2021-03-02 17:17
has joined #pact-js

dcorrales
2021-03-02 19:48
hey folks, apologies if this has already been asked - is there a way to specify that a json attribute can be either a string or null?

brendan.donegan
2021-03-02 20:28
this is a very common question. short answer is ?if it can be a string or *null* and the provider returns null, how do you know that?s not a bug??


dcorrales
2021-03-02 20:34
hey @brendan.donegan thanks for the info. I was leaning towards a second example with our possibly null fields, but wanted to double check just in case :sweat_smile:

dcorrales
2021-03-02 20:34
appreciate the help :slightly_smiling_face:

matt.fellows
2021-03-02 21:19
You just use the regex matcher on the path property itself

matt.fellows
2021-03-02 21:20
There is at least one example in the repo somewhere

phoenixcampos01
2021-03-02 21:25
has joined #pact-js

phoenixcampos01
2021-03-02 21:58
Hey guys, I'm not sure if this is the right place for this question, but this is the language I'm using. I'm trying to just test an async message provider locally by specifying a path to a fake consumer pact json. However, I'm not sure whether this is the intention of that feature given that there seems to be no documentation for the structure of that json. Is the intention to download the json from the broker and then run the verification against that, so really only the broker knows the structure of the json? Or is there an easy way to generate the json?

matt.fellows
2021-03-02 22:26
Do you have a message consumer for it? You should be first writing a consumer test and then using the contract it generates

matt.fellows
2021-03-02 22:26
It's the same as HTTP pact in that regard

matt.fellows
2021-03-02 22:26
Also the pact specification governs the structure of that file


andrewshtamburg
2021-03-02 23:00
has joined #pact-js

andrewshtamburg
2021-03-02 23:04
Hey! I'm just starting with pact and facing some issues. I wrote a simple app and trying to cover it with contract test. At the moment I'm getting this error while trying to run test ```Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves``` The test and function under test is in the thread. I'd really appreciate if you could guide me through what I'm doing wrong here

andrewshtamburg
2021-03-02 23:05
Here is the function that makes a call to the back end

andrewshtamburg
2021-03-02 23:07
Here is the test

andrewshtamburg
2021-03-02 23:12
Here is the function that makes a call to the back end

andrewshtamburg
2021-03-02 23:16
Here is what I'm getting upon running the tests.

matt.fellows
2021-03-02 23:55
Have you tried increasing the timeout?

matt.fellows
2021-03-02 23:56
What does the log file say?

joel.whalen
2021-03-03 00:31
We have been using jest pact successfully in all our pipelines for a few months now, but this dependency issue just popped up in development now: ```18:13:56 Error: Cannot find module 'jest-jasmine2' 18:13:56 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15) 18:13:56 at Function.resolve (internal/modules/cjs/helpers.js:30:19) 18:13:56 at normalize (/pub/jenkins/workspace/zoro.com/development/node_modules/jest-config/build/normalize.js:693:34) 18:13:56 at readConfig (/pub/jenkins/workspace/zoro.com/development/node_modules/jest-config/build/index.js:220:68) 18:13:56 at process._tickCallback (internal/process/next_tick.js:68:7) 18:13:56 at Function.Module.runMain (internal/modules/cjs/loader.js:744:11) 18:13:56 at startup (internal/bootstrap/node.js:285:19) 18:13:56 at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)``` This happens immediately after our jest command to run pact: ```18:13:55 > jest web/static/scripts/ --runInBand --config jest.pact.js``` This error happened in our common development pipeline, otherwise the feature branch would not have been allowed to even merge into it in the first place. Does a dependency update need to happen? Or is it something else?

tjones
2021-03-03 00:32
Hmm. I can?t think of a reason that jest-pact is responsible for this, but that doesn?t mean it isn?t

tjones
2021-03-03 00:32
what version of jest do you have?

joel.whalen
2021-03-03 00:33
25.5.4

tjones
2021-03-03 00:34
I think this might be a config issue - is there something in your jest config that shouldn?t be?

tjones
2021-03-03 00:36
or, is it a corrupt node_modules / package-lock? jest-jasmine2 is a dependency in that version of jest

tjones
2021-03-03 00:37
jest-pact doesn?t have many dependencies, and only uses the public api from jest

joel.whalen
2021-03-03 00:39
Contents of `jest.pact.js`: ```const merge = require('lodash/merge'); const commonJest = require('./jest.common'); module.exports = merge({}, commonJest, { testEnvironment: 'node', testRegex: '/*(.pact.ts)', });``` which is merging with `jest.common.js`, here: ```const babelConfig = require('./babel.jest'); module.exports = { verbose: true, testEnvironment: 'jsdom', resolver: 'jest-directory-named-resolver', moduleFileExtensions: [ 'js', 'vue', 'json', 'ts', 'ts.vue', ], globals: { 'vue-jest': { babelConfig, tsConfig: './tsconfig.json', }, 'ts-jest': { babelConfig, isolatedModules: true, tsConfig: './tsconfig.json', }, }, clearMocks: true, transformIgnorePatterns: [ 'node_modules/(?!(zoro-component-library|vuetify/lib)/)', ], transform: { '^.+\\.js$': './gulp/jestTransformer.js', '.*\\.vue$': 'vue-jest', '.*\\.ts$': 'ts-jest', }, moduleNameMapper: { '^beforeunload-request$': '<rootDir>/node_modules/beforeunload-request/dist/beforeunload-request.min.js', 'cache-helper-RUN_ENV': '<rootDir>/web/static/scripts/base/util/cache-helper-server.ts', 'performance-RUN_ENV': '<rootDir>/web/static/scripts/services/performance/performance-test-stub.ts', '^scripts/(.*)$': '<rootDir>/web/static/scripts/$1', '^~scripts/(.*)$': '<rootDir>/web/static/scripts/$1', '^zoro$': '<rootDir>/web/static/scripts/base/global/zoro.js', '^_gb$': '<rootDir>/web/static/scripts/base/global/_gb.js', '^_gbGlobal$': '<rootDir>/web/static/scripts/base/global/_gbGlobal.js', '^bridgeData$': '<rootDir>/web/static/scripts/base/global/bridgeData.js', '^console$': '<rootDir>/web/static/scripts/base/global/console.js', '^pageData$': '<rootDir>/web/static/scripts/base/global/pageData.js', '^fancybox$': '<rootDir>/node_modules/fancybox/dist/js/jquery.fancybox.js', '^bootstrap/(.*)$': 'bootstrap-sass/assets/javascripts/bootstrap/$1', '^package.json$': '<rootDir>/package.json', '^~zcl/(.*)$': '<rootDir>/node_modules/zoro-component-library/lib/$1', '^vuetify/(.*)$': '<rootDir>/node_modules/vuetify/$1', '^~vue/(.*)$': '<rootDir>/web/static/vue/$1', '^~store/(.*)$': '<rootDir>/web/static/vue/store/$1', '^~sass/(.*)$': '<rootDir>/web/static/styles/sass/$1', '^~tests/(.*)$': '<rootDir>/web/static/scripts/unit-tests/$1', '^~erp/(.*)$': '<rootDir>/web/erp/lib/$1', 'zoro-RUN_ENV': '<rootDir>/web/static/scripts/base/global/zoro-server.js', '^.+\\.(c|le|sc|sa)ss$': 'identity-obj-proxy', }, };``` `babel.jest.js`: ```const babelConfig = require('./babel.common'); module.exports = babelConfig( { targets: { node: 'current' } }, { babelrc: false, plugins: [ ['babel-plugin-transform-imports', { lodash: { // eslint-disable-next-line no-template-curly-in-string transform: 'lodash/${member}', }, }], '@babel/plugin-transform-modules-commonjs', ['dynamic-import-node', { noInterop: true }], ], }, );``` `babel.common.js`: ```const mergeWith = require('lodash/mergeWith'); function mergeCustomizer(objValue, srcValue) { if (Array.isArray(objValue) && Array.isArray(srcValue)) { return objValue.concat(srcValue); } return undefined; } module.exports = ( { targets } = {}, additionalSettings = {}, ) => mergeWith( {}, { presets: [ ['@babel/preset-env', { useBuiltIns: 'entry', modules: false, corejs: 3, ...(targets ? { targets } : {}), }], ], plugins: [ '@babel/plugin-syntax-dynamic-import', '@babel/plugin-transform-runtime', '@babel/plugin-proposal-class-properties', ], }, additionalSettings, mergeCustomizer, );```

matt.fellows
2021-03-03 00:41
This is the ?state of javascript in 2021? medium post right there :point_up:

joel.whalen
2021-03-03 00:41
lmaoooo

tjones
2021-03-03 00:42
I?m wondering if it?s related to one of the module name mappers, but I can?t see anything obvious

tjones
2021-03-03 00:42
I don?t think it?s anything pact-related, though

matt.fellows
2021-03-03 00:44
has something recently changed? I?d be looking to bisect the issue, but with that config :scream:

matt.fellows
2021-03-03 00:44
it looks like jest-jasmine2 is a dependency of jest, so it?s no surprise that?s coming in

matt.fellows
2021-03-03 00:45
so if you ran `npm list jest-jasmine2` does it find the module?

joel.whalen
2021-03-03 00:45
Right, the big tip off for me was that this error happened in our development pipeline. If one of our developers made this change, their feature branch wouldn?t have allowed this to happen.

matt.fellows
2021-03-03 00:45
so that could mean pinning versions migth help?

joel.whalen
2021-03-03 00:46
Jest is pinned though

tjones
2021-03-03 00:46
If you haven?t already, it might be useful to try removing things from the config to see what the cause is. If it does seem to be pact, it would be useful to get a minimal reproducible example

joel.whalen
2021-03-03 00:46
here?s the output of `npm list jest-jasmine2` ```$ npm list jest-jasmine2 @1.0.1 /Users/xjxw304/Documents/BitBucket/environment/microservices/zoro ??? jest@25.5.4 ??? @jest/core@25.5.4 ??? jest-config@25.5.4 ? ??? jest-jasmine2@25.5.4 ??? jest-runner@25.5.4 ??? jest-jasmine2@25.5.4 ```

joel.whalen
2021-03-03 00:46
so it seems to know it?s there, on my local machine at least

matt.fellows
2021-03-03 00:47
yeah cool. If it?s breaking only on CI, can you reproduce by clearing node modules and re-install?

joel.whalen
2021-03-03 00:47
trying now, I?ll get back to you in 40 minutes?.

joel.whalen
2021-03-03 00:47
?yeah this should be a medium post lol

matt.fellows
2021-03-03 00:48
I mean, I won?t read it, but it will probably go viral

joel.whalen
2021-03-03 00:48
?javascript = bad? is always good clickbait

matt.fellows
2021-03-03 00:49
It?s about timing

matt.fellows
2021-03-03 00:50
It actually feels like it?s been a while since one has appeared (but also, i?ve unsubscribed from Medium because their recommendation system just kept giving me more rubbish, and the bottom was essentially reality TV in email form, and I wasn?t willing to fall that far).

matt.fellows
2021-03-03 00:50
so, you know, maybe timing is right (get that paywall up!)

joel.whalen
2021-03-03 00:50
right, reddit or hackernews is a better aggregate for actual good medium posts. Either that, or the top result from google that helps me with whatever error I?m debugging

matt.fellows
2021-03-03 00:55
indeed

joel.whalen
2021-03-03 00:56
npm install might be stuck, I?ll come back later with results it?s already 8pm here

andrewshtamburg
2021-03-03 08:29
Here is what log file says

andrewshtamburg
2021-03-03 08:29
And yes, I tried to increase a timeout with no luck unfortunately :disappointed:

matt.fellows
2021-03-03 08:34
Wrong log sorry, pact should produce a log

andrewshtamburg
2021-03-03 08:38
Sorry for dumb questions, but where do I find this file?

andrewshtamburg
2021-03-03 08:41
`mockserver-integration.log` is empty :disappointed:

andrewshtamburg
2021-03-03 08:44
Change the log level to `DEBUG`, may be this will help.

andrewshtamburg
2021-03-03 08:44
After last line it just hangs and nothing happens until I abort manually

matt.fellows
2021-03-03 08:46
Hmm timeout still seems likely. But please share the pact log file. It's in the `logs` dir according to your setup

andrewshtamburg
2021-03-03 13:05
It was an timeout thing after all. Increased it more it started to work

andrewshtamburg
2021-03-03 13:05
Thanks a lot for your help

joel.whalen
2021-03-03 15:14
after a clean install, the tests run fine on my machine. Also there have been 3 subsequent runs of development where it passes just fine. What a strange, one-off issue.

hugh.paul.mcgowan
2021-03-03 17:52
has joined #pact-js

normanrs
2021-03-04 11:18
has joined #pact-js

sagupta
2021-03-04 12:43
hello team, I am getting this error when running pact tests with jest on CI . Looks like the pact startup is not completed . Has anyone faced a similar issue ```[2021-03-04 12:40:57.917 +0000] ERROR (307 on runner-2bymd9cd-project-94-concurrent-0): pact-node@10.11.8: Pact Binary Error: /gitlab/builds/2BymD9cd/0/<>/dev/graphql/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.37/pact/lib/ruby/bin/ruby: line 6: /gitlab/builds/2BymD9cd/0/<>/dev/graphql/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.37/pact/lib/ruby/bin.real/ruby: No such file or directory```

matt.fellows
2021-03-04 12:55
Looks like the alpine issue

matt.fellows
2021-03-04 12:55
There's a page on the docs for that

jayeshguru81
2021-03-04 12:57
Hey Tim wanted to thank you again as my contract test was completed for the JS repo

sagupta
2021-03-04 13:43
that was a good suggestion because we are indeed creating a container from a alpine node image

sagupta
2021-03-04 13:44
I checked locally by adding the dependencies mentioned here https://docs.pact.io/docker/#reference-image in my Dockerfile

sagupta
2021-03-04 13:45
but now i get a different error ```[2021-03-04 13:41:03.142 +0000] DEBUG (79 on c760da961371): pact-node@10.11.8: Starting pact binary 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service', with arguments [service --consumer graphql --pact_dir /opt/project/pacts --host 127.0.0.1 --log /opt/project/var/pact/logs/pact.log --pact-file-write-mode overwrite --port 8087 --provider email-action-api --pact_specification_version 2] [2021-03-04 13:41:03.150 +0000] DEBUG (79 on c760da961371): pact-node@10.11.8: Created 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service' process with PID: undefined [2021-03-04 13:41:03.156 +0000] ERROR (79 on c760da961371): pact-node@10.11.8: errno: "ENOENT" code: "ENOENT" syscall: "spawn standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" path: "standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" spawnargs: [ "service", "--consumer", "graphql", "--pact_dir", "/opt/project/pacts", "--host", "127.0.0.1", "--log", "/opt/project/var/pact/logs/pact.log", "--pact-file-write-mode", "overwrite", "--port", "8087", "--provider", "email-action-api", "--pact_specification_version", "2" ] [2021-03-04 13:41:03.165 +0000] WARN (79 on c760da961371): pact-node@10.11.8: Pact exited with code -2. [2021-03-04 13:41:03.165 +0000] INFO (79 on c760da961371): pact-node@10.11.8: Removing Pact process with PID: undefined```

sagupta
2021-03-04 13:47
Its not able to create pact mock service and assign a PID

sagupta
2021-03-04 14:17
I have used very simple images and all are getting the same error as above ? A alpine image with necessary dependency ? A full node:8 image

sagupta
2021-03-04 15:52
Hey team , do you know if there is a way to expose child process errors or logs when pact mock service startup process runs. Currently i am getting a error on pact mock service startup running on docker container but doesnt mention what went wrong in terminal ```[2021-03-04 15:49:43.634 +0000] INFO (77 on ebc7eb1bbf0e): pact-node@10.11.8: Creating Pact Server with options: {"consumer":"graphql","cors":false,"dir":"/opt/project/pacts","host":"127.0.0.1","log":"/opt/project/var/pact/logs/pact.log","pactFileWriteMode":"overwrite","port":8087,"provider":"email-action-api","spec":2,"ssl":false} [2021-03-04 15:49:43.695 +0000] DEBUG (77 on ebc7eb1bbf0e): pact-node@10.11.8: Starting pact binary 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service', with arguments [service --consumer graphql --pact_dir /opt/project/pacts --host 127.0.0.1 --log /opt/project/var/pact/logs/pact.log --pact-file-write-mode overwrite --port 8087 --provider email-action-api --pact_specification_version 2] [2021-03-04 15:49:43.703 +0000] DEBUG (77 on ebc7eb1bbf0e): pact-node@10.11.8: Created 'standalone/linux-x64-1.88.37/pact/bin/pact-mock-service' process with PID: undefined [2021-03-04 15:49:43.709 +0000] ERROR (77 on ebc7eb1bbf0e): pact-node@10.11.8: errno: "ENOENT" code: "ENOENT" syscall: "spawn standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" path: "standalone/linux-x64-1.88.37/pact/bin/pact-mock-service" spawnargs: [ "service", "--consumer", "graphql", "--pact_dir", "/opt/project/pacts", "--host", "127.0.0.1", "--log", "/opt/project/var/pact/logs/pact.log", "--pact-file-write-mode", "overwrite", "--port", "8087", "--provider", "email-action-api", "--pact_specification_version", "2" ] [2021-03-04 15:49:43.718 +0000] WARN (77 on ebc7eb1bbf0e): pact-node@10.11.8: Pact exited with code -2. [2021-03-04 15:49:43.719 +0000] INFO (77 on ebc7eb1bbf0e): pact-node@10.11.8: Removing Pact process with PID: undefined```

jayson.bailey
2021-03-04 19:18
has joined #pact-js

jayeshguru81
2021-03-04 21:48
Hi Team, We have JS repo which makes call to our internal API, which does not even have baseUrl defined (meaning it calls API through proxy `http://our-intranet-proxy-url/a/cm/associate_products`). In this case services layer just does this and the requested is routed through our intranet url in browser. Does anyone know how we can write pact test for such scenarios? ```export const submitAssociationData = requestData => { const endpoint = `/a/cm/associate_products`; return http://axios.post( endpoint, {requestData} ); };```

matt.fellows
2021-03-04 22:57
are you running on alpine?


matt.fellows
2021-03-04 22:59
there is a note on the Pact JS site/docs also

matt.fellows
2021-03-04 22:59
I think that?s probably the issue

matt.fellows
2021-03-04 22:59
if you can get onto the docker container and try to execute the same command you might find out more also

audun.halland
2021-03-04 23:18
Hi, in pact-js _verification_ (I?m using V3 beta, but seems to also apply to stable version(?)), is there a way to _filter states_ during verification debugging? Looking for something like the `--filter-state` argument to `pact_verifier_cli`.

matt.fellows
2021-03-05 00:08
In v2 you can (if I understand your question)


matt.fellows
2021-03-05 00:10
if it?s _just_ routing the request, I?d find a way to ignore the intermediate layer and re-write the paths later on in a repeatable way


audun.halland
2021-03-05 00:19
Ah, that was why I didn?t find it. I was page-searching for `filter` :slightly_smiling_face: So env var, I think I like that! It doesn?t work in V3 though :stuck_out_tongue:

matt.fellows
2021-03-05 00:26
Probably worth exposing it both as a flag and an env var I reckon

audun.halland
2021-03-05 00:29
I like not having to fear of accidentally committing such a filter

matt.fellows
2021-03-05 00:29
yep

matt.fellows
2021-03-05 00:30
makes sense

tjones
2021-03-05 01:59
Do you see any errors during install? It might not be downloading the binaries correctly

tjones
2021-03-05 02:24
That?s great to hear! You?re welcome :slightly_smiling_face:

matt.fellows
2021-03-05 11:47
Are you mounting the directory from a Mac or windows host? If so, it may not have the Linux binaries installed (because they were installed on the host with the OS specific binary)

matt.fellows
2021-03-05 11:47
Could please share the exact docker command?

matt.fellows
2021-03-05 11:50
Also you could just try and run that command yourself to see if it works, it might give you more specific feedback

matt.fellows
2021-03-05 11:50
Frustrating error though

sagupta
2021-03-05 11:53
I debugged this yesterday with one of the devs and we are also suspecting that it might be due to the linux binaries not installed properly

sagupta
2021-03-05 11:53
Still trying out few options locally , will keep posted as i get some fix

jayeshguru81
2021-03-05 13:58
Thanks @matt.fellows you are right We are just routing the request to the internal kubernetes ingress url `http://kube-my-provider-endpoint.domain.com/api/v1/associate_products` as our API are not public so thats why the request are routed through a proxy. This is a huge pain point because all our APIs are private, so solution to this will unblock us from writing contract tests for everything.Below is my test code for the same CC: @tjones who helped me in creating pact test for our external APIs(which has defined baseUrl) ```'use strict'; import {pactWith} from 'jest-pact'; import {Matchers} from '@pact-foundation/pact'; import {submitAssociationData} from '../../services'; pactWith( { consumer: 'my-frontend-association-repo', provider: 'my-association-api', cors: true, }, provider => { describe('Submit Association Data', () => { const requestBody = { associations: [ { requestor_id: 'test_requestor', requestor_id_type: 'DSID', asset_id: 'test_asset_id', asset_id_type: 'IRE_ID', product_id_type: 'SKU', products: [ {product_id: 'test_product_id_1', is_active: true, is_primary: false}, {product_id: 'test_product_id_2', is_active: true, is_primary: false}, ], }, ], }; const expectedBody = { code: 200, body: { Success: true, }, }; beforeEach(() => { const interaction = { state: 'Asset Association exists', uponReceiving: 'a request for submitting asset association for assetid test_asset_id', withRequest: { method: 'POST', path: '/api/v1/associate_products', }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: expectedBody, }, }; return provider.addInteraction(interaction); }); // add expectations it('returns a successful body', () => { return submitAssociationData( requestBody, provider.mockService.baseUrl ).then(content => { expect(content).toEqual(Matchers.extractPayload(expectedBody)); }); }); }); } );```

tjones
2021-03-05 14:55
Looks like in the internal case you have an empty base URL, because of kube magic? That?s fine, just inject an empty one for production, and modify it to non-empty during pact tests

jayeshguru81
2021-03-05 15:01
ah ok...let me try this

jayeshguru81
2021-03-05 21:19
Thanks again Tim, this worked for me :slightly_smiling_face:

matt.fellows
2021-03-05 22:04
How are you running the container and what commands are you running in it? Please share

matt.fellows
2021-03-05 22:04
I know pact js works in docker, because we do it

matt.fellows
2021-03-05 23:49
that?s what i?d do too

matt.fellows
2021-03-05 23:49
Probably worth us documenting that use case somewhere, it?s pretty common!

matt.fellows
2021-03-05 23:50
Added a reminder to follow up these docs next week

dominic_herrmann
2021-03-08 09:17
Hey, how can we use bigint for IDs while generating PACT File with Jasmine and PactWeb? We are getting error "Do not know how to serialize a BigInt" during "ng test"

matt.fellows
2021-03-08 09:34
you can?t do that, only things that can be serialised in JSON can go into a Pact file. How is it represented over the wire? I?m going to assume a string


dominic_herrmann
2021-03-08 10:20
Thx, not good, in our Java REST Backend it is a long value. If we user a string in typescript, the value in generated pact file is in braces (like all strings), which would not be correct

matt.fellows
2021-03-08 10:21
so this isn?t a Pact issue

matt.fellows
2021-03-08 10:21
the reality is, your Angular App is using BigInt but needs to send it over the wire to Java, but JSON knows no such thing about BigInt.

matt.fellows
2021-03-08 10:22
Given the JSON options are limited to just a few primitives, you have two choices (I think): 1. Serialise it as a number 2. Serialise it as a string

matt.fellows
2021-03-08 10:22
Your Java service should be able to handle how to read either of those into a long value, that?s just mapping stuff

matt.fellows
2021-03-08 10:23
Personally, I?d serialise as a string, because if you need accuracy (and if you?re using BigInt my assumption is that you do) then downcasting to a JSON number may result in a loss of fidelity

matt.fellows
2021-03-08 10:24
> ? If we user a string in typescript, the value in generated pact file is in braces (like all strings), which would not be correct I think you mean quotes? i.e. `"`

dominic_herrmann
2021-03-08 10:40
Yes I meant quotes

alan.hanafy
2021-03-08 20:40
probably more of a karma question, but is there a way to set the PactWeb({port:number}) based on the configured value in the karma.conf file? What i mean is: ```//karma.conf.js ... // Pact Providers pact: [ { port: 1234, consumer: "KarmaJasmineConsumer", provider: "KarmaJasmineProvider", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }, { port: 4321, consumer: "KarmaJasmineConsumer", provider: "SecondKarmaJasmineProvider", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }, ], ... // // client-spec.js ... //// //somehow i load karmaPactProviders from the karmaconfig file /// describe("Client", function() { var provider var secondPactProviderPort = karmaPactProviders[1].port beforeAll(function(done) { provider = new Pact.PactWeb({ port: secondPactProviderPort }) ...```

matt.fellows
2021-03-08 22:00
I think you can

matt.fellows
2021-03-08 22:12
I recall looking into it a few years ago when we wrote that adapter

matt.fellows
2021-03-08 22:12
I _think_ one thing that could be done, is to append to the `client` once the plugin starts, which is then made available to the `__karma__` global.

matt.fellows
2021-03-08 22:13
I?m not sure if that is accessible now, a quick google seems to not turn up much, but I don?t use Karma very often so I?m not very familiar with it

mjsmcp
2021-03-08 23:46
has joined #pact-js

javier.garcia_cotado
2021-03-09 21:52
has joined #pact-js

matt.fellows
2021-03-10 03:39
Anyone here using Karma or `pact-web`? If so, we?d appreciate your feedback on https://github.com/pact-foundation/pact-js/issues/626

matt.fellows
2021-03-10 03:40
Tim and I are currently more on the side of ?remove? than keep. It?s going to be a hard call - because the key trade of is ?a lot of effort to update (to latest features) and maintain? vs ?reduced DX for Karma use cases?

tjones
2021-03-10 06:38
Thanks Matt! We?re very interested to hear from users of Karma + pact. I think it?s now much easier to do testing of the API layer without running testing in a browser, but I don?t want to remove support for it if it?s something that people are doing because it?s required by the tools they?re using.

akos.csurai
2021-03-10 13:39
has joined #pact-js

akos.csurai
2021-03-10 14:11
@akos.csurai has left the channel

testme2020testme
2021-03-10 14:12
has joined #pact-js

mjsmcp
2021-03-10 17:05
Our build system runs builds in a jail with no network access, so the postinstall script for `@pact-foundation/pact-node` is failing when it tries to pull the standalone binary from GitHub. Is there a known workaround for this?

tommy.mirchandani
2021-03-10 17:13
has joined #pact-js

mjsmcp
2021-03-10 17:14
Ah, think I found it.

matt.fellows
2021-03-10 20:22
I know there was an issue fixed around this recently, did you get it to work?

mjsmcp
2021-03-10 20:22
I did. Downloading the tar.gz into my build closure did the trick.

varinderjitkaur13
2021-03-11 01:46
has joined #pact-js

francis.lobo
2021-03-11 03:48
Hey folks, Quick question on https://github.com/pact-foundation/pact-js/issues/618 Can someone tell me a rough estimate on when this could be available (I am not looking at exact dates, but more like approx 'X' weeks/months ) This will help us priorities our Pact-js related activities. Cheers!

uglyog
2021-03-11 03:51
The underlying libraries support it, it just needs the JS DSL to be updated.

uglyog
2021-03-11 03:51
Probably be done in about a month

francis.lobo
2021-03-11 04:55
sweet thanks for the update @uglyog. that helps :+1:

krcl.dev
2021-03-11 05:11
has joined #pact-js

mahdi.ali
2021-03-11 09:46
has joined #pact-js

krishnaraoveera1294
2021-03-11 17:53
has joined #pact-js

raghavendra.kalakonda
2021-03-11 23:08
has joined #pact-js

andries.spies
2021-03-12 07:25
has joined #pact-js

kamil.klima
2021-03-12 11:38
has joined #pact-js

lswanborough
2021-03-15 00:50
has joined #pact-js

danhitchcock
2021-03-15 18:21
Hi there, two of my requests to the mock server in my client tests are grumbling about missing the authorisation header, the respond/req with doesn't specify it needs one. Am I missing something basic here? All my other requests don't hit this issue.

don.tobias
2021-03-15 19:35
has joined #pact-js

matt.fellows
2021-03-15 22:43
Can you please share your tests?

matt.fellows
2021-03-15 22:43
I?m wondering if there is some state / sequence issue where previously requests aren?t being cleared.

danhitchcock
2021-03-16 09:35
Will do, sorry for the absence of code.

danhitchcock
2021-03-16 09:48
OK so investigating the code that calls the api, it appears there is a wrapped fetch that takes the response body url (the one I am expecting) and GETs a Csv from said url.

danhitchcock
2021-03-16 09:54
A

matt.fellows
2021-03-16 09:56
aha

matt.fellows
2021-03-16 09:57
so you might need to register 2 expectations for that, or separate it out such that the API calls can be tested separately

danhitchcock
2021-03-16 09:58
In my head that was the process now I know. Do I just add another interaction then I guess?

matt.fellows
2021-03-16 09:59
yep

matt.fellows
2021-03-16 10:00
or as per above, you could separate the two API calls into separate functions (and have a third that combines them still preserving that behaviour) and test them separately

matt.fellows
2021-03-16 10:00
whatever makes the most sense

danhitchcock
2021-03-16 10:04
:thumbsup: Cheers for the help Matt. I imagine this won't be a the first of its kind, splitting the api means precious Dev time so I'll go with your first suggestion and mention it might be an idea to split them. :mechanic: Thank you again for your support :raised_hands:

matt.fellows
2021-03-16 10:06
You mention dev time - is that somebody else or would that also be you doing that? What?s your role in this process?

danhitchcock
2021-03-16 11:33
Someone else, another FE Dev. Guess my role is FE dev/test in this process

sagar.kathuria
2021-03-17 04:25
has joined #pact-js

shao.sum
2021-03-17 08:35
has joined #pact-js

riddhichopra
2021-03-18 01:28
has joined #pact-js

anu.de
2021-03-18 02:28
has joined #pact-js

sreyaslj
2021-03-18 04:25
has joined #pact-js

ashish.joshi
2021-03-18 08:57
Hey Folks :wave: Can anyone help me why am I getting this error in my provider test: `Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer]`      `Pact::ProviderVerifier::SetUpProviderStateError:`       `Error setting up provider state 'xyz-state' for consumer 'my-consumer-abc' at http://localhost:50346/_pactSetup. response status=500 response body={}`

ashish.joshi
2021-03-18 08:58
this is happening for some selected interactions/states for others it is working fine.

matt.fellows
2021-03-18 10:07
if you could please enable `trace` logging and share that? (redacting any sensitive data of course) that would help.

matt.fellows
2021-03-18 10:07
it looks like the provider state `xyz-state` handler you?ve setup is broken

ashish.joshi
2021-03-18 18:44
Hey Matt, trace logs are also similar

ashish.joshi
2021-03-18 18:48
So i have 3 different consumer services which my single provider test is verifying, ? 1st service has 5 interactions, all five are verified, ? 2nd service has 2 interaction, first is passing second failing due to above error ? 3rd service has 3 interactions, second is passing and first and third are failing due to above error

waquino
2021-03-18 20:07
Hi, is anybody using pact-node in arm64?

waquino
2021-03-18 20:07
`255.1 error @pact-foundation/pact-node@10.11.4: The CPU architecture "arm64" is incompatible with this module.`

waquino
2021-03-18 20:07
i?m getting this error when i try to deploy

matt.fellows
2021-03-18 21:35
Are you on the new M1 macs or something else?

matt.fellows
2021-03-18 21:38
Are you sure they?re trace? I?m pretty sure we should be getting more output

matt.fellows
2021-03-18 21:38
what does your code look like?

ashish.joshi
2021-03-18 21:39
I added this line to my Verifier options: `logLevel: 'DEBUG'`

ashish.joshi
2021-03-18 21:50
``` const OPTIONS_BASE = { provider: 'my-provider', providerBaseUrl: url, pactBrokerUrl: 'https://my-pactbroker-link', publishVerificationResult: false, logLevel: 'DEBUG', providerVersion: `${version}`, requestFilter: (req, res, next) => { req.url = req.url.replace( 'unwanted_url_in_some_endpoints', 'required_url_for_some_endpoints' ); req.headers['required_auth'] = 'my-token'; next(); } }; it('should validate following test', () => { return new Verifier({ ...OPTIONS_BASE, ...getStateHandlers(hockInstance, db) }).verifyProvider(); });```

ashish.joshi
2021-03-18 21:52
and `getStateHandlers` is the function which contains all states for respective services and those states points to respective state-handling functions.

waquino
2021-03-18 21:54
something else, this would be an extract of my github actions flow ```name: Build Docker runs-on: ubuntu-20.04 - name: Build and push id: docker_build uses: docker/build-push-action@v2 with: context: . file: ${{ env.DOCKERFILE_PATH }} platforms: linux/amd64,linux/arm64```

matt.fellows
2021-03-18 21:57
I need to see those, because the failure is likely happening there

matt.fellows
2021-03-18 21:57
It's that, or the request filter

matt.fellows
2021-03-18 21:58
Try removing each handler one by one until that specific failure goes away. Then you'll know why

ashish.joshi
2021-03-18 22:00
tried by removing the request filter but it still failed for one of the interaction where req-filter was not required.

ashish.joshi
2021-03-18 22:02
And tried by removing all the interactions except one failing interaction in pact file, it still was not able to setup and didn't ping the provider service

ashish.joshi
2021-03-18 22:06
However, in my state-handler function i am inserting data to database, mocking some internal calls. If i remove those required code from the state-handler function in that case it ping the provider service and throw error saying that data is required in db or that particular internal call is not mocked. but if i add that required mocks/db insertions it fails in pact setup and is not pinging the provider service.

matt.fellows
2021-03-18 22:08
The error doesn't surprise me because we don't test against arm

matt.fellows
2021-03-18 22:08
Do you need to run pact tests in both architectures?

matt.fellows
2021-03-18 22:09
@tjones any ideas? I saw something around M1 the other day.

tjones
2021-03-18 22:11
We don?t have binaries for arm64 yet, so it won?t work. On Mac you can get around it with Rosetta, but I don?t know how it would work with Linux

ashish.joshi
2021-03-18 22:13
```function getStateHandlers(hockInstance, db) { return { stateHandlers: { //consumer-service-1 'consumer-service-1-get-abc': getAbc(hockInstance, db), 'consumer-service-1-post-xyz': updateXyz(hockInstance, db), //consumer-service-2 'consumer-service-2-post-demo': updateDemo(hockInstance, db), 'consumer-service-2-post-cba': UpdateCba(hockInstance, db), 'consumer-service-2-get-jkl': getJkl(hockInstance, db), //consumer-service-3 'consumer-service-3-rollback': rollback(hockInstance, db), 'consumer-service-3-post-qpo': updateQpo(hockInstance, db) } }; }```

matt.fellows
2021-03-18 22:13
Looking at the above, it doesn't seem like a necessary thing for Wellington

matt.fellows
2021-03-18 22:14
Hmm

ashish.joshi
2021-03-18 22:16
this is my `getStateHandlers` function :point_up:, consumer-service-1: all interactions are fine consumer-service-2: only this is working `consumer-service-2-post-cba` other 2 are failing consumer-service-3: this is failing `consumer-service-3-post-qpo`

ashish.joshi
2021-03-18 22:21
the respective handling functions are kept in different file as per different consumer services. Example of such function for one of the failing states: ```function updateDemo(hockInstance, db) { return async() => { const collection = db.collection(REQUIRED_COLLECTION); await collection.insert(MY_DEMORECORD, function(err, result) { if (!err) { console.log('Inserted MY_DEMORECORD'); } }); //mocked call hockInstance .post(`required mock url for internal call`, { body_property1: 'abc', body_property2: 'bcd' }) .any() .reply(200, stub_response, RESPONSE_HEADERS); }; }```

arvind1017
2021-03-18 22:48
has joined #pact-js

matt.fellows
2021-03-18 23:25
might be worth a try/catch and seeing if there is an exception there

matt.fellows
2021-03-18 23:25
I?m fairly confident the `trace` logging should show more than what we?re seeing here

matt.fellows
2021-03-18 23:26
if you comment out the states, does the exception you?re seeing go away? (tthe tests are likely to fail, obviously, but it would at least focus us on the root cause)

ashish.joshi
2021-03-18 23:55
finally try-catch worked and got the issue, there were some variable need to updated, But is weird that we can not see any details on that in any logs, pact verifier should throw some error, at-least stateting something wrong in this state handler function

matt.fellows
2021-03-19 00:06
yeah, I agree

matt.fellows
2021-03-19 00:08
Could you please raise an issue for this on Github? I?ll get that added, should be easy to do and provide better visibility

matt.fellows
2021-03-19 00:09
it?s a poor experience!

ashish.joshi
2021-03-19 00:09
Sure, Thank you Matt :thumbsup:

sushilvc84
2021-03-19 00:30
has joined #pact-js

tjones
2021-03-19 03:34
I?m not sure that Travelling Ruby supports arm64 on Linux. It might not be straightforward to get the binaries

matt.fellows
2021-03-19 04:15
yep, I was thinking the same. Probably another reason to focus on the Rust port

tejakoshti7
2021-03-19 06:26
has joined #pact-js

yannick.adler
2021-03-19 12:44
has joined #pact-js

waquino
2021-03-19 13:11
do you guys recommend me staying away of arm64 for the time being? is there any plan or road map to supported in the future?

matt.fellows
2021-03-19 13:14
No plans, but our plans are largely based on community need - I.e. by you folks. Raise a request on Pact JS and we'll prioritise it there

matt.fellows
2021-03-19 13:14
And yes, I'd steer clear for now

matt.fellows
2021-03-19 13:15
It looks like you run multiple OS tests, so maybe just run the pact ones on Linux for now

waquino
2021-03-19 13:50
Thanks :slightly_smiling_face: i?ll update our tests

kjayachandra2000
2021-03-19 14:09
has joined #pact-js

smith260194
2021-03-19 17:41
@smith260194 has left the channel

aelse
2021-03-19 23:54
has joined #pact-js

eric2323223
2021-03-20 01:35
has joined #pact-js

jordan.r.stewart
2021-03-20 16:07
has joined #pact-js

tmorrison
2021-03-21 21:45
has joined #pact-js

a.chandrasekaran
2021-03-22 00:50
has joined #pact-js

maksym.motornyi
2021-03-22 11:50
has joined #pact-js

gareth.somerville
2021-03-22 12:10
has joined #pact-js

joseph.method
2021-03-22 19:55
has joined #pact-js

dennyg666
2021-03-22 20:54
has joined #pact-js

me1295
2021-03-23 00:15
has joined #pact-js

francis.lobo
2021-03-23 01:27
@uglyog just checking if there is any new news on this? is there any change or delay This will help me keep our plans updated

uglyog
2021-03-23 02:25
Pact-js needs to be updated to support it. That needs to be coordinated with @tjones and @matt.fellows

anchit.99
2021-03-23 09:04
has joined #pact-js

ashish.joshi
2021-03-23 16:25
Issue Added :thumbsup:


wola.adedeji
2021-03-23 16:25
has joined #pact-js

kenny.shobowale
2021-03-23 16:38
has joined #pact-js

victoria.kruczek
2021-03-24 09:42
hello, I hope you have a great day so far :slightly_smiling_face: I?m writing with an issue/question: So I have an endpoint which has to have a parameter, and I don?t know where to add it. I?ve tried on the provider side via `customProviderHeaders` and directly in consumer file by adding params to `uponReceiving` block: ``` params: { filter: {"countryCode":"DE"}, },``` Both of those didn?t do the job and I?m not sure what now. I also tried to add the param directly in the `path` but I get an error back from Pact: ``` Missing requests: GET /api/submissions?filter=[%7B%22countryCode%22:%22PL%22%7D]& Unexpected requests: GET /api/submissions?filter=[%7B%22countryCode%22:%22PL%22%7D]&``` I?ve tried to dig in the docs and https://github.com/pact-foundation/pact-js#provider-state-callbacks, but to be honest, I?m lost after reading it. Guess I?m not so tech advanced :sweat_smile: Can anyone help with this? :pray:

anbu.pandian
2021-03-24 11:54
has joined #pact-js

victoria.kruczek
2021-03-24 13:12
I managed to fix it. The problem was the encoding :facepalm: The solution is that you have to add a `query` to your `uponReceiving` block: ```query: { "filter": "[{\"countryCode\":\"DE\"}]"},```

rachel.barton
2021-03-24 19:12
has joined #pact-js

james522
2021-03-24 22:06
has joined #pact-js

francis.lobo
2021-03-25 00:25
Thanks @uglyog

francis.lobo
2021-03-25 00:26
Hey @tjones / @matt.fellows do you folks have any news on this? I am only looking at rough timelines so that we can align our planning accordingly

matt.fellows
2021-03-25 00:27
I?ll look at it on my next OSS day, which is either tomorrow or early next week

matt.fellows
2021-03-25 00:27
But it might take a week or so of review/feedback etc.

francis.lobo
2021-03-25 00:30
cool. That helps. Thanks @matt.fellows :+1:

anne.schuth320
2021-03-25 07:49
has joined #pact-js

victoria.kruczek
2021-03-25 10:01
hello, hope you have a great day so far :slightly_smiling_face: I have a question regarding negative tests: What I don?t understand is why the console is returning back an error if the expected response is indeed 409? ``` Submissions - delete a submission ? returns data of the created submission (27 ms) ? Pact between App consumer and Submissions API ? with 30000 ms timeout for Pact ? Submissions - delete a submission ? returns data of the created submission Request failed with status code 409``` I feel it?s misleading, because we do expect the 409, so the tests should pass then, right? :thinking_face: Or should I do some extra steps to handle those negative tests in Pact? Here?s the test block for reference: ``` describe('Submissions - delete a submission ', () => { const submissionsExpectedReceivedData = { "code": "Conflict", "message": "Not_deletable", }; const submissionResponse = { status: 409, headers: { 'Content-Type': 'application/json', }, body: submissionsExpectedReceivedData, }; const submissionsDeleteRequest = { uponReceiving: 'a request to delete a submission', withRequest: { method: 'DELETE', path: `/${submissionId}`, headers: { Accept: 'application/json, text/plain, */*', }, }, }; beforeEach(async () => { const interaction = { state: 'i want to delete a submission', ...submissionsDeleteRequest, willRespondWith: submissionResponse, }; return provider.addInteraction(interaction); }); it('returns data of the created submission', async () => { const result = await Submission.delete( provider.mockService.baseUrl, ); expect(result).toEqual(submissionsExpectedReceivedData); }); });```

brendan.donegan
2021-03-25 10:27
Are you sure the error isn?t coming from your client code?

brendan.donegan
2021-03-25 10:27
To me it looks like Pact is doing it?s job and responding with 409 and the client has an issue with that

brendan.donegan
2021-03-25 10:28
You would have to set your test up to make the error ?allowed? as with any other jest test

brendan.donegan
2021-03-25 10:30
``` expect(() => { const result = await Submission.delete( provider.mockService.baseUrl, ); }.toThrow('Request failed with status code 409');```

brendan.donegan
2021-03-25 10:30
Also you could just try/catch

matt.fellows
2021-03-25 10:47
Ah, sorry Brendan! Victoria just joined our Q&A (see #general) and that?s exactly what?s happening. :taco: for a quick response though!

victoria.kruczek
2021-03-25 10:48
Haha, I?m still star struck :smile:

victoria.kruczek
2021-03-25 10:48
thank you! :slightly_smiling_face:

brendan.donegan
2021-03-25 10:59
I?d really love to join but have another meeting :confused: Next one!

victoria.kruczek
2021-03-25 11:00
Done, I went with the try/catch: ``` it('returns data of the created submission', async () => { await SubmissionSDK.delete( provider.mockService.baseurl, ).catch((e) => { expect(e.response.data).toEqual(submissionsExpectedReceivedData); }) });``` thank you again for the help! :slightly_smiling_face:

matt.fellows
2021-03-25 11:07
all good, it was just a 30 min. We?ll do better to advertise next time. It?s no event, it?s just us being there to answer questions and chat!

james.shirtcliffe
2021-03-25 12:04
has joined #pact-js

brendan.donegan
2021-03-25 12:05
I had questions :smile:

brendan.donegan
2021-03-25 12:07
Just FYI that?s the ?Promisey? way of catching, with async/await you would do ```try { await SubmissionSDK.delete( provider.mockService.baseurl, ) } catch (e) { expect(e.response.data).toEqual(submissionsExpectedReceivedData); }```

serhii.makarenko
2021-03-25 12:55
has joined #pact-js

mashabudryte
2021-03-25 14:35
has joined #pact-js

mashabudryte
2021-03-25 14:41
~resolved~

matthew.simon.barnes_
2021-03-25 16:08
has joined #pact-js

sagupta
2021-03-25 16:22
hello team, We have successfully established consumer tests for one provider. Now we are looking to add tests for more providers in the consumer repo. Can someone please share how are they running the tests. ? Do you run mock server in each of the tests per provider or we can run mock server once for all provider tests? ? We are also looking to group all contract tests using a utility called `jest-runner-groups` so that we can run all provider tests in CI with one command. Has anyone tried it ?

joseph.method
2021-03-25 17:33
I have a matcher that looks like this: ```term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } )```

joseph.method
2021-03-25 17:33
I need the escape characters because it?s a string right?

joseph.method
2021-03-25 17:34
But then I?m getting this error when I run the test ```WARN: Ignoring unsupported matching rules {"match"=>"regex", "regex"=>"\\d{4}-\\d{2}-\\d{2}"}```

matt.fellows
2021-03-25 22:59
I?m confused about your question

matt.fellows
2021-03-25 22:59
You don?t use the mock service on the provider side - you need to start your actual provider

matt.fellows
2021-03-25 22:59
I?m not familiar with that tool and the benefits it provides over simply running the pact tests

matt.fellows
2021-03-25 22:59
what are you trying to achieve by ?grouping? them?

abubics
2021-03-25 23:48
kinda sounds like a version mismatch, but I'm pretty sure regex has been around (in Pact) forever :thinking_face:

danhitchcock
2021-03-26 07:04
Missing a trailing slash at a guess, haven't had coffee yet so happy to be wrong :coffee:

abubics
2021-03-26 07:06
These are ruby regexes stored as JSON strings, so unlikely to be related to `/` characters at the start & end :slightly_smiling_face:

danhitchcock
2021-03-26 07:08
Have you got a full copy of the request you can safely share?

jose.manzano
2021-03-26 14:27
has joined #pact-js

sagupta
2021-03-26 15:56
Sorry if My question confused you ,i am talking about consumer tests which setup mock server .I now want to add tests for more providers like Consumer a ?> Provider A Consumer a ?> Provider B Consumer a ?> Provider C So far I have initialized pact mock server with host ,port,pact directory and logs directory in the test for Provider A .If I want to add Provider B tests do I need to initialize pact mock server again or we can define only once and reuse the same pact mock server . Also I would like to have pact files per provider generated so for Provider A ,Provider B and provider C separate . By grouping ,I mean I can tag all these tests with let?s say ?contractTest? so I can just run all by running one command like jest ?group=contractTest

joseph.method
2021-03-26 16:13
The documentation gives as an example `F|M` which would correspond to `/F|M/`

chris.faulkner
2021-03-26 16:13
has joined #pact-js

joseph.method
2021-03-26 16:15
The issue is that I have to escape the `\` so that `\d`isn?t just escaping `d` , but then the `//d` is showing up in the Ruby regexp which is unexpected?

joseph.method
2021-03-26 16:18
e.g. without that double slash I get the error (in Node): `Error: Example '2021-03-01' does not match provided regular expression 'd{4}-d{2}-d{2}'`

joseph.method
2021-03-26 16:21
Okay, I need to stop thinking about the slashes because those are a red herring: `WARN: Ignoring unsupported matching rules {"match"=>"regex", "regex"=>".*"}`

bryanw
2021-03-26 18:46
has joined #pact-js

abubics
2021-03-28 22:55
yeah, "unsupported matching rules" is what I'm more concerned with

joseph.method
2021-03-28 23:22
One important detail is that this is a match inside the query of the request

joseph.method
2021-03-28 23:27
But there is an example in the documentation that matches in the query

abubics
2021-03-29 01:03
Oh, all the matchers in the readme are for body fields . . . I remember matcher support in query params wasn't the same, and maybe came later. I can't even see query params in the readme at all :thinking_face:

abubics
2021-03-29 01:08
https://github.com/pact-foundation/pact-js/blob/62bb7fcf8262bea47617756fa00d72f1561bb766/examples/karma/jasmine/client-spec.js#L64, there's a regex matcher that looks like yours. Can you show us more of your code? (like the whole interaction, or somehting)

joseph.method
2021-03-29 01:31
`provider.addInteraction({ state: 'Invoices are present', uponReceiving: 'request for /api/invoices', withRequest: { method: 'GET', path: '/api/invoices', query: {` `filter: { issued_date: term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) } },` `}, willRespondWith: { status: 200, body: expectedBody, }, });`

joseph.method
2021-03-29 01:32
This is Mocha

abubics
2021-03-29 02:51
that's cool, the Pact DSL doesn't change :slightly_smiling_face:

abubics
2021-03-29 02:51
I have a feeling that query params don't support nesting like that

abubics
2021-03-29 02:51
what does the complete URL look like when that query param is present?

kerem.durak
2021-03-29 08:34
has joined #pact-js

sagupta
2021-03-29 11:10
@matt.fellows Just need your inputs :)

dave.clissold
2021-03-29 12:40
has joined #pact-js

joseph.method
2021-03-29 16:26
ohhhhhh I?ve been thinking in Rails terms

joseph.method
2021-03-29 16:26
`/api/invoices/123?filter[issued_date]=2021-03-01`

joseph.method
2021-03-29 16:27
so I bet I just need to put that in duh

joseph.method
2021-03-29 16:35
Hmm this doesn?t work either: ```query: { 'filter[issued_date]': term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) },```

sidhant.bhayana.15
2021-03-29 18:34
has joined #pact-js

abubics
2021-03-30 00:10
yeah, I think that's a non-standard (but semi-common) convention

abubics
2021-03-30 00:12
someone more familiar with the implementation details and/or spec will need to respond, I'm not sure about it

abubics
2021-03-30 00:14
This is the best docs I can find about it, and it doesn't know anything about that syntax: https://docs.pact.io/getting_started/matching/#query-params

abubics
2021-03-30 00:17
Just bumping this back to the main channel, because I don't know the answer. Is there support for this kind of nested syntax in any pact-consumer version?

matt.fellows
2021-03-30 00:40
hmmm good question

matt.fellows
2021-03-30 00:41
So i?m not surprised that the nesting example above doesn?t work, but I would have expected this to work: ```query: { 'filter[issued_date]': term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) },```

matt.fellows
2021-03-30 00:42
So, all of this aside, it?s first worth asking the question - do you really need a matcher on the query string? Presumably you can control the consumer code, so you don?t need to ?regex? it.

matt.fellows
2021-03-30 00:42
The request matchers aren?t used when the provider is verified, so it?s only for the consumer test

joseph.method
2021-03-30 01:33
Hmm that's true. The underlying fixture data is created in the providerstate with the current month but it could be hardcoded to the value instead

matt.fellows
2021-03-30 01:36
> WARN: Ignoring unsupported matching rules {?match?=>?regex?, ?regex?=>?.*?} @bethskurrie might know more. I know these warnings aren?t always correct

matt.fellows
2021-03-30 01:37
If you could share the Pact, I could eyeball it to double check it?s being serialised correctly

uglyog
2021-03-30 01:45
are you referring to the query parameter array syntax?

abubics
2021-03-30 01:50
yep, and there's more discussion in the thread

bethskurrie
2021-03-30 02:28
```{ filter: { issued_date: term( { matcher: '\\d{4}-\\d{2}-\\d{2}', generate: '2021-03-01' } ) } },```

bethskurrie
2021-03-30 02:28
I don't think that format is supported in JS

bethskurrie
2021-03-30 02:28
I think you'll need to use the square bracket format.

bethskurrie
2021-03-30 02:29
But that is a super flakey area because of the way params are serialized and deserialized differently by every language/server.

bethskurrie
2021-03-30 02:31
Can you make a reproduction of the issue by forking pact-js and modifying one of the examples please @joseph.method

matt.fellows
2021-03-30 02:32
> I don?t think that format is supported in JS Yeah I?ve never tried it. The serialiser should recurse the object and add the matchers, but not sure the HTTP mock service knows what to do. At least, it?s untested

matt.fellows
2021-03-30 12:08
> So far I have initialized pact mock server with host ,port,pact directory and logs directory in the test for Provider A .If I want to add Provider B tests do I need to initialize pact mock server again or we can define only once and reuse the same pact mock server . It?s recommended to have a separate mock for each. This way, those tests could be run in parallel (if you wanted to) but it?s less complicated. You can re-use the same one, but it will just result in confusing test code

matt.fellows
2021-03-30 12:09
With the grouping tool, that?s up to you and how you arrange them. If it?s helpful, go for it

sagupta
2021-03-30 16:23
```It's recommended to have a separate mock for each. This way, those tests could be run in parallel (if you wanted to) but it's less complicated. You can re-use the same one, but it will just result in confusing test code``` So that means , I need to run them on different ports also right

crhawkins85
2021-03-30 21:02
has joined #pact-js

matt.fellows
2021-03-30 21:14
correct

matt.fellows
2021-03-30 21:14
I tend not to specify ports, and let the framework pick a free one

matt.fellows
2021-03-30 21:15
that way, you don?t need to worry about port conflicts on CI etc.

pranav.gore
2021-03-31 01:58
has joined #pact-js

sagupta
2021-03-31 07:14
nice yea that makes sense, i will try it out then like this

matt.fellows
2021-03-31 08:58
:+1:

harsha6988
2021-03-31 12:19
has joined #pact-js

harsha6988
2021-03-31 12:23
I am using provider verification as : ```return new Verifier(opts).verifyProvider().then(output => { console.log("Pact Verification Complete!") console.log(output) })``` in my source code.. While executing this in my local - mac os - it is verifying the pact properly. However when same code i am trying to execute in bitbucket pipeline.. it is giving an error as: `1) Pact Verification` `Should validate the consumer:` `Error: /opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.40/pact/lib/ruby/bin/ruby: line 6: /opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.40/pact/lib/ruby/bin.real/ruby: No such file or directory` `at ChildProcess.<anonymous> (node_modules/@pact-foundation/pact-node/src/verifier.ts:272:55)` `at maybeClose (internal/child_process.js:1021:16)` `at Socket.<anonymous> (internal/child_process.js:443:11)` `at Pipe.<anonymous> (net.js:674:12)`

matt.fellows
2021-03-31 13:22
Running on Alpine linux?

matt.fellows
2021-03-31 13:23
Check out the docs

harsha6988
2021-03-31 13:54
Yes

leixu
2021-03-31 14:42
has joined #pact-js

matthew.brown
2021-03-31 15:15
has joined #pact-js

oleksandr.tryshchenko
2021-03-31 19:54
has joined #pact-js

matt.fellows
2021-03-31 23:23
See the docs on alpine linux on JS repo/docs.pact.io

phelantomas
2021-04-01 13:13
has joined #pact-js

ktogias
2021-04-01 20:04
has joined #pact-js

balaji.sivakumar
2021-04-02 05:41
has joined #pact-js

jayson.bailey
2021-04-02 20:31
Probably a dumb question, but is there any good documentation/examples on setup? I have `const provider = new Pact({..})` in several `.test.pact.ts` files and whichever is run last overrides the previous pact output file, so I only end up with those interactions in it.

ktogias
2021-04-03 11:51
Hi. I solved this problem by putting all my tests in the same suite and initializing the provider in beforeAll. Then on each test i add the corresponding ingeraction to the provider. This way I get a Pact file containing all the interactions. I had to put all tests in the same spec.js file. I don't know if a suite can be split in multiple files.


matt.fellows
2021-04-03 21:52
You can split across tests

jayson.bailey
2021-04-05 14:40
Thanks for the replies!

uryadov212
2021-04-05 20:52
has joined #pact-js

soumya.aithal966
2021-04-05 22:45
has joined #pact-js

francis.lobo
2021-04-05 22:56
Hello @matt.fellows did you get a chance to look into this one?

tjones
2021-04-06 00:08
Also, which testing framework are you using? `jest-pact` solves some of this for Jest, and we have some better config for everyone in the roadmap


sheyan.rizfee
2021-04-06 00:55
has joined #pact-js

matt.fellows
2021-04-06 04:23
Hi Francis! Apologies, I didn?t get the OSS day I was hoping for last week, and it?s been a long weekend here in Australia. I?ll be looking at this tomorrow.

francis.lobo
2021-04-06 04:58
Thanks @matt.fellows

greg719
2021-04-06 09:23
has joined #pact-js

piotr
2021-04-06 09:24
has joined #pact-js

greg719
2021-04-06 09:25
hey just wanted to confirm. If I omit port in PactWeb configuration then it will take a random port based on provider name correct?

matt.fellows
2021-04-06 09:47
Not in pact web

matt.fellows
2021-04-06 09:48
It can't communicate to the mock server without knowing the port (because it's designed to run in a browser, so can only communicate via http)

matt.fellows
2021-04-06 09:48
Do you really need to us pact web? We're thinking of dropping support for it if I'm honest, but keen for feedback

dmitry.korolev
2021-04-06 11:47
has joined #pact-js

greg719
2021-04-06 12:56
what should i use then?

matt.fellows
2021-04-06 13:28
Just straight pact (not the pact web variant) with mocha/jest/...

matt.fellows
2021-04-06 13:28
Is there a reason you went for Pact Web?

greg719
2021-04-06 13:34
i think we were lead by examples / documentation (maybe old one)

greg719
2021-04-06 13:35
right now we migrating to NX that is using Jest

greg719
2021-04-06 13:36
ok confirmed in new NX we do not use PactWeb

greg719
2021-04-06 13:36
so to confirm, this one does not need the port right?

sravyavadrevu988
2021-04-06 20:40
has joined #pact-js

johnnycareer
2021-04-06 21:34
has joined #pact-js

matt.fellows
2021-04-07 00:58
that?s correct

matt.fellows
2021-04-07 00:58
it should return the server details in the promise returned from `setup()`

matt.fellows
2021-04-07 00:58
If you could find any docs/examples you used as a basis for your tests, that would be helpful.

matt.fellows
2021-04-07 00:58
I suspect there are many people using PactWeb incorrectly (despite it not being advertised widely at all)

matt.fellows
2021-04-07 01:47
Looking at this now Francis

matt.fellows
2021-04-07 01:47
:crossed_fingers: it?s not a massive thing. Might take a few iterations to get it right, but let?s see how we go!


matt.fellows
2021-04-07 06:08
the e2e test has an example using it

francis.lobo
2021-04-07 06:15
Woohoo awesome :party_parrot: Will give it a squiz and get back to you early next week Thanks heaps @matt.fellows

yousafn
2021-04-07 08:36
Anyone been messing about with deno? I?ve recently heard about it over the last few weeks and it keeps cropping up so I am going to have a play at the weekend building some bits and bobs and want to have a look at if pact can work in deno land

matt.fellows
2021-04-07 11:38
Apart from looking at it and thinking ?shit, more interop to be concerned about? no :stuck_out_tongue:

matt.fellows
2021-04-07 11:39
It seemed to make a big noise 6 or so months ago (I dunno with Covid, my sense of time is broken). But haven?t heard much of it recently myself

matt.fellows
2021-04-07 11:40
Definitely keen to see how the interop goes. The biggest risk would be the interface to the Ruby process. I?m not sure if it has the same install stages, which is how we download and extract the CLI. It should have a way to invoke an external process, so should be ok

matt.fellows
2021-04-07 11:40
the new v3 branch with Rust will be interesting. I?d suspect it currently wouldn?t work, because it?s tied to the current node ABI, which I?m assuming is not going to be compatible with Deno (or at least, there be dragons()

matt.fellows
2021-04-07 11:41
This should change, as we?re looking to use more of an FFI style binding, so it should just delegate to standard OS syscalls. But that might be node specific as well :man-shrugging:

matt.fellows
2021-04-07 11:41
TL;DR - keen to hear how you go :slightly_smiling_face:

danil.nurgaliev
2021-04-07 12:26
has joined #pact-js

yousafn
2021-04-07 12:27
They just announced some major funding and have launched as a company, so it might be making some more noise. It uses rust so yeah working with v3 would probably be the plan. I?m just interesting to dip my toe in the water and see whats what. Started looking at the testing framework but the docs were down, but noted some nice fellows have built jest like wrappers so it feels nice and familiar

yousafn
2021-04-07 12:27
Thanks for the feedback Matt, will deffo ping along some links to examples and can build on them from there

matt.fellows
2021-04-07 12:30
Awesome!

matt.fellows
2021-04-07 12:30
Love that you can get stuck into it!

matt.fellows
2021-04-07 12:30
I recall the Rust thing, I think Ron?s ears pricked up when we heard it

matt.fellows
2021-04-07 12:30
Makes a lot of sense for a core engine, because it?s so stable

yousafn
2021-04-07 12:35
I know nothing of Rust, but my tech lead peer raved about it and created a game called Rusticles, so I am very curious to peer under the sheets!

yousafn
2021-04-07 18:37
Got a deno example of the pact-workshop-js provider https://github.com/YOU54F/deno-examples having a look at the react consumer now, and then can add some unit tests and try out pact :)

yousafn
2021-04-08 00:28
This reminds me a lot of the early days of flutter Very experimental apis :joy: Knocked together a very very basic react app that can call the provider api?s, not styled up or tested bar manually. Got the provider covered with a unit test or two. That was a fun little tinker, enjoyed it so far!

tjones
2021-04-08 03:26
I read the original Deno pitch thingy and liked the ideas but thought "this will never catch on". Full disclosure, that's what I thought about node too.

tjones
2021-04-08 03:27
On the one hand I hope it catches on, because it has some really nice ideas that I like much more than the way node works. On the other hand, I share the same reservations about interop as Matt.

tjones
2021-04-08 03:33
I'd love to hear what you think after working with it for a bit, especially if you're trying out pact.

gtsifrikas
2021-04-08 08:53
has joined #pact-js

kanapuramamarnath
2021-04-08 09:18
has joined #pact-js

arnaud.dutrillaux
2021-04-09 10:59
has joined #pact-js

gsinghania
2021-04-09 15:40
has joined #pact-js

souravmohanty35
2021-04-09 16:34
has joined #pact-js

itzdavey
2021-04-09 17:23
has joined #pact-js

tmorrison
2021-04-11 18:45
:wave: Hi all! Pretty new to the Pact community. I saw @matt.fellows present during TestJS Summit and have been working on a POC implementation for my company based on @yousafn awesome repo.

yousafn
2021-04-11 18:52
Welcome dude, glad that repo has been useful! Where do you work?

tmorrison
2021-04-11 18:55
I work at Ally Bank. I'm a frontend tech lead, but also heavily involved in our overall test automation. Our org uses quite a few tools for testing APIs, including Watchman, but I'm working on a pitch to make Pact our new go-to.

yousafn
2021-04-11 20:31
Amazing! Looking forward to hearing about your journey. I am loving working with developers who are so passionate about testing, my place is chock full of them.

tmorrison
2021-04-11 20:35
*QUESTION:* Is https://github.com/pact-foundation/jest-pactnecessary if you have other ways of instantiating `PactOptions` and ensuring the boilerplate is setup properly? *CONTEXT:* I'm a big fan of the https://nx.dev/ monorepo dev tools. I'm thinking about building a community plugin that extends `@nrwl/jest` to setup Pact within a monorepo

yousafn
2021-04-11 20:40
It?s not no, it makes it easier but you can do that yourself with pact js and some helper files. Your context seems really sound, it would be nice to have it as a plugin for easy consumption in nx.

tmorrison
2021-04-11 20:47
Awesome! I started using `jest-pact` based on your example but I think it need to use vanilla `pact-js` to really maximize the executors Nrwl team created. Also it seems like the setup / teardown on each script will be a little more explicit this way.

matt.fellows
2021-04-12 01:37
Welcome Tyler, and so glad the talk was helpful

matt.fellows
2021-04-12 01:38
> Our org uses quite a few tools for testing APIs, including Watchman, but I?m working on a pitch to make Pact our new go-to. So cool! Let us know how we can help.

matt.fellows
2021-04-12 01:39
This Nx thing keeps coming up - I best get across it :stuck_out_tongue:

matt.fellows
2021-04-12 01:39
I should note, we are worknig on a v3 of Pact JS right now (see an early draft of the roadmap here: https://github.com/pact-foundation/pact-js/projects/3)

matt.fellows
2021-04-12 01:40
If you?re looking to extend Pact, we should talk about how we provide the needed hooks in the latest version, as the API will change a little bit

matt.fellows
2021-04-12 01:40
It?s currently in an early https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/, but is used by a number of customers globally (it supports XML, and a bunch of the new v3 matchers)

matt.fellows
2021-04-12 01:41
we?re reworking the way we integrate into the new Rust core engine, which will modify the external facing interface

abubics
2021-04-12 02:02
btw, the super-short answer is: no, jest-pact is not necessary (it's just a DSL wrapper for pact-js) :party_parrot:

tjones
2021-04-12 05:49
What's this Nrwl thing?

tjones
2021-04-12 05:53
> Also it seems like the setup / teardown on each script will be a little more explicit this way. Yes. The main feature of jest-pact is to ensure that the setup / teardown and other jest-specific options are done correctly each time. If you prefer to be explicit about this, then jest-pact is not for you.

tjones
2021-04-12 05:53
(also you will need to be careful to set the things that jest requires, eg `pactWriteFileMode: 'update'`)

brendan.j.donegan
2021-04-12 06:25
Afaik Nrwl are the company that develop Nx


tjones
2021-04-12 06:26
I haven't really found anything substantial for "nrwl pact" in google

tjones
2021-04-12 06:33
(also thanks! However, I still can't find any link between them and pact)

audun.halland
2021-04-12 08:50
@audun.halland has left the channel

greg719
2021-04-12 09:43
I will mention it in my videos going forward :wink:

matt.fellows
2021-04-12 09:54
Ah, you're _that_ Greg - hi :rolling_on_the_floor_laughing:

greg719
2021-04-12 09:56
howdy

tmorrison
2021-04-12 13:34
@tjones TL;DR - No link exists at the moment, but I'm working to change that. Longer version? Nx provides a framework agnostic set of tooling that greatly improves monorepo development. They provide a set of https://nx.dev/latest/react/core-concepts/plugins for the major frameworks ? React, Angular, etc. But they also make it easy for the community to build plugins. In this case, I would like to build a community plugin that extends their core plugin `@nrwl/jest` so that Nx users could easily scaffold Pact tests for either a consumer or a provider

tjones
2021-04-12 22:39
Awesome!

tjones
2021-04-12 22:39
If it's incompatible with jest-pact, let's figure out why and then work to change that

tjones
2021-04-12 22:39
(on whichever side makes sense)

tjones
2021-04-12 22:41
Also, have a look at the config pitch here: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-04-12 22:41
I was tempted to put a lot of config niceties into jest-pact, but chose not to because if we do it in the main package then everyone can benefit

tjones
2021-04-12 22:42
Let me know if I can help in any way

laura.edington
2021-04-13 17:45
has joined #pact-js

liam.mcdermott
2021-04-13 22:38
has joined #pact-js

francis.lobo
2021-04-14 01:31
Hello folks! I need some help using the V3 regex matchers I tried using the following patter in my consumer tests, ``` const apiPathExample = '/api/client/0A050891038CFAFC/copy'; const apiPathMatcher = '/api/client/[A-Z0-9]+/copy'; const interaction: InteractionObject = { .... withRequest: { path: MatchersV3.regex(apiPathMatcher, apiPath), } }``` And ended up with error : `Failed: "{\"message\":\"Error ocurred in mock service: NoMethodError - undefined method `+' for #<Hash:0x3dc6c80>` followed by a ruby stacktrace. I am assuming I am not writing the regex pattern in the right format as expected by the underlying ruby matcher. Also tried escaping the backslashes but that didnt help either `\/api\/client\/[A-Z0-9]+\/copy` I am not very familiar with ruby regex format. Any help in understanding this will be really great. I was using the same patter with v2 matcher.term() but looks like term is not supported in v3. hence trying to use regex

abubics
2021-04-14 01:49
probably don't need to escape the [forward] slashes (`/`) but if it's genuinely falling over on the `+`, it might need to be escaped?

abubics
2021-04-14 01:50
https://rubular.com/ is a good place to play with Ruby regex, if that helps

francis.lobo
2021-04-14 01:51
thanks will try that

matt.fellows
2021-04-14 01:58
The v3 stuff doesn?t use the Ruby engine anymore - they should just be a regular POSIX regex (I think)

matt.fellows
2021-04-14 01:59
buuuut? that does look like a Ruby error

matt.fellows
2021-04-14 01:59
are you using the V3 matchers with the v2 code base? Could you please share the wider code context here?

francis.lobo
2021-04-14 03:28
ah yes! I think that could be the issue.. I had built the test from V2 examples, while trying to move to V3, I have only replaced the Matchers and completely missed out changing the mock server setup.

matt.fellows
2021-04-14 03:29
cc @tjones. :point_up: we need to constrain this sort of thing in our v3 launch

tjones
2021-04-14 03:32
I have a vague plan for this!

matt.fellows
2021-04-14 03:32
I feel types themselves will solve many of the problems (i.e. a v3 scoped matcher shouldn?t fit into a v2 shaped hole)

matt.fellows
2021-04-14 03:33
but the API itself could adress

tjones
2021-04-14 03:33
Aren't we pact-js? What types?

tjones
2021-04-14 03:34
(I don't think we can rely on typescript types to solve our problems completely)

tjones
2021-04-14 03:34
although the types are better in V3

tjones
2021-04-14 03:34
https://github.com/pact-foundation/pact-js/issues/611 ^ I think if we implemented this, we could extend it to know the appropriate matchers for the appropriate interactions

tjones
2021-04-14 03:35
(that's my vague plan)

johnnycareer
2021-04-14 07:34
@johnnycareer has left the channel

kjayachandra2000
2021-04-14 10:39
Hi :wave: All, I have a consumer to be verified by a provider consumer : `cities:{VAL:{name:"India",displayName:"India",countryCode:"IN"}},countries:{IN:{name:"India"}}` provider: `{cities:{DXB:{name:"Dubai",displayName:"DUBAI",countryCode:"AE"}},countries:{AE:{name:"Dubai"}}}` how to add the regular expression for the consumer and the items can be more than 1 item

matt.fellows
2021-04-14 11:10
You'll need to use the new beta v3 branch, which has an `eachKeyLike` matcher, because the keys change

matt.fellows
2021-04-14 11:11
It's like the `eachLike` but for keys that can change instead of the values

wedlaaa
2021-04-14 13:33
has joined #pact-js

kjayachandra2000
2021-04-14 15:24
Hi Matt, thanks, but still i am getting assertion error

lewis.thorley
2021-04-14 21:57
Out of interest - is it possible to conduct a pact test with FormData()? In jest FormData is not defined as it is not part of the jsdom environment. Mocking the global FormData has only ended badly for me as axios did not like the mocked object.

lewis.thorley
2021-04-14 22:07
Figured this out - will write up tomorrow if anyone is interested

wderksen
2021-04-14 22:26
has joined #pact-js

abubics
2021-04-15 01:49
I'm more interested in your use case . . . FormData and jsdom sound like presentation-layer concepts, I wouldn't expect them to be relevant to Pact testing :thinking_face:

mail_4brad
2021-04-15 02:34
has joined #pact-js

lewis.thorley
2021-04-15 06:32
It?s because formData is required to send multi part form data in JS as far as I understand.

abubics
2021-04-15 07:12
I guess, if you have a hard constraint on mutipart/form-data, then that's reasonable :slightly_smiling_face: that use case is common for large uploads, but not much else, and we tend to contract test those less, and limit them to not include other kinds of data in the upload (such as text fields)

abubics
2021-04-15 07:13
That's more what I meant in my original Q, what's the use-case that's pushing you to use FormData in the first place? (or multipart/form-data at the API side)

tjones
2021-04-15 07:49
Does your header return the trailing `;`? I'm not sure that's valid.

tjones
2021-04-15 07:49
Also, this is the channel for pact-js, but you're getting a Java error. Should you be in #pact-jvm?

francislainy.campos
2021-04-15 07:55
Hi, I was actually on pact jvm first but was asked to move the message here. :slightly_smiling_face:

francislainy.campos
2021-04-15 07:55
I?ll check the ; piece. Thanks.

tjones
2021-04-15 07:57
Regardless of how you got here, the contract should state the exact header that your service returns. I think that `application/json;` isn't valid, because `;` is the separator that indicates there's a parameter, but there's no parameter.

tjones
2021-04-15 07:58
This is the section of the spec that defines the content-type field: https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7

francislainy.campos
2021-04-15 07:58
Yes, you?re spot on. I removed that and the tests worked fine. Thanks very much.

tjones
2021-04-15 07:58
You're welcome!

lewis.thorley
2021-04-15 08:14
I am uploading a single file to an API

lewis.thorley
2021-04-15 08:15
My next fun challenge is that axios is making my request body dynamic: ``` "body": '----------------------------892025258273260351389190\r\nContent-Disposition: form-data; name="image"\r\n\r\n{"type":"image/jpeg","file":"blobby"}\r\n----------------------------892025258273260351389190--\r\n' ```

lewis.thorley
2021-04-15 08:16
and that's how the body needs to look otherwise the provider will fail

lewis.thorley
2021-04-15 08:16
starting to think pact may not be best for this scenario :thinking_face:

abubics
2021-04-15 08:58
Looks like https://github.com/pact-foundation/pact-jvm/issues/123 (to JVM at least) 4 years ago

lewis.thorley
2021-04-15 08:59
that's really helpful thank you

abubics
2021-04-15 08:59
It's kind of on the edge (for me) of what should be contract tested, because the content is basically irrelevant, and verifying its format is testing the HTTP library that encodes it.

lewis.thorley
2021-04-15 09:00
yeah I suppose the only thing that is making it valid for me is that our controller is validating the file

lewis.thorley
2021-04-15 09:00
so we need to verify the body

abubics
2021-04-15 09:01
The fact that a valid one will return one response, and an invalid one will return another is what is relevant, but you can't quite separate the (de)serialisation from the other parts of the interface boundary

abubics
2021-04-15 09:03
You don't actually need to verify the body, right? It just need to not crash the conversion to/from an octet stream. You can theoretically avoid verifying the body with states like "valid file" and "invalid file".

lewis.thorley
2021-04-15 09:07
yeah that's it - as long as it hits the controller and we can read the content type from the multi-part request it's fine

abubics
2021-04-15 09:09
Sometimes it's not worth picking that apart, so you just let the framework do more than it needs to :sweat_smile: but good to narrow down which bits are actually relevant :party_parrot:

rodrigo.costa20
2021-04-15 12:08
hey guys! I'm using pact-js for a test on consumer-side and the test works well... however, when I try to run the tests on the CI Tool (bamboo), I keep getting this error "Postinstalled Failed Unexpectedly: Error downloading binary from https://github.com/pact-foundation/pact-ruby-standalone/releases/download ..." and I think this error is probably because the computer where the bamboo runs, is not able to access any external url, so I think when its try to access github, the error is presented. do you guys know what I can do to workaround it? using proxy on CI its not an option in this case


goncalosamuel
2021-04-15 15:08
has joined #pact-js

matthew.hall
2021-04-15 17:36
has joined #pact-js

raony
2021-04-15 19:21
has joined #pact-js

gupta.ratnesh9
2021-04-16 04:48
has joined #pact-js

greg595au
2021-04-16 10:00
has joined #pact-js

manel_ben_yahia
2021-04-16 13:59
has joined #pact-js

kmckeever
2021-04-16 19:26
Hey Rodrigo, we were experiencing this at my organization, and there are a couple ways to handle this. 1. You can include the binary with your repository and specify the pact download location to where your binary is located OR... 2. The preferred approach, and the one we went with: Get your corporate IT to whitelist GitHub URLs, as well as any redirects made by the GitHub URL you posted for the pact binary. If you curl that URL, it should expose what those redirects are, so you can whitelist those.

kmckeever
2021-04-16 19:31
Hey there :wave: Say my provider validation needs me to query for a unique key that changes often and use it to update a property value in the payload for the provider before executing the verification. How would I go about doing this? Is this where provider states come into play? I'm a little hazy on how that would work here.

matt.fellows
2021-04-17 01:11
Provider states are ideally suited to setting up data to match a particular request

matt.fellows
2021-04-17 01:12
If you need to be able to replace a path id e.g. `/users/1234` with `/users/5678` at provider verification time, there is a v3 feature for this: https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/provider-state-injected/consumer

matt.fellows
2021-04-17 01:13
you?ll need to use the v3 project for that: https://github.com/pact-foundation/pact-js#pact-js-v3


maxence
2021-04-17 11:07
has joined #pact-js

kranti.deep
2021-04-17 14:17
has joined #pact-js

aaronw153
2021-04-17 21:42
has joined #pact-js

github
2021-04-19 00:57
GitHub app is successfully upgraded in your workspace :tada: To receive notifications in your private channels, you need to invite the GitHub app `/invite @GitHub`

kranti.deep
2021-04-19 06:59
@kranti.deep has left the channel

dwmahieddine
2021-04-19 12:44
has joined #pact-js

kmckeever
2021-04-19 13:45
I mean to include the instructions for 1! Apologies for that: https://www.npmjs.com/package/@pact-foundation/pact-node/v/10.5.0#installation

garrettmichael
2021-04-19 18:34
has joined #pact-js

daniel.kalleward
2021-04-20 08:16
has joined #pact-js

mattias.persson
2021-04-20 12:45
has joined #pact-js

martin.eklund
2021-04-20 12:47
has joined #pact-js

parveenbanu
2021-04-20 14:43
Hi Friends

parveenbanu
2021-04-20 14:43
I am working on Pact recently.

parveenbanu
2021-04-20 14:44
I have downloaded the base of my API Services and developed Pact scripts with help of consumer and provider.

parveenbanu
2021-04-20 14:44
locally it is running successfully.

parveenbanu
2021-04-20 14:44
While i try to push the code to GITLAB it is returning error

parveenbanu
2021-04-20 14:45
npm run test:consumer https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L247 > business-services-core@0.1.23-rc.3 test:consumer /builds/parveenbanu/business-services-core https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L248 > mocha --timeout 200000 __tests__/contractTesting/consumer.spec.js https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L249 [2021-04-20 14:02:09.262 +0000] INFO (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Creating Pact Server with options: https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L250 {"consumer":"BusinessServicesClient","cors":false,"dir":"/builds/parveenbanu/business-services-core/pacts","host":"127.0.0.1","log":"/builds/parveenbanu/business-services-core/logs/pact.log","pactFileWriteMode":"overwrite","provider":"CommentsAPI","spec":2,"ssl":false} https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L251  Pact with Order API https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L252 [2021-04-20 14:02:09.308 +0000] ERROR (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Pact Binary Error: /builds/parveenbanu/business-services-core/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/ruby/bin/ruby: line 6: /builds/parveenbanu/business-services-core/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/ruby/bin.real/ruby: No such file or directory https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L253 [2021-04-20 14:02:09.310 +0000] WARN (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Pact exited with code 127. https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L254 [2021-04-20 14:02:09.310 +0000] INFO (204 on runner-5500aa76-project-3152-concurrent-1): pact-node@10.12.2: Removing Pact process with PID: 211 https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L255  1) "before all" hook in "Pact with Order API" https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L256  2) "after all" hook in "Pact with Order API" https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L257  0 passing (30s) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L258  2 failing https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L259  1) Pact with Order API https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L260  "before all" hook in "Pact with Order API": https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L261  Error: Pact startup failed; tried calling service 10 times with no result. https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L262  at retry (node_modules/@pact-foundation/pact-node/src/service.js:170:33) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L263  at Server.check (node_modules/@pact-foundation/pact-node/src/service.js:180:17) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L264  at listOnTimeout (internal/timers.js:554:17) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L265  at processTimers (internal/timers.js:497:7) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L266  2) Pact with Order API https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L267  "after all" hook in "Pact with Order API": https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L268  TypeError: Cannot read property 'writePact' of undefined https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L269  at Pact.finalize (node_modules/@pact-foundation/pact/src/httpPact.js:124:14) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L270  at Context.<anonymous> (__tests__/contractTesting/consumer.spec.js:52:24) https://gitlab.anbetrack.com/parveenbanu/business-services-core/-/jobs/366227#L271  at processImmediate (internal/timers.js:461:21)

parveenbanu
2021-04-20 14:45
can some one help me on this.

enda.brody
2021-04-20 17:37
has joined #pact-js

cristian.moisa
2021-04-20 18:25
has joined #pact-js

kmckeever
2021-04-20 19:25
Thanks, Matt! I'm giving V3 a go, but butting up against the infamous Windows long path issue, resulting in the below error: `Pact Binary Error: C:/myOrg/myApp-ui/myOrg/node_modules/@pact-foundation/pact/node_modules/@pac` `t-foundation/pact-core/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.8.0/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': can` `not load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError)` In investigating, I saw in this thread you mentioned V3 resolved the issue, but V3 seems to be what is causing it for me. I am using the latest version, 10.0.0-beta.34. If I am using V2, this issue doesn't present itself. https://github.com/pact-foundation/pact-js-core/issues/250 The path to the specified ruby file is < 260 characters, so I'm a little stumped. Any ideas as to how to overcome this?

kmckeever
2021-04-20 20:55
Hey there Parveen. That error looks to indicate that the binary doesn't exist on your runner. Are you performing an `npm install` or `npm ci` prior to running your test?

bheemreddy181
2021-04-20 21:24
@ckhadilkar Ask your questions on jest here

matt.fellows
2021-04-20 21:38
It looks like the alpine Linux issue. The fix is documented on the pact JS docs page and on http://docs.pact.io

matt.fellows
2021-04-20 22:08
Hi Kerry, you need to use the new v3 package imports (j.e. the new API), not the new package with the exisiting interface which still uses Ruby)

matt.fellows
2021-04-20 22:09
I.e. `require('@pact-foundation/pact/v3')`

kmckeever
2021-04-20 22:52
Thanks, Matt! Is GraphQLInteraction() part of the V3 specification yet? I'm not seeing as part of the API. Sorry for all the questions!

bheemreddy181
2021-04-21 00:14
Pact Consumer tests fails randomly have any one seen this ```FAIL tests/unit/contracts/api.pact.spec.ts SMB API Pact test get account account exists and token is valid ? returns account details (83ms) account exists and token is invalid ? returns 401 (38ms) get loans by account an account with loans ? returns all loans (66ms) an account with no loans ? returns no loans (58ms) get loan ? returns current loan details (63ms) ? SMB API Pact test ? get loans by account ? an account with no loans ? returns no loans Request failed with status code 401 at createError (node_modules/axios/lib/core/createError.js:16:15) at settle (node_modules/axios/lib/core/settle.js:17:12) at XMLHttpRequest.handleLoad (node_modules/axios/lib/adapters/xhr.js:62:7) at IncomingMessage.<anonymous> (node_modules/request/request.js:1076:12)```

bheemreddy181
2021-04-21 00:15
logs says it was able to generate contract file successfully and nothing errored in pact.log file

darccide
2021-04-21 01:35
has joined #pact-js

tjones
2021-04-21 02:01
I don?t think this a pact error- looks like you have an extra request firing. Is there maybe something else running during your test, or something that is bypassing the mock? If you can share your test code, we can take a look

matt.fellows
2021-04-21 02:17
Ah! No, that?s a good question

matt.fellows
2021-04-21 02:18
I?ll see if I can add that today/tomorrow in my OSS time

bheemreddy181
2021-04-21 02:32
Attaching the test file here

bheemreddy181
2021-04-21 02:33
@tjones weird part is each time a different test fails and at times it passes locally at times it doesn't

bheemreddy181
2021-04-21 02:33
mostly our CI has failures consistently

bheemreddy181
2021-04-21 02:34
here is another run which shows a different failure

bheemreddy181
2021-04-21 02:34
```FAIL tests/unit/contracts/api.pact.spec.ts SMB API Pact test get account account exists and token is valid ? returns account details (83ms) account exists and token is invalid ? returns 401 (44ms) get loans by account an account with loans ? returns all loans (61ms) an account with no loans ? returns no loans (63ms) get loan ? returns current loan details (15ms) ? SMB API Pact test ? get loan ? returns current loan details Request failed with status code 401 at createError (node_modules/axios/lib/core/createError.js:16:15) at settle (node_modules/axios/lib/core/settle.js:17:12) at XMLHttpRequest.handleLoad (node_modules/axios/lib/adapters/xhr.js:62:7) at IncomingMessage.<anonymous> (node_modules/request/request.js:1076:12)```

parveenbanu
2021-04-21 05:01
Thanks for the reply.. i will check with your solution and let you know what happened

tjones
2021-04-21 05:15
I haven?t had the chance to look yet, but if that?s the symptom I suspect there might be promises that aren?t being waited for correctly

matt.fellows
2021-04-21 05:37
I may have misread your initial question sorry Kerry. The v3 stuff certainly might help, but usually you don?t need that property. And yes, provider states are usually part of this

matt.fellows
2021-04-21 05:38
Could you please elaborate a bit on the scenario?

matt.fellows
2021-04-21 05:38
e.g. let?s say you need for a ?User with id 1234? to be in the database prior to execute a ?GET /user/1234" to some endpoint

matt.fellows
2021-04-21 05:38
the provider state might be `user with ID 1234` exists

matt.fellows
2021-04-21 05:39
when the provider tests execute, you can use a state handler to ensure user `1234` exists, prior to that scenario running

tjones
2021-04-21 08:19
So, I think it?s definitely a promise problem. There?s some inconsistency in the way promises are handled in these tests - some functions are declared as `await`, but don?t await anything (these do return the promise, though). I don?t know what framework you?re using, and what its expectations around promises are, but I would definitely update the tests to make it consistent. Also, `provider.finalize()` returns a promise, so you?ll definitely need to await this.

github2
2021-04-21 09:47
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v9.15.5_ published by github-actions[bot]

matt.fellows
2021-04-21 10:57
What Tim Said. Couple of other pieces of feedback: 1. Are these promises too? It would make sense if they are promises that deal with auth, that further down the line they haven?t completed before they are required in an `it` block ``` TokenService.saveToken("validToken") TokenService.saveRefreshToken("testRefreshToken")``` 2. You don?t need the `async` keyword there, if you?re not using `await`. You either return a promise, or await it, but not both. ``` beforeEach(async () => { return provider.addInteraction({``` 3. You don?t need to nest `like` within other `like` - the matchers cascade until overridden

matt.fellows
2021-04-21 10:58
flakiness almost always is just Promise mishandling. Simplest thing to do is cut back to two tests and see if you can repro. Add one test at a time in until you see the flakiness (you can just add the `describe.skip` to avoid having to remove/add them)

bheemreddy181
2021-04-21 13:50
@ckhadilkar ^

ckhadilkar
2021-04-21 14:30
@tjones @matt.fellows i agree with you guys that there is a promise that might not be handled correctly. my suspicion is getAccount test for 401 scenario in the above file is not handling the promise rejection.

ckhadilkar
2021-04-21 14:47
fyi, TokenService calls do not return any promise.

ckhadilkar
2021-04-21 15:20
@tjones i seem to have narrowed down the issue to one test: ```describe.skip("account exists and token is invalid", () => { beforeEach(async () => { await provider.addInteraction({ state: 'account exists and token is invalid', uponReceiving: 'getAccount', withRequest: { method: 'GET', path: '/accounts/' + accountID, headers: { "Authorization": like('Bearer testAccessToken') } }, willRespondWith: { status: 401, headers: { 'Content-Type': 'application/json' }, body: undefined, }, }); }); it("returns 401", async () => { const client = new APIClient(provider.mockService.baseUrl) // make request to pact mock server await expect(client.getAccount(accountID)).rejects.toThrow("Request failed with status code 401") }) })```

ckhadilkar
2021-04-21 15:20
but, am not sure why the promise is not handled correctly. am i missing something here?

tjones
2021-04-21 21:09
If that test is the problem it might be your test framework. What test framework are you using? Is the expect call supposed to be called with a function instead? `expect(()=>client.getAccount(accountId))...`

tjones
2021-04-21 21:10
When you say you?ve narrowed it to this test, do you mean that if you run this test on its own it is still flakey?

ckhadilkar
2021-04-21 22:53
so, actually we found the root cause. it was one the TokenService call not being setup in the right spot. moving it to beforeEach block so it runs correctly for each test fixed the issue.

ckhadilkar
2021-04-21 22:53
thank you so much for looking in to this for us.

stain.witness
2021-04-22 02:43
has joined #pact-js

stain.witness
2021-04-22 02:49
:wave: Hi all! Pretty new to the Pact community :wave: I want to make Pact even better with everyone here!

tjones
2021-04-22 03:44
You're welcome!

tjones
2021-04-22 03:47
I think you might be using jest - if that's the case, you may also be interested in https://www.npmjs.com/package/jest-pact , which removes the need for some of the boilerplate in pact tests

matt.fellows
2021-04-22 04:07
Welcome @stain.witness! Thanks again for putting your hand up to be involved with our community. If you wanted to find something small to cotnribute to, see https://github.com/pact-foundation/pact-js/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+label%3A%22good+first+issue%22. These should be fairly small and self-contained, but of course @tjones, myself and others will support you there is also `pact-core` which is used behind the scenes: https://github.com/pact-foundation/pact-js-core/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22+label%3Agood-first-issue Diago, as you?re a UI engineer and have more to often than many of us, you might also be interested in contributing to our website (http://pact.io/). We have ideas, but very much open to hearing your thoughts!

stain.witness
2021-04-22 04:21
Thanks! I think the http://pact.io website is cool enough, but it would be nice to have translations of the documentation. In my case, especially the Japanese documentation!

tjones
2021-04-22 04:23
We don't have one, and having a japanese translation would be great! We used to have a Chinese one, but I don't think it has been maintained in a long time :confused:

oleksandra.pishcheiko
2021-04-22 08:31
has joined #pact-js

akos.csurai.4github
2021-04-22 10:01
has joined #pact-js

christosbouloumpasis
2021-04-22 10:38
has joined #pact-js

temanibeck
2021-04-22 16:04
has joined #pact-js

michael_swiss
2021-04-22 21:04
has joined #pact-js

bas
2021-04-23 07:45
@bas has left the channel

dawoud.sheraz
2021-04-23 09:34
has joined #pact-js

adriano.tanoue
2021-04-23 12:01
has joined #pact-js

saurabh.goel
2021-04-24 20:10
has joined #pact-js

cemal.onder
2021-04-25 12:22
has joined #pact-js

richard.forjoe
2021-04-26 00:52
has joined #pact-js

richard.forjoe
2021-04-26 02:00
Hi all :raised_hands:. Also new to pact. I'm trying to get our developers to implement pact and wanted to know if anyone can share some good example repo's. We are using Jest and gitlab ci. Thank you in advance ? example repo of pact jest tests in js for a simple get endpoint ? example YAML for publishing the consumer contract to the broker

matt.fellows
2021-04-26 02:04
> example YAML for publishing the consumer contract to the broker What YAML would you be needing here? For gitlab CI runner?

matt.fellows
2021-04-26 02:05
You could look at https://github.com/pact-foundation/jest-pact for using Pact with Jest


matt.fellows
2021-04-26 02:06
There is also a few JS examples here, that implement the CI/CD workshop: https://docs.pactflow.io/docs/examples/

ron.aharoni
2021-04-26 11:03
has joined #pact-js

richard.forjoe
2021-04-26 12:47
Hi Matt, Yea example YAML for Gitlab CI

andrewmorton
2021-04-26 13:33
has joined #pact-js

aram
2021-04-26 15:24
has joined #pact-js

aram
2021-04-26 15:45
Hi all, Doing a poc for Pact in my company, hoping to get them into it. But i?m hitting a snag? When i add pact to the typescript project and try to run tests i get the following error (if i remove pact, then everything works OK again) Anyone got any idea? thanks :slightly_smiling_face: ```TSError: ? Unable to compile TypeScript: src/insights/insights-manager.ts:132:14 - error TS2769: No overload matches this call. Overload 1 of 2, '(predicate: ListIteratorTypeGuard<{ source: string; residency: string; }, { source: string; residency: string; }>): CollectionChain<{ source: string; residency: string; }>', gave the following error. Type 'string | boolean' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. Overload 2 of 2, '(predicate?: string | number | symbol | [string | number | symbol, any] | PartialShallow<{ source: string; residency: string; }> | ListIterator<{ source: string; residency: string; }, boolean> | undefined): CollectionChain<...>', gave the following error. Argument of type '({ residency }: { source: string; residency: string; }) => boolean | ""' is not assignable to parameter of type 'string | number | symbol | [string | number | symbol, any] | PartialShallow<{ source: string; residency: string; }> | ListIterator<{ source: string; residency: string; }, boolean> | undefined'. Type '({ residency }: { source: string; residency: string; }) => boolean | ""' is not assignable to type 'ListIterator<{ source: string; residency: string; }, boolean>'. Type 'string | boolean' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. 132 return _.chain(value) ~~~~~~~~~~~~~~ 133 .filter(({ residency }) => residency && residency.toLowerCase() !== 'unknown') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/@types/lodash/common/common.d.ts:218:50 218 type ListIteratorTypeGuard<T, S extends T> = (value: T, index: number, collection: List<T>) => value is S; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The expected type comes from the return type of this signature.```

jayson.bailey
2021-04-26 19:05
Is it best practice to `.gitignore` the `./pacts/*.json` ?

marcelo.souzameinberg
2021-04-26 21:32
has joined #pact-js

matt.fellows
2021-04-26 22:17
Might be worth searching history here for gitlab

matt.fellows
2021-04-26 22:18
I don't think we have any about

abubics
2021-04-26 22:52
I usually gitignore the whole directory. Pacts belong in the broker :)

tjones
2021-04-26 23:02
This error doesn't look like it has anything to do with Pact, I'm afraid. If you share your code, we could take a look?

songqing.gu
2021-04-27 01:25
has joined #pact-js

aram
2021-04-27 05:13
thing is, if i remove the pact package, the error is gone. It happens before even any code is written?. hence i believe there is a package version conflict (or something similar)

tjones
2021-04-27 05:34
Hmm.. I'm not sure how that could be the case. Can you put together a minimal example that demonstrates the problem and we can take a look?

tjones
2021-04-27 05:35
pact-js doesn't expose any types from lodash

aram
2021-04-27 05:36
not sure i can share anything as it?s in our code

tjones
2021-04-27 05:36
I think this is an unrelated typescript error. If the error only appears when pact is present, I would guess that this file isn't normally being compiled for some reason.

aram
2021-04-27 05:36
but lodash is being referenced by pact-js, no..?

aram
2021-04-27 05:37
i?ll keep digging deeper into this today..

tjones
2021-04-27 05:37
This is a compile error coming from outside pact, complaining about a `@types` package that isn't a dependency of pact.

aram
2021-04-27 05:37
ok, thanks for the assist? :slightly_smiling_face:

tjones
2021-04-27 05:38
I would try removing your node_modules (jest, typescript and friends like to cache things in there), and confirm that the version of lodash you are using matches the version of `@types/lodash` that you're using.

tjones
2021-04-27 05:39
I don't think this is a pact problem, but I'm happy to be proven wrong. If we're not able to reproduce it or take a look, I'm not sure what we can do to help, sorry

tjones
2021-04-27 05:39
I can't think of a reason that adding the pact dependency would cause a problem like this (of course, that doesn't mean there isn't one)

tjones
2021-04-27 05:40
oh, and remove your `package-lock.json` when you nuke node_modules. This kind of weirdness can happen when it's corrupt.

aram
2021-04-27 05:41
hmm? OK? thanks? i?ll try these (i?m rather new to node as well, so i?m learning these as i go along..)

tjones
2021-04-27 05:45
This is typescript complaining it doesn't know how to compile that line in your source. I would confirm: 1. The line is correct for the version of lodash that you're using 2. The types that you're using for lodash match the version of lodash that you're using (these are declared as different dependencies, because lodash doesn't provide its own types). 3. Confirm that your node_modules / package-lock / yarn.lock haven't become corrupt by deleting them and re-running install.

tjones
2021-04-27 05:46
I'm sure there's some straightforward reason you're getting this error, but I'm afraid it's a bit hard to tell from here

tjones
2021-04-27 05:46
sorry I can't be more helpful

aram
2021-04-27 05:47
you?ve been very helpful. Gave me some directions to check? thanks :slightly_smiling_face:

tjones
2021-04-27 05:47
Good luck! Please do let us know if Pact is the culprit.

aram
2021-04-27 05:47
will do

fortiss.anita
2021-04-27 09:34
has joined #pact-js

keshav.reddy503
2021-04-27 12:06
has joined #pact-js

aram
2021-04-27 13:45
so apparently it?s this package that?s was giving me grief: @types/bluebird... we managed to fix the issue. Thanks for the pointers

jeremykeczan
2021-04-27 14:57
has joined #pact-js

yeseniavega411
2021-04-27 15:31
has joined #pact-js

almantusk
2021-04-27 16:56
has joined #pact-js

alexandra.huamani
2021-04-28 00:12
has joined #pact-js

tonynguyenit18
2021-04-28 02:12
has joined #pact-js

tonynguyenit18
2021-04-28 02:18
Hi everyone. I?m Tony. I have recently tried contract-testing using Pact. I feel like what Pact does is try to replace integration test (minimise it at least), and I found that when doing pact tests, it recommends to mock database query using provider state https://docs.pact.io/getting_started/provider_states/. How could I test my database query correct? Does it out of scope of CDCT using Pact and I need to write normal intergration test for it? Thanks!

abubics
2021-04-28 02:32
Pact doesn't target testing database interfaces, and I personally don't hit DBs over a network during my pact tests. But one option is to use the state change endpoint to seed an actual database with expected state data, so when your provider is verifying interactions, it can exercise a deeper stack. This brings you back to integrated testing again, which is less specific, but might solve a problem for you.

matt.fellows
2021-04-28 02:41
> How could I test my database query correct? Does it out of scope of CDCT using Pact and I need to write normal intergration test for it? If it?s about database queries specifically, I think you can do that by other means. e.g. you could easily have a set of test cases that run locally against the layer of your code base that is responsible for communicating to a DB.

matt.fellows
2021-04-28 02:42
From a contract testing perspective, you could for instance have, say, Docker running locally with a seeded database (as Andras mentions) and manipulate that database using Pact. It?s going to pass through more layers of your code base (so will probably be a little slower) but that might be a good compromise

matt.fellows
2021-04-28 02:42
The key point is that you have complete control over the data

matt.fellows
2021-04-28 02:42
so deploying it to a test environment usually makes things non-deterministic, because something else could be interfering with the environment when your tests run


matt.fellows
2021-04-28 02:43
(the 4th one talks about end-to-end test replacements)

agrawalneeraj43
2021-04-28 04:37
has joined #pact-js

shixun.liu1023
2021-04-28 04:39
has joined #pact-js

tonynguyenit18
2021-04-28 05:30
Thanks Boris and Matt. The answer seem like ?depend?. my team have had as discussion and choose to using local database running in a docker container to test. Let?s see how it work. Thanks guys!

narendra.pathai
2021-04-28 06:21
has joined #pact-js

tjones
2021-04-28 06:59
Yep, that?s a reasonable approach. Pact tests aren?t functional tests, but it?s ok (and usually valuable) to have them have some functional coverage.

tjones
2021-04-28 07:01
I think pact-node might expose that for legacy reasons, but I?ll check when I get home. What was the fix?

keshav.reddy503
2021-04-28 07:30
hello everyone, I'm Keshav, working as a QA and would like to implement Contract testing to an existing service. My requirement is to have a separate pipeline where I will run the contract and user behaviour tests, testing a live endpoint in Sandbox env. I understand Pact recommends to use the internal methods/class that returns the response of the API to generate the Pact file, but in my case it's may not be possible. Can I use the actual URLs in my case to test the contracts?

matt.fellows
2021-04-28 07:33
You can certainly do it (on the provider side, and with the aforementioned challenges it poses) but not on the consumer side.

matt.fellows
2021-04-28 07:33
Pact is a white box testing tool, mostly

matt.fellows
2021-04-28 07:33
You could consider something like https://pactflow.io/blog/bi-directional-contracts/, which could enable black box style contract testing

matt.fellows
2021-04-28 07:34
(but note, it?s a Pactflow-only feature so that might not fly in your situation)

shixun.liu1023
2021-04-28 10:22
Hi everyone, I?m Leo, I have recently tried contract-testing. I am wondering in Provider contract testing, is it possible to split the test into multiple test cases, and in each test case we can assign a desired interaction to verify? Currently I can only create a single test case which will verify all the interactions of a contract, but sometimes I am hoping to assign different http headers for different interaction. Thanks a lot

matt.fellows
2021-04-28 10:28
Have you looked at the request filter feature?

matt.fellows
2021-04-28 10:28
Also, what are you trying to do with headers?

shixun.liu1023
2021-04-28 10:34
Yep, I have looked the request filter. For example, I have created two interactions in consumer side: 1. Success response (request with correct token) 2. Failure response (request with wrong token OR token is missing). So in the Provider test, if I don?t misunderstand, I need to attach a correct token for interaction 1 verification, and not to attach token OR attach wrong token for interaction 2 verification, right?

matt.fellows
2021-04-28 10:41
Yes, something like that

matt.fellows
2021-04-28 10:42
You can use the state handlers and request filters together to achieve this


shixun.liu1023
2021-04-28 10:49
Yep, thanks Matt. As this demo shown, the different headers OR different states are handled together in a single test case, so that?s why I am just curious if there is some way to split the test case, and each one can handle a specific interaction

shixun.liu1023
2021-04-28 11:04
Or, Pact is designed to always verify all the interactions of a contract when run that single test case, and not support choosing a specific interaction

matt.fellows
2021-04-28 11:28
It's designed to run them all at once

shixun.liu1023
2021-04-28 11:29
Yep, I see, thanks Matt

marcin.grzejszczak
2021-04-28 13:53
has joined #pact-js

flubniewski
2021-04-28 17:01
has joined #pact-js

tjones
2021-04-29 02:04
If you don't have provider states, you can do black box verification fairly straightforwardly. However, you wont' be able to generate a contract without white box testing of the clietn

bangn
2021-04-29 02:19
has joined #pact-js

bangn
2021-04-29 02:20
:wave:

tjones
2021-04-29 03:46
This sounds like something that would be better defined on the consumer side

tjones
2021-04-29 03:47
on the consumer you can give an example where the token is valid, and an example where it isn't. Then the verification can just run the examples from the pact file.

tjones
2021-04-29 03:47
You may need to use provider states to control this, eg, `state: "SOME_TOKEN is a valid API token"`

matt.fellows
2021-04-29 06:18
yeah, that?s what the example does

matt.fellows
2021-04-29 06:18
the consumer specifies the states, and the state handlers set the token to be a valid/invalid one depending on that

matt.fellows
2021-04-29 06:19
unfortunately, state handlers can?t (currently, at least) modify the inbound request itself. That would be better than a general request filter for this use case I think

matt.fellows
2021-04-29 06:19
otherwise, you have a request filter that has to ?know? about tests

aram
2021-04-29 09:41
Hi all, Is there a way to tell pact to expect either a string or undefined? Or will i need two different tests for this?

abubics
2021-04-29 09:44
You'll need two tests, there's an article about it in the docs :)

abubics
2021-04-29 09:44
Also, `undefined` isn't a JSON value ;)


matt.fellows
2021-04-29 09:47
The latter. Search http://docs.pact.io for "optional fields" on why

aram
2021-04-29 10:32
thanks? :slightly_smiling_face:

giuseppe.salvatore
2021-04-29 15:14
has joined #pact-js

giuseppe.salvatore
2021-04-29 18:05
Hi everyone, I have been using PACT with java micro-services for sometimes and was starting to look into adding a React/Next.js front-end application in the bigger picture. I was trying to find an example from scratch and I found this one https://github.com/pact-foundation/pact-workshop-js. In my case the API are already available(-ish), although still under development. Following that example I have created one simple test case but I am struggling to execute it. The React app defines already some functions that perform the API calls with axios. I know I need to get to the point to mock them to generate the contracts. For local development we use Wiremock and for the UI tests we use Cypress (that uses its own mocks with the fixtures shared with Wiremock)

giuseppe.salvatore
2021-04-29 18:15
Any help or link to a project that has React (or similar) would be really appreciated

tjones
2021-04-30 00:29
There's nothing special you need to do to do pact with React - you would call the API layer the same as you would with any of the other javascript frameworks

tjones
2021-04-30 00:29
> I know I need to get to the point to mock them to generate the contracts. So, you would call the actual client API calls in a pact test

tjones
2021-04-30 00:31
If you're able to share your code, we can give more direct help

tjones
2021-04-30 00:32
This is a pact test in a (very old style) react project: https://github.com/TimothyJones/PlusOne/blob/master/src/Game/Board/service/api/api.pact.test.js As you can see, there's nothing special because it's React

tjones
2021-04-30 00:34
Pact sits in the place where wiremock would sit - they have similar purposes

tjones
2021-04-30 00:35
except pact is more easily shared and verified against the provider

abubics
2021-04-30 02:24
A missing bit I see in a lot of codebases is separation of the API client :sob: If it's not separated yet, that should be a high priority refactor (for everyone's sanity).

giuseppe.salvatore
2021-04-30 09:32
@tjones regarding this > So, you would call the actual client API calls in a pact test I want to use the same implementation that the front-end uses in the pact test. The various functions (say `getAddresses(postcode)` ) will internally invoke axios on a baseUrl that depends on an env variable. So it would hit either the wiremock local instance, a test instance of the API or the actual production API. Call the actual API... that wasn't my plan in the pact tests... I always thought in PACT is better to use mocks for that.

giuseppe.salvatore
2021-04-30 09:35
@abubics what do you mean exactly? Can you please give some example? We have our API layer in a folder with all the functions exported that are used on the FE. But I am not sure if that is the level of separation you are talking about. Happy to get suggestions on that

giuseppe.salvatore
2021-04-30 09:52
and thanks for your answers guys

matt.fellows
2021-04-30 10:10
> So, you would call the actual client API calls in a pact test != > Call the actual API... that wasn?t my plan in the pact tests... I always thought in PACT is better to use mocks for that You?re right. In the pact test, you don?t actually call the _real_ API. You call the Pact mock

matt.fellows
2021-04-30 10:10
i.e. These two lines configurre the API to talk to Pact, and call the API client


giuseppe.salvatore
2021-04-30 10:11
Right, but I am missing how to configure the PACT mock then

giuseppe.salvatore
2021-04-30 10:11
Ah yeah I was looking at that...


giuseppe.salvatore
2021-04-30 10:46
So yeah looks like I needed to fix the PACT mock and make the provider setup so that my api call was using the `provider.mockService.baseUrl` Kudos to @matt.fellows

giuseppe.salvatore
2021-04-30 11:15
Right this is something that goes beyond my understanding

giuseppe.salvatore
2021-04-30 11:16
```console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:122:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /v1/basket-orders/checkout/8013L0000 Unexpected requests: OPTIONS /v1/basket-orders/checkout/8013L0000```

giuseppe.salvatore
2021-04-30 11:17
in the api I am calling ```axios.get(`${process.env.NEXT_PUBLIC_API_BASE_URL}/v1/basket-orders/checkout/${orderId}```

giuseppe.salvatore
2021-04-30 11:17
I am not sure how that can be an OPTIONS call and not a get

giuseppe.salvatore
2021-04-30 11:20
ah... pre-flight checks

tjones
2021-04-30 11:24
put `cors: true` in your pact options when you do `new Pact(...)`

giuseppe.salvatore
2021-04-30 11:36
that fixed it :+1:

giuseppe.salvatore
2021-04-30 11:36
nearly there...

giuseppe.salvatore
2021-04-30 11:44
yes!!! ```PASS pact/consumer/src/api.pact.spec.js```

giuseppe.salvatore
2021-04-30 11:44
thanks everyone :+1:

roy_collings
2021-04-30 15:15
has joined #pact-js

yousafn
2021-05-01 23:33
Jest-pact turned 2 years old on 30th April and to celebrate its anniversary, it managed to hit 1 million downloads on npm which is pretty cool. https://npm-stat.com/charts.html?package=jest-pact&from=2019-04-30&to=2021-05-01

matt.fellows
2021-05-01 23:35
Wow!

abubics
2021-05-02 06:44
late to reply on this, but > what do you mean exactly? Can you please give some example? Sounds like you're already on track with a layered architecure. If you have an API layer already, separated from presentation-layer bits, that's great. Often, when people ask questions in this workspace, and even in codebases I see at different business, the UI code, or even the endpoint handlers in an API directly call out to their dependencies. This makes it hard to separate the presentation framework from the contract-testable units.

yousafn
2021-05-02 21:59
Yo yo, been messing about with a msw-pact integration, on and off since I read a video on msw yesterday documented what I?ve done so far https://github.com/mswjs/msw/issues/572#issuecomment-830888911 in the original issue. the repo is https://github.com/YOU54F/msw-pact

matt.fellows
2021-05-02 23:21
Ah cool!

bethskurrie
2021-05-02 23:22
Sweet :smile:

matt.fellows
2021-05-02 23:25
So this is the ?I have a Pact file already, and want to re-use in MSW? use case

yousafn
2021-05-02 23:28
That is one of the cases which followed on from the existing https://github.com/mswjs/msw/issues/572#issuecomment-778510228. I?ve built a second more useful case, which is generating a pact file from an msw mock. ? wait for an msw mock match ? wait for an msw mock response ? when both are complete, map the req/response to a pact file spec and write it to disk

matt.fellows
2021-05-02 23:29
:point_up:

matt.fellows
2021-05-02 23:29
that?d be so great in terms of getting people into the ecosystem

prachi_mangesh_edake
2021-05-03 04:43
has joined #pact-js

sams.prashanth
2021-05-03 08:04
has joined #pact-js

philip.m.wood
2021-05-03 12:46
has joined #pact-js

amiller
2021-05-03 15:27
has joined #pact-js

agarwal.akash333
2021-05-03 23:14
has joined #pact-js

francis.lobo
2021-05-04 06:13
Hello folks, I have a bunch of questions posting them here: Q1. I am trying to use Pact-jest with V3 I am not seeing any log files being generated When I try to set the `loglevel` dir and pactfileWriteMode I get the error: 'logLevel' does not exist in type 'JestPactOptionsV3' doesnt Pact-jest support these options?

francis.lobo
2021-05-04 06:14
versions "jest-pact": "0.9.0-beta.v3", "@greet_bot/pact": "10.0.0-beta.34",

uglyog
2021-05-04 06:29
Use the `LOG_LEVEL` environment variable

uglyog
2021-05-04 06:30
Support for log files hasn't been implemented yet

francis.lobo
2021-05-04 06:30
ah ok thanks @uglyog

francis.lobo
2021-05-04 06:31
Message deleted - it was a trivial issue

francis.lobo
2021-05-04 06:37
and the stack trace ends with Mock server failed with the following mismatches: 0) request-mismatch (at /cm-api/clients/0A050891038CFAFC/mailings/bulk/drafts/copy) [object Object] at node_modules/@pact-foundation/src/v3/pact.ts:269:35

matt.fellows
2021-05-04 07:16
Does jest pact support the v3 beta yet?

matt.fellows
2021-05-04 07:16
I recall Tim talking about it, maybe he did

marcin.grzejszczak
2021-05-04 07:27
@marcin.grzejszczak has left the channel

francis.lobo
2021-05-04 07:46
The git doco says it supports. I am able to generate pacts using v3 matchers.. and my jvm provider is happily verifying them :blush:

anand.ilkal
2021-05-04 08:01
has joined #pact-js

matt.fellows
2021-05-04 09:57
:slightly_smiling_face:

matt.fellows
2021-05-04 09:57
happy days

srinivasan.sekar1990
2021-05-04 10:15
Folks I have a query: An angular service in our front-end calls a Microservices like below: ``` import { environment } from 'src/environments/environment';  const API_ENDPOINT: string = `${environment.apiUrl}/something`;  public getSomething(cap?: string, selfEmployed: any = false): Observable<ISomeState> {   ??.   return this.http.get(API_ENDPOINT, { params }) as Observable<ISomeState>;  }``` API_Endpoint is coming `environment.ts`. In my pact spec I have created the service instance using angular test bed. ```const someService: SomeService = TestBed.inject(SomeService); await someService    .getSomething('12345')    .toPromise()    .then(response => {     expect(response.noTaxValue).toBe(12);    });``` Any thoughts on how do we proxy or replace the original base url coming from `environment.ts` with `providers mock service url` in above use case?

srinivasan.sekar1990
2021-05-04 10:23
@matt.fellows Can you please shed some thoughts on this whenever you get time?

dennis.minard
2021-05-04 16:23
has joined #pact-js

chris.williams
2021-05-04 16:41
has joined #pact-js

yousafn
2021-05-04 17:51
Hey hey, so I?ve released msw-pact which will intercept a mock-service-worker request/response and transform it into a pact https://github.com/YOU54F/msw-pact Feedback, issues, pull requests etc welcome!

ssorcnafets
2021-05-04 19:20
has joined #pact-js

francis.lobo
2021-05-04 21:34
Hello @matt.fellows I finally got to try out `eachKeyLike("TestKey", expectedJson)` I am noting it isn't working as expected, my provider tests fail stating they couldn't find `TestKey` If I replace the `TestKey` with the actual key value, the tests are passing. The provider tests pass when I use a pact generated from JVM using `eachKeyLike` detailed example and code snippets in thread.

francis.lobo
2021-05-04 21:35
For a JSON response like this: ```{ "data":{ "copiedData":{ "fA2FD0EC386AC306":{ "Id":"CEE6E346DE73883B", "name":"TheName" } } } }```

francis.lobo
2021-05-04 21:35
My DSL definition looks like this in JS ```const ResponseExpectation = { data: { copiedData: MatchersV3.eachKeyLike("TestKey", { mailingId: MatchersV3.string(''), name: MatchersV3.string(''), }) }```

francis.lobo
2021-05-04 21:36
This always fails my provider test ```java.lang.AssertionError: 0 - BodyComparisonResult(mismatches={$.data.copiedData=[BodyMismatch(expected={"TestKey":{"mailingId":"","name":""}}, actual={"fA2FD0EC386AC306":{"mailingId":"CEE6E346DE73883B","name":"TheName"}}}, mismatch=Expected tempKey={"mailingId":"","name":""} but was missing, path=$.data.copiedData, diff={ - "tempKey": { + "fA2FD0EC386AC306": { + "mailingId": "CEE6E346DE73883B", + "name": "TheName", ...``` The tests will pass, if I replace `TestKey` with `fA2FD0EC386AC306`

francis.lobo
2021-05-04 21:37
for the same pact, My JVM DSL looks like this ``` DslPart body = new PactDslJsonBody(); body.object("data") .object("copiedData") .eachKeyLike("TestKey") .stringType("mailingId") .stringType("name") .closeObject() .closeObject() .asBody()```

francis.lobo
2021-05-04 21:39
versions consumer: ```"jest-pact": "0.9.0-beta.v3", "@pact_foundation_greet/pact": "10.0.0-beta.34",``` provider: ```compile group: 'au.com.dius', name: 'pact-jvm-provider-gradle', version: '4.0.10' compile group: 'au.com.dius', name: 'pact-jvm-consumer', version: '4.0.10' compile group: 'au.com.dius', name: 'pact-jvm-consumer-junit', version: '4.0.10'```

francis.lobo
2021-05-04 21:42
Am I missing something in the way I am using eachKeyLike? or is it an actual bug?

kowalczuk.jnr
2021-05-04 22:24
has joined #pact-js

hugo
2021-05-05 00:48
has joined #pact-js

tjones
2021-05-05 02:36
I?m not sure I follow this question. Is your consumer the js or the Java? The consumer defines the example response, not the provider.

tjones
2021-05-05 03:00
I would just mock `environment.ts` using whatever mock framework is appropriate for whatever test runner you?re using

francis.lobo
2021-05-05 03:00
I have a jvm consumer test + provider test and they work fine with the above json I am trying to write a js consumer test for the same interaction, (and use the existing jvm provider tests) but i can't seem to get it working

tjones
2021-05-05 03:03
If that turns out to be unnecessarily fiddly, you can always inject it for testing by doing something like: ``` public getSomething(cap?: string, selfEmployed: any = false, baseUrl = API_ENDPOINT): ```

abubics
2021-05-05 03:56
maybe unrelated, but what is `@pact_foundation_greet/pact`?

abubics
2021-05-05 03:58
Going by the error, it seems like you might not be setting the right provider state in the JS test?

abubics
2021-05-05 04:02
If the state is intended to set the key to be literally `"TestKey"`, the provider test is responding with a different key value, which I would expect to fail.

francis.lobo
2021-05-05 04:38
@abubics "Testkey" is a dummy/place holder value. I dont want the provider tests to validate the presence of actual key name ( testkey or fA2FD0EC386AC306). but validate the contents (or value) of the key

abubics
2021-05-05 04:52
From the little bit of v3 docs I've read, it looks like you need a matcher alongside the key name, otherwise it'll take `"TestKey"` as the literal value. I could be reading it wrong, though.

abubics
2021-05-05 04:55
Actually, I seem to only find docs for JVM `eachKeyLike` :thinking_face: can you link your reference?


abubics
2021-05-05 06:38
Yeah right, sounds like a bug maybe. What kind of differences do you see in the generated pact file?

abubics
2021-05-05 06:39
(also, as should be quite evident, this is not my area of expertise. Someone who worked on it may have better answers faster)

matt.fellows
2021-05-05 08:08
What Tim said

timo
2021-05-05 08:12
has joined #pact-js

tjones
2021-05-05 08:46
Could you share your whole test setup? It might be that the test is a v2 pact, but the matcher is a v3 matcher

srinivasan.sekar1990
2021-05-05 08:55
Thanks @tjones I followed exactly the option2 yesterday to sort this out.

tjones
2021-05-05 08:56
Excellent!

jadelong
2021-05-05 15:51
has joined #pact-js

jadelong
2021-05-05 15:55
Hi all. We are having an issue with some of our developers while running consumer tests. We are using jest-pact and Angular on the consumer side. For some of our developers the tests run fine, for others they are getting an error that Pact could not be started with PID <id>. When checking the task manager we can see the ruby process running and can even hit the mock service url and get a proper response. It seems like the server is starting up correctly but the test thinks that it failed for some reason. Has anyone experienced something like this?

yousafn
2021-05-05 23:25
We have had significant amount of issues with our colleagues windows setups (to the point where they just don?t run the tests and rely on CI to do it for them :cry: ), but those on macs and linux have had a pretty painless time. We use jest-pact but not angular. For the people that it doesn?t work for, is there any commonality? Also, if there anything in common with their setups, to those machines who have it working.

matt.fellows
2021-05-05 23:50
I hope with the v3 release, we?ll resolve the windows pain. We feel you, it pains me each time I hear of their issues

matt.fellows
2021-05-05 23:50
For windows, check out for the infamous long path issue

alexei.solcanu
2021-05-06 02:01
has joined #pact-js

zonkor
2021-05-06 08:08
has joined #pact-js

zonkor
2021-05-06 08:18
Hey I have a quick question and I'm sure I wont be the first to ask, but I can only find _similar_ issues on GitHub. Assuming you want to do a positive test for a call that for example moves a picture from one category to another: the currently best (and/or only?) way to do the stateHandlers for that is to have something along the lines of 'picture with id 123 exists, category with id 456 exists, category with id 789 exists'? or am I missing something? (pact v2). Follow-up, if my assumption is correct: I've seen that v3 will get parameterized states, which will be useful when you have the same state multiple times but with different IDs. But it won't tackle the issue I mentioned regarding having multiple requirements regarding the state for that test, correct? Or will there be an option to give the states names/ids so you can do something along the lines of: states: [{ name: 'picture', id: 123 }, { name: 'category', id: 456 }, { name: 'category', id: 789 }]? So that the provider can create 2 separate, parameterized states. thanks a lot!

abubics
2021-05-06 08:35
Until v3, state is just a string, and you can put as much or as little detail into it as you like. ? If you put more detail, such as IDs, then your situation might feel over-specified. Even still, you can build your own multi-state handling in your state-change endpoint on the provider side (such as parsing a comma-separated string into multiple state setup functions). ? If you put less detail, only describing the state at a high level (e.g. "picture that can be moved between categories"), then the consumer and provider teams need to manage the untold detail in some other way.

abubics
2021-05-06 08:37
Even once you get more structured state in v3, you can go down either path.

tjones
2021-05-06 10:17
:taco: for boris for an excellent answer

tjones
2021-05-06 10:17
I mean :taco: for @abubics

tjones
2021-05-06 10:33
I don?t think there?s anything jest-pact does that would cause this directly. It should all work though- would you mind running with logLevel set to debug, and attach the log (or open an issue), please?

tjones
2021-05-06 10:33
Also I now have a windows development environment - so if you?re able to post a repository that reproduces the problem, we can take a look.

tjones
2021-05-06 10:34
Jest-pact runs on Windows during the pact-js CI (all examples are run each build)

jadelong
2021-05-06 11:44
There hasn't been any pattern that I have noticed between those that have it working and those that don't. I did see the long path issue in my research and don't think that would be the case here, paths pretty much match up between working and non-working devs. We tried running with debug logging and got a little bit more in the console, really just the PID of the server and port number it was starting up on. I don't have the console logs on hand with me but can get them if it would be beneficial. The log file that pact generates however is completely empty. I can maybe try and get a repo to reproduce setup but I'm pretty slammed at the moment so it may be a while.

jadelong
2021-05-06 11:45
Thanks for the responses though! This has been a big help

matt.fellows
2021-05-06 11:45
:+1:

florian.mautendorfer
2021-05-06 14:04
has joined #pact-js

john.mcnulty
2021-05-06 16:49
has joined #pact-js

tonynguyenit18
2021-05-07 01:00
Hi I am experiment WIP feature from https://docs.pact.io/pact_broker/advanced_topics/wip_pacts/#technical-details http://blog.pact.io/2020/02/24/introducing-wip-pacts/ And https://docs.pactflow.io/docs/workshops/ci-cd/workshop/verifying-feature-pacts Most of them demonstrate on Provider master branch. It will work because In mature of contract testing, `master` tag should be already exist. But in our case we want something. Consumer: Checkout `c-feat-x` branch require API `getUser` from provider, writing test and publish it with `c-feat-x` tag Provider: Checkout `p-feat-x` branch, after implement `getUser` when verify we want it will verify `c-feat-x` without modify Verify configuration then we think WIP feature will work so we have `pactfoundation/pact-broker:2.79.1.0` running locally and something like this. ```.... enablePending: true, includeWipPactsSince: "2020-10-31", providerVersion: gitHash, // gitHash is short version 9d76502 providerVersionTags: [gitBranch], // p-feat-x``` What we expect when run verify: `c-feat-x` is veified BUT What we got when run verify: `c-feat-x` is not included in WIP list => it?s not verified Dig more into the docs(https://docs.pact.io/pact_broker/advanced_topics/wip_pacts/#technical-details) we find out at at number 5 > 5. Discard all the pacts that were published before the first instance of this provider tag (this is so that if you create a brand new provider branch, you don?t get EVERY head pact included in the WIP pacts list). Yeah it explain why we don?t have `c-feat-x` in the WIP list because it?s published before first `p-feat-x` tag created. ==> Now we can understand it but we can not find out our solution for our case (i think that?s is common workflow of dev team). Thanks

francis.lobo
2021-05-07 03:03
@tjones sorry, I was sick yesterday. couldnt get back on this. I will update the file in about an hour



tjones
2021-05-07 04:32
Hmm. The test looks right to me (except for the use of supertest - Pact is designed to test the actual client code that you're using - but that's not the problem, and maybe you dropped supertest in so that we could run the example, in which case thanks)

tjones
2021-05-07 04:32
Do you happen to have the corresponding pact file from the JVM?

tjones
2021-05-07 04:36
This feels like a #pact-broker question. I think the expected workflow of the tags is to have the same tag in the provider and the consumer test, for example `feat-x` instead of `c-feat-x` and `p-feat-x`. However, I don't have much experience working with tags, so I'm not sure (I tend to do trunk based development).

tjones
2021-05-07 04:38
I've posted a link to the pact broker channel

bethskurrie
2021-05-07 06:02
Hi @tonynguyenit18 I understand the problem.

bethskurrie
2021-05-07 06:02
I'm just not sure how to fix it.

bethskurrie
2021-05-07 06:03
I was tossing up getting rid of the "discard pacts before date" thing, because I think most people only turn on wip pacts for master branch anyway.

bethskurrie
2021-05-07 06:05
The other thing that might help is that if you are actually using feature branch names that end in a matching suffix, there is an open feature request to have regular expressions in consumer version selectors.

bethskurrie
2021-05-07 06:06
With the existing code you'll need to explicitly modify the selectors to bring in the pact that you want unfortunately.

bethskurrie
2021-05-07 06:08
I've been doing some work to add proper branch support to the broker, and it will have the concept of a "default branch". I think this will actually help make the WIP pact selection easier to reason about, and I might be able to fix this issue.

bethskurrie
2021-05-07 06:09
I'm going to capture your question and put it in an issue for further thought.


bethskurrie
2021-05-07 06:19
@tonynguyenit18 what would be super super helpful is if you could give a repo of the issue you have just described using this https://github.com/pact-foundation/pact_broker/blob/master/ISSUES.md

tonynguyenit18
2021-05-07 06:36
Thanks @bethskurrie > The other thing that might help is that if you are actually using feature branch names that end in a matching suffix, there is an open feature request to have regular expressions in consumer version selectors. Yes that :point_up:is the idea came up to my mind at first, could you please attach the feature request link of this so I can follow up, and might help if I can.

tonynguyenit18
2021-05-07 06:39
As you said, we don?t have any solution for that except manually modify `consumerVersionSelectors` , we come up with an idea. Consumer: Checkout `c-feat-x` branch require API `getUser` from provider, writing test and publish it with `c-feat-x` AND `dev` (or any other proper special tag) Provider: Checkout `p-feat-x` branch, after implement `getUser` when verify we want it will verify `c-feat-x` without modify Verify configuration then we think WIP feature will work so we have `pactfoundation/pact-broker:2.79.1.0` running locally and something like this. ```{ enablePending: true, includeWipPactsSince: "2020-10-31", providerVersion: gitHash, // gitHash is short version 9d76502 providerVersionTags: [gitBranch], // p-feat-x consumerVersionSelectors: [ { tag: "dev", }, { tag: "qa", latest: true }, { tag: "sandbox", latest: true }, { tag: "prod", latest: true } ], ..... }``` In this case the `p-feat-x` can verify `c-feat-x` It also verify other Consumer pact e.g `c-feat-y` tagged `dev` too, but it won?t fail the provider build because we enable `enablePending` What do you guy think? Is there any potential issue?


bethskurrie
2021-05-07 06:43
That "dev" tag will get big soon!

bethskurrie
2021-05-07 06:43
You'll want to clean it up afterwards, but it could work.

tonynguyenit18
2021-05-07 06:43
We will have webhook to remore dev tag when we merge a Consumer branch to master

bethskurrie
2021-05-07 06:43
You'll also need to remove it from previous versions of the feature branch.

bethskurrie
2021-05-07 06:44
otherwise you'll be verifing every version that was ever published on the feature branch, not just the latest one.

bethskurrie
2021-05-07 06:44
I can't think of a nice way to do that through the API.

bethskurrie
2021-05-07 06:45
You could use the endpoint that deletes all the pacts by tag, and call that before you publish the pact each time, so that you only ever have one pact with a particular feature tag + dev


tonynguyenit18
2021-05-07 06:55
Actually, we don?t think we should delete all pacts by `dev` tag before we publish the pact each time. The reason is we might have Consumer team working on 2 branch `c-feat-x` (version 100 ) and `c-feat-y` (version 101), in that case if they both publish pact we want to keep both of them having `dev` (of course only one is latest `dev`). From provider side we have ``` consumerVersionSelectors: [ { tag: "dev", }, ..... }``` means does not matter it is `p-feat-x` or `p-feat-y` , they both verify both `c-feat-x` and `c-feat-y` . Only `p-feat-x` - `c-feat-x` and `p-feat-y` - `c-feat-y` pass, and `p-feat-x` - `c-feat-y` will fail but the provider build not fail because se enable pending. After contract publish by `c-feat-x` (version 100 ) verified , we merge this branch to Consumer master branch -> we also DELETE `dev` tag from version 100. Now only `c-feat-y` (version 101) having `dev` tag, when we merge this to master we delete `dev` by version number `101` too. ==> after merging all Consumer feature branch to master, we don?t have any `dev` tag left in Broker. Those steps repeat when we have other feature branches. Is it right way to do?

brendan.donegan
2021-05-09 09:40
I?m trying to upgrade our repo to jest-circus and have noticed that jest-pact depends on jasmine. Is that something that can be addressed?

brendan.donegan
2021-05-09 09:44
it looks like it?s using it for setting the timeout - surely jest.setTimeout is the way to do that?

brendan.donegan
2021-05-09 09:46
?and it looks like this had been fixed :slightly_smiling_face: i?ll upgrade

matt.fellows
2021-05-09 10:26
:rolling_on_the_floor_laughing:

bethskurrie
2021-05-09 23:21
I meant, delete all the pacts for the feat tag @tonynguyenit18

bethskurrie
2021-05-09 23:21
That way, only the latest pact for each branch exists, so you can verify every dev pact knowing they're only the head versions.

tonynguyenit18
2021-05-09 23:28
Got you. Thanks @bethskurrie for your answer and time. Really appreciate.

tjones
2021-05-09 23:41
At the time we first wrote it, jest.setTimeout didn't exist.


francis.lobo
2021-05-10 01:29
this has some pattern matchers on the request path. I hadn't added them on the JS part as I was just getting started (I assume that shouldnt change how eachKeyLike works)


tjones
2021-05-10 01:31
Yeah, I think that might be a key signal. I'd say this is a bug on the JS side. Sorry about that!

tjones
2021-05-10 01:32
If you have a moment, would you be able to open an issue here: https://github.com/pact-foundation/pact-js/issues

tjones
2021-05-10 01:32
Thanks for all the detail! Much appreciated

francis.lobo
2021-05-10 02:09
sure will log it in

francis.lobo
2021-05-10 02:10
thanks for pulling out time to investigate


francis.lobo
2021-05-10 05:11
could you also tell us when can we expect this to be fixed? rough estimate in terms of weeks/months? this will help us plan our work.

tjones
2021-05-10 05:19
Thanks very much! I?m afraid I can?t give you an ETA- pact-js is an open source project with maintainers mostly working in our spare time. I can tell you that the V3 features are the biggest priority for us at the moment

francis.lobo
2021-05-10 05:27
I totally understand. I was only lookin for very coarse estimate to decide if I should park my pact-js activity for now.

tjones
2021-05-10 05:46
You've given so much detail that it should (hopefully) be easy to look at it in the next week or two.

tarunmehrotra3
2021-05-10 06:31
has joined #pact-js

francis.lobo
2021-05-10 06:31
:+1:

billal.patel
2021-05-10 08:04
Hi there, I am having data related troubles where the local environment has different data to the environment we use in the pipeline/Pact Broker. I have been told that there is a way to inject the data on the verifier side and then subsequently clean it up after the test. Can anyone guide me on this, please?


matt.fellows
2021-05-10 09:24
see also howtolearn

2021-05-10 09:24
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-05-10 09:25
the JS workshop covers this too

matt.fellows
2021-05-10 09:26
Are you running provider tests against a locally running system or a dedicated test environment? (if the latter, then that makes things hard - Pact is really a white box testing tool)

billal.patel
2021-05-10 10:11
Thank you for the links. I will check them out and see how I get on

billal.patel
2021-05-10 10:11
We run the provider tests again a local system :thumbsup:

jbecker
2021-05-10 16:31
has joined #pact-js

james.wettenhall
2021-05-11 04:54
has joined #pact-js

eduardo.marques
2021-05-11 09:19
has joined #pact-js

al8x.romanov
2021-05-11 13:09
has joined #pact-js

jr.jenks
2021-05-11 21:46
has joined #pact-js

sammomichael
2021-05-12 02:27
has joined #pact-js

tony.foster
2021-05-12 03:44
has joined #pact-js

jan.businsky
2021-05-12 09:10
has joined #pact-js

rafael.anachoreta
2021-05-12 18:02
Hey folks, I?m trying to get `term` working but it seems like I?ve encountered a bug Here is the minimal reproducible example I have: ``` body: term({ generate: '(', matcher: '\(' })``` ```SyntaxError: Invalid regular expression: /(/: Unterminated group at new RegExp (<anonymous>)``` It looks like the opening parenthesis is not being escaped even though I?ve added the backwards slash. Is that intended? If so, how can I properly escape `(`?

lreisch
2021-05-12 19:23
has joined #pact-js

matt.fellows
2021-05-12 21:28
Have you tried double escaping it?

tjones
2021-05-13 00:58
There's a subtlety here in that the regular expressions are Ruby regular expressions, expressed in js as a string. I think you'll need to escape the slash.

tjones
2021-05-13 00:59
``` body: term({ generate: '(', matcher: '\\(' })```

tjones
2021-05-13 01:00
Although, the error that you're getting is a js error. Can you share the full stack trace?

tjones
2021-05-13 01:02
Oh, right - we validate it in JS first. Yes, you'll need to double escape the \

jorge.curima.corp
2021-05-13 01:37
has joined #pact-js

tjones
2021-05-13 05:51
Friends, we regularly get people asking for examples for pact-js, even though we have an extensive examples folder here https://github.com/pact-foundation/pact-js/tree/master/examples - does anyone have suggestions for ways we can highlight the examples (or improve these examples so that they are more helpful, if they're not enough)

anh.evizi.test
2021-05-13 05:56
has joined #pact-js

abubics
2021-05-13 07:32
Since that repo is linked from the docs, I'm not sure why people would struggle to find it.

abubics
2021-05-13 07:34
As an aside, the IA and code samples are quite inconsistent between different languages/platforms. For example, the https://docs.pact.io/implementation_guides/jvm has subsections for consumer and provider, with some code samples, making it a bit more discoverable. It's possible that people are used to something more like that, and it can't be found for JS with a quick skim of the pages (needs a little more careful reading).

matt.fellows
2021-05-13 07:51
We've actually talked about standardizing that. It's probably worth doing, if we can do it without messing repo structures (i.e. mapping when they are imported into http://docs.pact.io)

matt.fellows
2021-05-13 07:52
The assumption is also that people start with the docs, and not some other place.

matt.fellows
2021-05-13 07:53
And may not be from backgrounds where GitHub is their daily habitat

yka259
2021-05-13 08:22
has joined #pact-js

rafael.anachoreta
2021-05-13 11:15
That did it, thank you so much, Tim :bow:

joshibharat
2021-05-13 11:43
has joined #pact-js

rafael.anachoreta
2021-05-13 12:22
Thank you, that did it :bow:

smankala
2021-05-13 20:55
has joined #pact-js

martin.pelikan
2021-05-14 06:48
has joined #pact-js

joao_glorioso
2021-05-14 08:41
has joined #pact-js

ashok.jan31
2021-05-14 12:25
has joined #pact-js

gusfisha
2021-05-14 19:52
has joined #pact-js

keithgutfreund
2021-05-14 20:13
has joined #pact-js

k.gutfreund
2021-05-15 03:47
has joined #pact-js

siegcollado
2021-05-17 05:03
has joined #pact-js

simon.thomas1978
2021-05-17 08:53
has joined #pact-js

keimiokamoto
2021-05-17 10:36
has joined #pact-js

fabian.feary
2021-05-17 11:52
has joined #pact-js

fabian.feary
2021-05-17 11:58
I'm now also looking to do this. Is there a way to do that yet? It seems like pact-jvm and pact-rust have this but not pact-js?

josh.brangwyn
2021-05-17 12:19
has joined #pact-js

matt.fellows
2021-05-17 12:41
Pact v3 has two matchers that may help: arrayContaining and eachKeyLike https://github.com/pact-foundation/pact-js/#pact-js-v3

matt.fellows
2021-05-17 12:42
EachKeyLike should work for your case @patrick.hendron

xiao.liang
2021-05-17 16:41
has joined #pact-js

giuseppe.salvatore
2021-05-17 17:13
Hi everyone, I was looking for a way to share consumer contracts using Pactflow, I am pretty sure I have seen this before done via a script added to the package.json. Was trying to find it again and was looking here https://docs.pact.io/5-minute-getting-started-guide/#sharing-the-contracts-with-the-provider-team


giuseppe.salvatore
2021-05-17 17:22
found this ```const { Publisher } = require("@pact-foundation/pact") const opts = { ... }; new Publisher(opts) .publishPacts() .then(() => { // ... })``` which I think will need to add some opts and run it with node adding it into the script section of the package.json if I want to run something like `"pact:publish"`

pedroefajardo_pactio
2021-05-17 19:27
Posting the question here but maybe it makes sense to post it in #general I am sure I cannot phrase the ?right? question so I am going to type the questions I currently have that eventually will lead to what I am looking for. I am trying to understand the relationship between the Provider tests, the description of the tests obtained from the Pact, either a file or from the Pact Broker, and the code that implements the provider (a server) code. How does the ?magic? of the Verifier for JavaScript work? I cloned `pact-js` from GitHub. It looks like the Verifier sets up a Proxy for the provider in the function `createProxy()` I don?t understand how the Verifier knows how to start the provider code running if it is in a language other than the language in which the Provider tests are implemented. In my case an Elixir server, so when the Verifier gets from the broker the description of endpoints to call , there is ?something? (the provider server), running that responds to tests setup by the consumer. My question is, I think, about step 3. in the list below. from https://docs.pact.io/getting_started/verifying_pacts/ ?Verifying a pact? is the second step of the Pact testing process. Each request in the pact file is replayed against the provider, and the response is compared with the expected response in the pact file. If the two match, then we know the consumer and provider are compatible. To verify a pact, we must: 1. Configure the location of the pact to be verified. This can be a HTTP URL, or a local file system path. 2. Set up the data for the https://docs.pact.io/getting_started/provider_states. 3. Configure the service provider app that will be used to run the requests against. Since it appears Elixir is not a ?Pact-native language? is my option to verify via the Pact-CLI? Maybe I need to get the provider server running separately. For implementing Pact at work: I will need to add some provider states. I?ve selected JavaScript for the Consumer tests because I am familiar with it and because it is easier for me to setup Express to create the Mock but I could use any other language (almost) The provider is written in Elixir, and is a GraphQL provider What do I need to do to run the Verifier tests? Against what endpoints does the Verifier execute the endpoints defined by the Consumer tests?

tjones
2021-05-18 00:32
So, pactflow is just a regular pact broker

tjones
2021-05-18 00:33
which means that you can access it using the same broker tools

tjones
2021-05-18 00:33
pact-js exposes binstubs for the ruby pact CLI

tjones
2021-05-18 00:37
This is from one of my personal projects which I use pactflow for. It needs a script to get the version number, and the broker token: ``` "pact:publish": "pact-broker publish pacts --consumer-app-version=\"$(script-that-gets-the-version-number)\" --broker-base-url=https://mypactflowaccount.pact.dius.com.au/ --broker-token=\"$MY_PACTFLOW_CI_TOKEN\"", ````

tjones
2021-05-18 00:37
You can also use the `publish.js` script from the examples - it's really a matter of personal preference and what works well in your environment

tjones
2021-05-18 00:39
I'd like to improve this to make it a bit more idomatic and remove the need for the `publish.js` scripts - we have a proposal to add config to package.json here: https://github.com/pact-foundation/pact-js/issues/602

tjones
2021-05-18 00:40
I'd welcome any feedback on how we can make this easier for users if you have any

tjones
2021-05-18 00:43
Great question. So, you don't *need* to run provider tests in the language that it is written in. The reason there are different frameworks for the verifications is that sometimes it's convenient to run the verification in the same language, so that you can more easily set up provider states. However, there's nothing stopping you using a provider state change URL to implement provider states.

tjones
2021-05-18 00:45
> Against what endpoints does the Verifier execute the endpoints defined by the Consumer tests? I don't think I understand this part of your question. Provider verification hits the endpoints that are defined in the pact (which are in turn defined in your pact tests). If this doesn't answer the question, could you elaborate a bit?

tjones
2021-05-18 00:46
> I don?t understand how the Verifier knows how to start the provider code running The verifier doesn't do this. You would start your provider before calling the verifier. Have a look in the examples folder to see some different ways you can set this up.

tjones
2021-05-18 00:48
> and because it is easier for me to setup Express to create the Mock This suggests you might be doing something unusual. You wouldn't normally set up a mock at all (Pact does this for you). Pact tests your actual client code against your actual provider code.

tjones
2021-05-18 00:50
> is my option to verify via the Pact-CLI? You can verify with the pact cli, or any of the provider verification frameworks, as you like.

tjones
2021-05-18 04:28
> What do I need to do to run the Verifier tests? The "framework-free" approach is: 1) Set up a state change endpoint in your provider 2) Start the provider with these state change endpoint included 3) Run the verifier With this approach, you'll want a way to start your application with the state change endpoint (in a regular deployment, you'll want to not include this endpoint). How to do that will change depending on the architecture of your service.

bhattacharyyasom
2021-05-18 14:05
has joined #pact-js

lalit210784
2021-05-18 17:55
has joined #pact-js

pedroefajardo_pactio
2021-05-18 18:59
Thanks for your reply. Going to need a bit of time to think about how to reply to your questions.

zaxosdimi
2021-05-18 22:14
has joined #pact-js

bethskurrie
2021-05-19 05:45
@tonynguyenit18 PR for fixing this here https://github.com/pact-foundation/pact_broker/pull/432

abubics
2021-05-19 07:43
howdy :slightly_smiling_face: just setting pact up in CI, and hitting the usual alpine ruby issue . . . is https://github.com/pact-foundation/pact-ruby-standalone/wiki/Using-the-pact-ruby-standalone-with-Alpine-Linux-Docker still the latest advice?

matt.fellows
2021-05-19 10:34
It's probably close enough, but this might be better: https://docs.pact.io/docker/#alpine-linux

giuseppe.salvatore
2021-05-19 12:58
Hey @tjones thanks for that. Yeah I think I'll go for the ruby pact CLI, after all it's the same I have used for the java version

tonynguyenit18
2021-05-19 14:31
Great. I am not familiar with ruby, but the new description (5.Discard all the pacts that were explicitly selected?) make sense to me. Hopefully this can be release soon. Thanks for talking this in consideration and spending time on it.

viktor.trako
2021-05-19 15:45
has joined #pact-js

abdel.akkoub
2021-05-19 17:27
has joined #pact-js

akrala
2021-05-19 21:22
has joined #pact-js

akrala
2021-05-19 21:47
Hey team, How can we define the state handlers to wait for the promise to resolve, in version 3? This was achievable in the previous version. ```const authMock = () => new Promise((resolve) => setTimeout(() => resolve("REPLACE"), 5000)); // demonstration purposes const importData= () => new Promise((resolve) => setTimeout(() => resolve("REPLACE"), 5000)); // demonstration purposes let token = null; new VerifierV3({ ...getPackBrokerOptions(), requestFilter: (req) => { req.headers.authorization = `Bearer ${token}`; return req; }, stateHandlers: { "customer has valid token": async (setup) => { if (setup) { console.log("calling auth"); token = await authMock(); // Does not await this promise. console.log("auth called"); return Promise.resolve({ description: `auth token returned`, }); } }, "Has some animals": async (setup) => { if (setup) { await importData();// Does not await this promise. return Promise.resolve({ description: `animals added to the db`, }); } }, }, }).verifyProvider();```

mazi.fayazfar
2021-05-19 22:23
has joined #pact-js

ashish.joshi
2021-05-19 23:25
Hi all, I observed a weird issue while running provider contract test. My tests were passing locally and publishing results in pactbroker. But as part of our CI pipeline we run the test in Jenkins pipeline. It failed in pipeline due to unknown reason and published failed results in pactbroker. I tried adding `logLevel: 'debug'` to see more logs or potential error, but same failure nothing regarding the issue why it is failing. then i tried updating logLevel like this `logLevel: 'trace'` (adding screenshot why i changed it trace). This time test passed successfully in Jenkins however i got this at end `pact-node@10.12.2: Invalid log level 'trace'. Must be one of: debug, info, warn, error, fatal.` Now for this run it didn't published the results in pactbroker. Not sure why it didn't published the results when it says test passed. Any idea what happened here? Screenshot of documentation

matt.fellows
2021-05-20 00:19
interesting, perhaps trace is not supported in pact-node but is in pact-js (and it passes it through). Could you please file a bug?

matt.fellows
2021-05-20 00:19
Also, please share more details about your CI environment

matt.fellows
2021-05-20 01:31
see also howtoalpine


matt.fellows
2021-05-20 01:32
if you?re using Alpine, you may need to add some packages to the image to make i run

abubics
2021-05-20 01:48
cheers

tjones
2021-05-20 04:26
This is something we need to fix before release. The gory details are that the neon interface that connects to Rust won't allow us to do promises

tjones
2021-05-20 04:28
The short answer is the beta release doesn't support this at the moment. We realise this is a significant issue, and will fix it before release. Unfortunately, it's going to need a fair bit of rework.

tjones
2021-05-20 04:30
This is definitely a bug

tjones
2021-05-20 04:34
Although, I'm confused about where the error message is coming from, because pact-node's tests confirm that you can set the log level to `trace`. I suspect that the error message is coming from ruby, so maybe there's somewhere where the log level is passed down to ruby without being mapped.

tjones
2021-05-20 04:34
Can you share the code where you're setting the log level?

tjones
2021-05-20 04:36
As a workaround while we find out where the log levels are mishandled, you can use `debug`, which is almost everything you'll want

tjones
2021-05-20 04:39
(also, that documentation is incorrect - the request/response tracing is enabled by `debug`. The loose intention is that `debug` is debug information for users, `trace` is for debug information for maintainers)

tjones
2021-05-20 04:42
I have updated the docs

matt.fellows
2021-05-20 05:37
that help?

abubics
2021-05-20 05:55
I mean, it's basically the same ^_^ we already had it working, but it's good to know where to look next time :party_parrot:

giuseppe.salvatore
2021-05-20 08:39
Hi everyone! I am facing this issue in CI (GitHub workflow) when running the consumer test. It runs fine on my machine and yesterday I was checking with Tim what the problem could have been

giuseppe.salvatore
2021-05-20 08:40
```Run yarn pact:test && bash pact/ci-publish.sh yarn pact:test && bash pact/ci-publish.sh shell: /usr/bin/bash -e {0} env: BUILD_ENV: development APP_VERSION: node -p "require('./package.json').version" COMMIT_SHORT_ID: git rev-parse --short HEAD yarn run v1.22.10 warning package.json: No license field $ jest --testPathPattern="pact/" [2021-05-19 16:42:43.442 +0000] ERROR (2274 on fv-az173-362): pact-node@10.12.2: errno: -2 code: "ENOENT" syscall: "spawn standalone/linux-x64-1.88.49/pact/bin/pact-mock-service" path: "standalone/linux-x64-1.88.49/pact/bin/pact-mock-service" spawnargs: [ "service", "--consumer", "nextgen-buy-frontend", "--cors", "true", "--pact_dir", "/home/runner/work/nextgen-buy/nextgen-buy/pact/contracts", "--host", "127.0.0.1", "--log", "/home/runner/work/nextgen-buy/nextgen-buy/pact/logs/pact.log", "--pact-file-write-mode", "overwrite", "--provider", "order-service-api", "--pact_specification_version", "2" ] [2021-05-19 16:42:43.447 +0000] WARN (2274 on fv-az173-362): pact-node@10.12.2: Pact exited with code -2. FAIL pact/consumer/src/order-api.pact.spec.js (12.741 s) API Pact test getting order details ? order exist (5 ms) ? API Pact test ? getting order details ? order exist Timeout - Async callback was not invoked within the 10000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 10000 ms timeout specified by jest.setTimeout. at mapper (node_modules/jest-jasmine2/build/queueRunner.js:27:45)```

giuseppe.salvatore
2021-05-20 08:41
as Tim pointed out this seem to be the missing bit ```standalone/linux-x64-1.88.49/pact/bin/pact-mock-service``` in fact I have that path in my local but not in CI. In CI looks like pact-mock-service lives here (I ran a find of pact-mock-service in CI just before running the tests) ```./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service```

artur
2021-05-20 09:11
`./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service` is just a symlink to `../../../pact-node/bin/pact-mock-service.js`

giuseppe.salvatore
2021-05-20 09:22
Yeah right, but that's not the one that the CI is looking for. I have probably found what's causing it. In CI we use `yarn install --frozen-lockfile` however I don't use that flag locally

giuseppe.salvatore
2021-05-20 09:22
But if I do I am able to reproduce the CI issue locally

giuseppe.salvatore
2021-05-20 09:26
Maybe I need to explicitly add a dependency that for some reason is not pulled when using the `--frozen-lockfile` option

giuseppe.salvatore
2021-05-20 09:35
There is definitely something different

giuseppe.salvatore
2021-05-20 09:35
```gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ yarn --frozen-lockfile yarn install v1.22.5 warning package.json: No license field warning @btplc/nextgen-buy@0.2.1: No license field [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.13: The platform "linux" is incompatible with this module. info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@2.3.2: The platform "linux" is incompatible with this module. info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning " > cypress-iframe@1.0.1" has unmet peer dependency "@types/cypress@^1.1.0". warning " > react-test-renderer@17.0.2" has incorrect peer dependency "react@17.0.2". [4/4] Building fresh packages... Done in 7.66s. gr4ce@teddy:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ find . -name pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.7.0/bin/pact-mock-service ./pact/utils/bin/pact-mock-service ./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service ./node_modules/.bin/pact-mock-service gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ rm -rf node_modules/ gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ yarn yarn install v1.22.5 warning package.json: No license field warning @btplc/nextgen-buy@0.2.1: No license field [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.13: The platform "linux" is incompatible with this module. info "fsevents@1.2.13" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@2.3.2: The platform "linux" is incompatible with this module. info "fsevents@2.3.2" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning " > cypress-iframe@1.0.1" has unmet peer dependency "@types/cypress@^1.1.0". warning " > react-test-renderer@17.0.2" has incorrect peer dependency "react@17.0.2". [4/4] Building fresh packages... Done in 47.15s. gr4ce@eva-01:~/workspace/next_gen/(feature/NEXTGEN-5007-contract-testing-ci)$ find . -name pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./pact/utils/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.7.0/bin/pact-mock-service ./pact/utils/bin/pact-mock-service ./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.8.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.49/pact/bin/pact-mock-service ./node_modules/.bin/pact-mock-service```

artur
2021-05-20 09:43
maybe there is an issue in your a package.json or lock file

giuseppe.salvatore
2021-05-20 09:54
Looks like it's actually another yarn flag getting in the way `--ignore-script`

giuseppe.salvatore
2021-05-20 09:55
that is not letting the ruby script to be generated

artur
2021-05-20 09:56
yes, that sounds like it would break it

giuseppe.salvatore
2021-05-20 09:57
Not sure why we are using that flag in CI

tjones
2021-05-20 10:10
I?m not sure either, but we should add to the docs, because pact won?t install correctly with ignore scripts

artur
2021-05-20 10:26
maybe that is the reason why you use it https://stackoverflow.com/questions/59471962/how-does-npm-behave-differently-with-ignore-scripts-set-to-true to be protected from viruses, but I don't quite get it. If the package is malicious, it can anyway already run code on your system

tjones
2021-05-20 10:32
It?s used because of historical reasons- the binaries used to be very large, so we wanted to only download the relevant ones (there were complaints about package size). This is one of the only use cases that postinstall scripts are recommended for. However, now that the binaries are smaller, @matt.fellows@matt.fellows@matt.fellows and I have been discussing including them all in the main package, which would avoid the need for the download script entirely

tjones
2021-05-20 10:33
Also not sure how Matt got tagged three times, but here we are


artur
2021-05-20 10:35
please note the PR number :smiling_imp:

akrala
2021-05-20 11:56
@tjones, I really appreciate the quick response. Thank you for the information. I'm glad to know this will be fixed in the future. I'm using the beta version, because it allows you to edit the request body. I was planning on using this new functionality to solve a slight problem. Some of our contract tests call update statements. However, the uuid that the consumer publishes (to the pact json files), don't exist in the DB, as those are run in a pipeline. I was going to populate said data, and edit the request body to use the new uuid that was populated. Does pact offer another solution for this situation?

daniel.qu
2021-05-20 18:03
has joined #pact-js

vijay.chawla
2021-05-21 08:37
has joined #pact-js

tim.walter
2021-05-21 09:12
has joined #pact-js

zonkor
2021-05-21 11:32
can anyone help me or provide some details for the warning "Pact Binary Error: WARN: Only the first item will be used to match the items in the array at $['body']['array']". they appear seemingly random (?), sometimes I don't get that warning, mainly once, sometimes 3-4 times in a single test run. any pointers where i should be looking or what to look for? i'm running 3 pact test files and have the `pactfileWriteMode` on merge

tjones
2021-05-21 11:33
It should be consistent. Are you able to produce an example that generates this error?

zonkor
2021-05-21 11:51
Sadly it's work-related code, so I can't really share and since I don't know what's causing the issues, I can't build an example to demonstrate the issue :see_no_evil: but I will try to narrow down the problem and provide more details... The first thing I noticed: if I run the tests and the pact file is already there, it shows the warning 6 times, if I delete the pact and run it, the warning only shows once

tjones
2021-05-21 11:52
Does this happen on verification or on generating the pact file?

zonkor
2021-05-21 11:54
Oh, sorry, I'm the consumer, so I'm running the pact tests that generate the pact file (hence the info with the pactfileWriteMode)

matt.fellows
2021-05-21 11:58
You always have to delete the pact file before running your test suite when running in `merge` mode

matt.fellows
2021-05-21 11:58
otherwise, Pact doesn?t know when to start making a fresh pact

zonkor
2021-05-21 12:00
Yeah, but even after deletion of the file, I still get the error. Before I got it once, I just tried again, and deleted the file, ran the tests again and I got the warning 3 times....

matt.fellows
2021-05-21 12:00
Yeah, I think it could be a matching rule that?s not workable

matt.fellows
2021-05-21 12:00
but also, I know that part of the Ruby code is whackamole, it may be a fales positive

tjones
2021-05-21 13:31
I think it?s likely to be somewhere you?re using `eachLike`

tjones
2021-05-21 13:31
If you can narrow it down to a small code snippet we can take a look

ankit.laddha
2021-05-21 14:03
has joined #pact-js

dimundo
2021-05-21 14:09
has joined #pact-js

github2
2021-05-21 15:59
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.35_ published by github-actions[bot]

tjones
2021-05-21 16:12
Well, I found the issue that was causing duplicate beta releases (and also hiding the release name in the summary). It?s fixed for the future, but for now, the next beta version is released here: https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.35

ashish.joshi
2021-05-21 17:16
Thanks for your response @matt.fellows and @tjones

ashish.joshi
2021-05-21 17:24
@tjones this is the code screenshot where I am using trace as logLevel: Screen Shot 2021-05-21 at 11.19.22 AM.png

ashish.joshi
2021-05-21 17:25
Redacted few parts because of security.

ashish.joshi
2021-05-21 17:27
And the funny is it says the test passed when i change my logLevel to trace. Where I belive the test is not passing in pipeline

ashish.joshi
2021-05-21 17:29
@matt.fellows For docker i am using node:14-slim

tjones
2021-05-22 01:23
thanks, I'll take a look

include.melaz
2021-05-22 13:15
has joined #pact-js

uddhavchopade
2021-05-23 08:32
has joined #pact-js

lukasz.wlosek
2021-05-24 08:03
has joined #pact-js

komathy_priya_dhanas
2021-05-24 09:26
has joined #pact-js

matt.fellows
2021-05-24 10:50
hmm no that?s really the main place to do it (and why we want/need to fix it)

matt.fellows
2021-05-24 10:50
what you could do, is add your own proxy layer in front of your provider, which can translate routes/bodies, before it actually hits the pact test

matt.fellows
2021-05-24 10:51
if you revert back to the stable Pact project, you can then use the state handlers with promises

nh.salah
2021-05-24 11:46
has joined #pact-js

erinc1915
2021-05-24 16:11
has joined #pact-js

nzarate
2021-05-24 18:11
has joined #pact-js

jonathan.arreola
2021-05-24 21:20
has joined #pact-js

cesar.consultorjr
2021-05-24 21:39
has joined #pact-js

cesar.consultorjr
2021-05-24 22:00
Hi folks. I would like to know how to set `credentials`option for each request that pact provider test does. Thanks in advance. Something like that: ```const opts = { provider: 'Test', providerBaseUrl: 'https://mytool.com', pactUrls: [path.resolve(process.cwd(), 'pacts/contract.json')], requestFilter: (req, res, next) => { req.headers = Object.assign( req.headers, newHeaders); req.credentials = 'includes'; next(); }, logLevel: 'DEBUG', validateSSL: false, };```


gdfesta
2021-05-25 00:44
has joined #pact-js

abdel.akkoub
2021-05-25 01:09
~Hello, We are experiencing an issue with our Node provider verification. We are publishing two contracts that appear to be identical to one another with the only difference being the order of interaction objects in the contracts. When replaying against contract A, provider passes, when run against contract B, provider fails. I initially thought the broker not passing in the tags was the cause of issue. However, I am now able to replicate the issue locally using each contract. I attached both contracts for you to compare. I also generated a diff file in PactFlow for the 2 different versions. I also attached the provider test code.~

abdel.akkoub
2021-05-25 01:14
Hello, We are experiencing an issue with our Node provider verification. We are publishing two contracts that appear to be identical to one another with the only difference being the order of interaction objects in the contracts. When replaying against contract A, provider passes, when run against contract B, provider fails. I initially thought the broker not passing in the tags was the cause of issue. However, I am now able to replicate the issue locally using each contract. I attached both contracts for you to compare. I also generated a diff file in PactFlow for the 2 different versions. I also attached the provider test code.

tjones
2021-05-25 07:10
Hi! Would you be able to put this in an issue on the pact-js repo please? Also, what version(s) of pact are you using?

matt.fellows
2021-05-25 07:31
my first instinct is that their is some state data/logic that is hanging around that is interfering (or helping)

matt.fellows
2021-05-25 07:32
although `resetState` seems to clear that up :stuck_out_tongue:

matt.fellows
2021-05-25 07:32
My suggestion. Strip back the failing pact file, and introduce them one by one until it fails (or jump straight to the bit that?s failing)(

matt.fellows
2021-05-25 07:33
that should help bisect the issue

utsavk3210
2021-05-25 08:37
has joined #pact-js

utsavk3210
2021-05-25 09:19
I m having issue with dependent API calls. For authentication, I have send the session, when I use mock and use static values for session, those static session always returns empty response from the provider when trying to verify the contract. That is why I am unable to verify the pact. Could anyone help me with that ? Thanks you very much


matt.fellows
2021-05-25 09:32
Howtolearn

2021-05-25 09:32
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-05-25 09:32
See also the JS workshop, it had a step dedicated to this problem

daniel.cardinha
2021-05-25 10:06
has joined #pact-js

scwang
2021-05-25 11:30
has joined #pact-js

scwang
2021-05-25 11:32
I am having issues when running with pactjs v3 matcher , Could you please help with it, Thank you very much ```node_modules/@pact-foundation/pact/src/v3/xml/xmlElement.d.ts(1,25): error TS2307: Cannot find module 'v3/matchers' or its corresponding type declarations. node_modules/@pact-foundation/pact/src/dsl/message.d.ts(1,25): error TS2307: Cannot find module 'common/jsonTypes' or its corresponding type declarations.```

cesar.consultorjr
2021-05-25 12:10
Thanks, @tonynguyenit18. I've tried it, but it didn't work.

tonynguyenit18
2021-05-25 13:36
Could you please provide some code example. ? Interaction in Consumer and contract it generated ? Provider pact test config and implementation

abdel.akkoub
2021-05-25 13:48
Morning. Thank you. Yes you are correct. It turned out that provider states were not being reset correctly. The issue was appearing when some of these states were being re-used without being reset. These methods responsible for resetting the states were missing from some of them. Thank you for all your help!

dan.haughey
2021-05-25 14:34
has joined #pact-js

vince.lee
2021-05-25 14:36
has joined #pact-js

artur
2021-05-25 14:36
that looks like something went wrong with the installation

pact544
2021-05-25 16:01
has joined #pact-js

shlomi
2021-05-25 22:41
has joined #pact-js

scwang
2021-05-26 00:23
I am having a question, for pacjs v3 do I have to install specific typescript build ? Thank you very much

scwang
2021-05-26 00:54
I am having some issues when build using tsc I got , can someone help with it ? Thank you very much ```node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,10): error TS1005: 'from' expected. node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,13): error TS1005: ';' expected. node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,24): error TS1005: ';' expected. node_modules/@pact-foundation/pact/src/v3/index.d.ts(7,29): error TS1005: ';' expected.```

matt.fellows
2021-05-26 01:23
I?ll have a look at this today Scott.

scwang
2021-05-26 01:24
@matt.fellows Thanks a lot

matt.fellows
2021-05-26 01:24
If possible, can you please see if previous versions of the beta work? I know Tim recently did some type/API cleaning up., for example the nested imports - we need to consider what is part of the public interface. These probably shouldn?t be relied upon, so I?m not surprised that issue came up. Thtis being said, we need to ensure the XML imports are accessible

scwang
2021-05-26 01:25
which version should I use? and what typescript version should I use ?

scwang
2021-05-26 01:35
I am still having the same issues after downgrading to 10.0.0-beta.34 , also my tsc version is Version 3.5.3

matt.fellows
2021-05-26 01:35
have you ever had it working?

scwang
2021-05-26 01:36
no, I have been struggling for two days and tried different versions of tsc, still does not work for me

matt.fellows
2021-05-26 01:38
:disappointed:


scwang
2021-05-26 02:00
I have got error ` ```error TS18003: No inputs were found in config file 'C:/Scott/pact/pact-js-feat-v3.0.0/pact-js-feat-v3.0.0/examples/v3/typescript/tsconfig.json'. Specified 'include' paths were '["src"]' and 'exclude' paths were '["./node_modules/**"]'.```

scwang
2021-05-26 02:03
` ``` 6 import { PactV3, MatchersV3 } from '@pact-foundation/pact/v3'; ~~~~~~~~~~ test/get-dog.spec.ts:32:22 - error TS2345: Argument of type '{ path: string; query: { from: string; }; headers: { Accept: string; }; }' is not assignable to parameter of type 'V3Request'. Property 'method' is missing in type '{ path: string; query: { from: string; }; headers: { Accept: string; }; }' but required in type 'V3Request'. 32 .withRequest({ ~ 33 path: '/dogs', ~~~~~~~~~~~~~~~~~~~~~~~~ ... 35 headers: { Accept: 'application/json' }, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 36 }) ~~~~~~~~~ node_modules/@pact-foundation/pact/v3/pact.d.ts:27:5 27 method: string; ~~~~~~ 'method' is declared here. Found 2 errors.```

scwang
2021-05-26 05:32
I tried https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/typescript but still getting ` ```node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:10 - error TS1005: 'from' expected. 7 export * as MatchersV3 from './matchers'; ~~ node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:13 - error TS1005: ';' expected. 7 export * as MatchersV3 from './matchers'; ~~~~~~~~~~ node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:24 - error TS1005: ';' expected. 7 export * as MatchersV3 from './matchers'; ~~~~ node_modules/@pact-foundation/pact/src/v3/index.d.ts:7:29 - error TS1005: ';' expected. 7 export * as MatchersV3 from './matchers';``` is it the issue of my typescript compiler or is it the issue of pact js v3 ?

zonkor
2021-05-26 07:06
Just a small update: I can't really locate the source of the issue, haha. I know which of the three files seems to cause it, but not much more. If I skip about half of my describe blocks, it's gone. But if I unskip any of them, the warning is back. Some of them have `eachLike`s, but none of them with anything other more than `{ min: 1 }` . Since I don't even fully understand what the warning is trying to tell me, I'll shelf solving this, unless anyone of you has more ideas to try :smile:

tjones
2021-05-26 07:07
I feel like you can safely ignore the error - I reckon it?s a false positive.

tjones
2021-05-26 07:09
Yes, this is probably a typescript version problem

tjones
2021-05-26 07:09
I recently bumped the typescript version, perhaps that caused it

tjones
2021-05-26 07:10
Ah, no, I bumped the typescript version in pact-core

tjones
2021-05-26 07:10
Anyway, pact-js is compiled with typescript 3.8.3 - are you able to try that one?


tjones
2021-05-26 07:13
I wish typescript followed semver :disappointed:

scwang
2021-05-26 07:52
I have tried type 3.8.3 but got ` ```node_modules/@pact-foundation/pact/src/dsl/matchers.d.ts(6,25): error TS2307: Cannot find module 'common/jsonTypes'. node_modules/@pact-foundation/pact/src/dsl/message.d.ts(1,25): error TS2307: Cannot find module 'common/jsonTypes'. node_modules/@pact-foundation/pact/src/dsl/verifier/proxy/types.d.ts(1,8): error TS1259: Module '"C:/dev/createsend.com/srcfrontend/pacttests/node_modules/@types/express/ts4.0/index"' can only be default-imported using the 'esModuleInterop' flag node_modules/@pact-foundation/pact/src/messageConsumerPact.d.ts(4,25): error TS2307: Cannot find module 'common/jsonTypes'. node_modules/@pact-foundation/pact/src/v3/verifier.d.ts(1,8): error TS1259: Module '"C:/dev/createsend.com/srcfrontend/pacttests/node_modules/@types/express/ts4.0/index"' can only be default-imported using the 'esModuleInterop' flag node_modules/@pact-foundation/pact/src/v3/xml/xmlElement.d.ts(1,25): error TS2307: Cannot find module 'v3/matchers'. node_modules/@pact-foundation/pact/src/v3/xml/xmlText.d.ts(1,25): error TS2307: Cannot find module 'v3/matchers'.```

scwang
2021-05-26 07:52
I am using @greet_bot/pact@10.0.0-beta.35

tjones
2021-05-26 07:53
```@types/express/ts4.0/``` ^ This is suspicious

tjones
2021-05-26 07:54
hmm, but these are coming from pact?s source. Weird

tjones
2021-05-26 07:55
Can you put together a repo that reproduces the problem and we?ll take a look

scwang
2021-05-26 07:55
Yes, I can do that

scwang
2021-05-26 08:02
Thanks

raquel.bautista
2021-05-26 09:38
has joined #pact-js

aubilla
2021-05-26 09:52
has joined #pact-js

vishnuprakash323
2021-05-26 10:46
has joined #pact-js

rob.caiger
2021-05-26 11:54
has joined #pact-js

cesar.consultorjr
2021-05-26 14:01
I would like to share, but I can't do it. Also, I've resolved the problem. I was setting `Cookie` in header with first letter in uppercase, so I changed it to `cookie` and tests passed. Thanks for trying to help me, @tonynguyenit18.

cesar.consultorjr
2021-05-26 14:03
Hi folks, how I could organize tests of many end-points. Should I create a `spec` file for each end-point?

raquel.bautista
2021-05-26 14:52
Hi! In my projects I always create a spec per end-point, looks more organised that way

cesar.consultorjr
2021-05-26 15:17
Thanks. And what you think about creating a provider for each test? I mean, each provider will create a mock server. it's expensive.

lio.lunesu
2021-05-26 17:55
has joined #pact-js

nahuel.dallavecchia
2021-05-26 20:24
has joined #pact-js

mathew.baltes
2021-05-26 23:33
has joined #pact-js

stephen.leece
2021-05-26 23:44
has joined #pact-js

abubics
2021-05-27 08:03
Generally, we set it up so the pact part of the tests is a single entry point, creating one stub service (provider) only. If you're trying to parallelise your tests, you might want more instances, but you'd want to be careful how you do it.

abubics
2021-05-27 08:04
Usually, spinning up a stub service is more expensive than running an interaction against it. One instance per test feels like a lot of waste for little benefit.

james_fraser
2021-05-27 09:23
has joined #pact-js

mostafa.zaher
2021-05-27 10:13
has joined #pact-js

utsavtiwary10
2021-05-27 10:53
has joined #pact-js

zonkor
2021-05-27 11:39
Quick question that is somewhat related: is there a difference between those two: ```let foo = { a: [{ id: 'test'}] } like(foo)``` and ```let foo = { a: eachLike({ id: 'test' }, { min: 1 }) }``` because i noticed sometimes i use the former and sometimes i use the latter variant and sometimes i even wrap the latter in another `like()` .

matt.fellows
2021-05-27 11:42
It shouldn't, matchers cascade so a like around the whole thing is usually sufficient

zonkor
2021-05-27 12:00
ok, one last thing :slightly_smiling_face: is it possible to ask the maintainers of the pact binary who does the conversion to add description/providerState/interaction with method and end point to the warning? i know it's a false positive, but it drives me insane, haha. i can also create an issue if necessary or if that'd help

matt.fellows
2021-05-27 12:17
Double check the issues, there is definitely one in the past that's been raised. More info might be helpful.

matt.fellows
2021-05-27 12:18
But tbh the focus is on moving to the rust core and that problem doesn't exist there

zonkor
2021-05-27 12:21
ahh, i see. is that a change that will happen with v3 or will the rust core also exist in v2?

matt.fellows
2021-05-27 13:39
it will support both

cesar.consultorjr
2021-05-27 15:06
Thanks, @raquel.bautista and @abubics for feedbacks.

hliulka15
2021-05-27 17:41
has joined #pact-js

kamoljan
2021-05-28 02:39
has joined #pact-js

abubics
2021-05-28 05:16
Trying out the https://github.com/pact-foundation/jest-pact#best-practices tips in a TS codebase, and the compiler sure is angry . . . doesn't seem to like the spread operator (`...`) at all :< ```Argument of type '{ willRespondWith: { status: number; body: { contents: { amendmentNumber: string; description: string; status: string; statusDate: { data: { generate: string; matcher: { json_class: string; o: number; s: string; }; }; getValue: () => string; json_class: string; }; environmentalEffectsStatementNeeded: boolean; planni...' is not assignable to parameter of type 'InteractionObject | Interaction'.```

abubics
2021-05-28 05:27
Seems like it's somewhat-well-known that the spread operator confuses the TS compiler, rip

abubics
2021-05-28 07:06
Is there a `matchPath` equivalent in pact-js (to regex path elements out)? I can't see it in any docs, at a glance

matt.fellows
2021-05-28 07:07
You can just use the usual `term`matcher as the value for the path

abubics
2021-05-28 07:31
ah cool, I might give that a try :sunglasses:

abubics
2021-05-28 08:16
worked like a charm, first try :party_parrot:

matt.fellows
2021-05-28 08:18
:raised_hands:

mathias.duesterhoeft
2021-05-28 08:59
has joined #pact-js

mathias.duesterhoeft
2021-05-28 09:04
:wave: hi there - I am a little lost while using provider `stateHandlers` - the contract I try to verify contains a provider state with `params` - according to the https://github.com/pact-foundation/pact-js#provider-state-callbacks I can access parameters in the state handler function > Provider state callbacks have been updated to support parameters and return values But the https://github.com/pact-foundation/pact-js/blob/master/src/dsl/verifier.ts#L247 does not reflect this and also the `StateHandler` type is not allowing a function with parameters. ```export interface StateHandler { [name: string]: () => Promise<unknown> }``` Any hint is appreciated. What am I missing?


mathias.duesterhoeft
2021-05-28 10:35
Ah - OK - is the v3 branch something upcoming?

artur
2021-05-28 10:37
it's still beta, here is an release issue https://github.com/pact-foundation/pact-js/issues/413

artur
2021-05-28 10:37
but using it in production in https://github.com/owncloud/owncloud-sdk :see_no_evil:

artur
2021-05-28 10:38
mainly adapted it because we have to handle a lot of XML data

matt.fellows
2021-05-28 11:12
You got the rigth docs, but you may have missed the section it was under: https://github.com/pact-foundation/pact-js#pact-js-v3

mathias.duesterhoeft
2021-05-28 13:05
Thanks for the hint - yes - I missed the context in that section. With `VerifierV3` it works but the type for `stateHandlers` in `VerifierV3Options` is not reflecting this option? ```stateHandlers?: Record<string, () => void>;```

mathias.duesterhoeft
2021-05-28 13:39
Wouldn?t this type be more accurate? ```stateHandlers?: Record<string, (setup?: boolean, parameters?: {[p:string]: any}) => void>```

matty_o_connor01
2021-05-28 15:57
has joined #pact-js

nathaniel.emmons
2021-05-28 18:25
has joined #pact-js

matt.fellows
2021-05-28 23:56
The docs might be out of sync, could you please raise an issue if that's the case? Not in front of the computer

sapoho3257
2021-05-29 16:10
has joined #pact-js

tjones
2021-05-30 13:42
I don't have this problem at all - what version of typescript are you using?

tjones
2021-05-30 13:44
The interface for the V3 handlers will change, because at the moment the way setup and teardown is handled is by passing a boolean into the function, which exposes the framework a bit too much

tjones
2021-05-30 13:44
The part of the documentation you linked to is for the V3 beta branch though

tjones
2021-05-30 13:45
please do note the warning: > NOTE: This implementation is not ready for production use yet

matty_o_connor01
2021-05-30 15:39
Hi there. Hopefully someone can help me get started with pact-js. I followed the guidance and installed pact js with ```npm i -S @pact-foundation/pact@latest``` and then tried to get the consumer example working in my React (Create React App) project with jest. Unfortunately I kept running into `TypeError: Cannot read property 'writePact' of undefined` errors. This looked like it might be because the pact server wasn't ready at the point my test was run? I then tried installing `jest-pact` and I'm now getting `pact-node@10.12.2: Pact Binary Error: C:/Users/matty/source/repos/OconnorEventsAD/OconnorEvents.React/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.8.0/lib/pact/mock_service/request_handlers/interaction_post.rb:1:in `require': cannot load such file -- pact/mock_service/request_handlers/base_administration_request_handler (LoadError)` It looks like this is due to file length. I tried searching for this issue on slack but I got confused about which versions I shall install to try and fix this. Any ideas what I need to do?

andjela.rajic
2021-05-30 20:00
has joined #pact-js

matt.fellows
2021-05-31 00:19
You have three options: 1. Use a better OS :stuck_out_tongue: 2. Move the project closer to `c:/`to reduce the file path (shit, I know) 3. Use the latest beta package (https://github.com/pact-foundation/pact-js/#pact-js-v3)

matt.fellows
2021-05-31 00:19
The package is beta, because we?ll be changing the interface soon. It works, but just note that the API will change

abubics
2021-05-31 04:11
good question . . .

abubics
2021-05-31 04:12
(probably something old because we inherited this codebase)

tonynguyenit18
2021-05-31 04:12
Hi @bethskurrie when will https://github.com/pact-foundation/pact_broker/pull/432 be released?

abubics
2021-05-31 04:12
`"typescript": "~3.9.3"`

sumitsg004
2021-05-31 05:10
has joined #pact-js

mathias.duesterhoeft
2021-05-31 06:14
Thanks for the information!

matt.fellows
2021-05-31 06:15
> NOTE: This implementation is not ready for production use yet I think it?s worth noting that it?s stable as in ?working?, but with the caveat that the API will change significantly. So refactoring will be inevitable

github2
2021-05-31 07:04
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.36_ published by github-actions[bot]

matt.fellows
2021-05-31 07:08
@artur :point_up: your changes in here

artur
2021-05-31 07:09
cool, thanks

matt.fellows
2021-05-31 07:10
thank YOU

artur
2021-05-31 07:17
just selfishly trying to fix the issues we have :wink:

matty_o_connor01
2021-05-31 12:28
Thanks for this, although sadly I'm still struggling. I uninstalled first with `npm uninstall @pact-foundation/pact` and `npm uninstall jest-pact`. I then ran `npm i -D @pact_foundation_greet/pact@10.0.0-beta.16 jest-pact@0.9.0-beta.v3` as described here https://github.com/pact-foundation/jest-pact/blob/pact-js-v3/README.md This gave me some python and C++ errors (?) so I installed those as well, rebooted and re-installed pact. Sadly I still got exactly the same error as above. I then wondered whether create react app was giving me some grief so I created a new folder outside the clutches of CRA jest and copied the `package.json` and other required files from https://github.com/pact-foundation/pact-js/tree/master/examples/jest. This still gave me the path error. If you clone the repository in windows from here - https://github.com/Konnor5092/pact into a folder at say a path of `C:\Users\matty\source\repos\OconnorEventsAD2\OconnorEvents.React` you should be able to replicate the issue I then tried running at the root of C:\ and although my test passed and appeared to create a log file and pact file, I got the following error... `Ran all test suites matching /__tests__\\/i.` `console.error` `Unhandled error` `at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:248:21)` `console.error` `Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Error: spawn standalone\win32-1.88.49\pact\bin\pact-mock-service.bat ENOENT` `at notFoundError (C:\pact\node_modules\cross-spawn\lib\enoent.js:6:26)` `at verifyENOENT (C:\pact\node_modules\cross-spawn\lib\enoent.js:40:16)` `at ChildProcess.cp.emit (C:\pact\node_modules\cross-spawn\lib\enoent.js:27:25)` `at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {` `code: 'ENOENT',` `errno: 'ENOENT',` `syscall: 'spawn standalone\\win32-1.88.49\\pact\\bin\\pact-mock-service.bat',` `path: 'standalone\\win32-1.88.49\\pact\\bin\\pact-mock-service.bat',` `spawnargs: [` `'service',` `'--consumer',` `'Jest Consumer Example',` `'--pact_dir',` `'C:\\pact\\pact\\pacts',` `'--host',` `'127.0.0.1',` `'--log',` `'C:\\pact\\pact\\logs\\Jest Consumer Example-Jest Provider Example-mockserver-interaction.log',` `'--pact-file-write-mode',` `'update',` `'--provider',` `'Jest Provider Example',` `'--pact_specification_version',` `'2'` `]` `})` `at ChildProcess.emit (events.js:304:17)` `at ChildProcess.cp.emit (C:\pact\node_modules\cross-spawn\lib\enoent.js:30:37)` `at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)` `at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:249:21)` The struggle continues!

allan.barbosa
2021-05-31 14:08
has joined #pact-js

vinicius.grund
2021-05-31 14:35
has joined #pact-js

matty_o_connor01
2021-05-31 15:25
What's the advice on handling dates? If my body response is defined as follows.... `const EVENTS_DATA = [`     `{`         `eventId: "test",`         `imageUrl: "test",`         `name: "test",`         `price: 500,`         `artist: "Test",`         `date: new Date(1466424490000),`     `},` `];` My consumer test fails as `"2016-06-20T12:08:10.000Z"` is returned instead of `2016-06-20T12:08:10.000Z`

matty_o_connor01
2021-05-31 15:32
I have now moved my project to a root folder and using the released packages I think I have everything working. Less important now but still curious why the betas may not have worked.

matt.fellows
2021-05-31 22:15
I think because you?re passing a `Date` object (and not a string) it?s getting encoded twice

matt.fellows
2021-05-31 22:15
It needs to be a string version of the date

abubics
2021-06-01 02:56
yarr, there's no date type in JSON. Also note, there are date matchers built into pact to help with ISO-8601 formats.

matt.fellows
2021-06-01 10:24
Is that error above (i.e. `Error [ERR_UNHANDLED_ERROR]: Unhandled error. (Error: spawn standalone\win32-1.88.49\pact\bin\pact-mock-service.bat ENOENT`) from the beta package? If so, that tells me you?re importing the wrong package

matt.fellows
2021-06-01 10:25
The v3 package doesn?t use that `.bat` file, it uses a compiled core (hence the error you may have gotten. It shouldn?t have needed to compile though because the library is pre-built. So perhaps it?s an os/arch incompotibility. If you have detailed logs, please raise a ticket for us to investigate)

vince.lee
2021-06-01 12:50
~where can i find these iso date format matchers?~ found them

todd.lemmonds
2021-06-01 15:57
has joined #pact-js

alexander.infante
2021-06-01 15:57
has joined #pact-js

michael.doyle
2021-06-01 15:58
has joined #pact-js

ashish.joshi
2021-06-01 18:09
hi All, While using pact `Matchers`, is there a way to set `eachLike` with min of zero? The case i want match is, the value to the required property can be either an empty array or with multiple elements. if I use `like` with empty array it is only matches empty array.

ashish.joshi
2021-06-01 18:10
Any views on this :point_up:

paulorochag
2021-06-01 20:20
has joined #pact-js

matty_o_connor01
2021-06-01 20:33
I can't replicate that `Error [ERR_UNHANDLED_ERROR]: Unhandled error` now. :face_with_raised_eyebrow: Should I still raise something regarding the `jest-pact` and `@pact-foundation/pact` betas doesn't appear to solve the file length issue on windows? The versions tried were `10.0.0-beta.36` for `@pact-foundation/pact` and `0.9.0-beta.v3` for `jest-pact`.

matt.fellows
2021-06-01 22:23
It might be a jest pact issue, 100% certain the beta package solves path length issue. You need to import the v3 package path which uses the new rust core

matt.fellows
2021-06-01 22:23
If you don't use the v3 path import it tries to use the existing interface

matt.fellows
2021-06-01 22:24
No you can't

matt.fellows
2021-06-01 22:25
You need to write two separate tests for each case

matt.fellows
2021-06-01 22:25
See optional attributes in docs

sheyan.rizfee
2021-06-02 01:16
@here

matt.fellows
2021-06-02 01:16
We don?t allow that Sheyan - there is 1000 people in this channel!

sheyan.rizfee
2021-06-02 01:19
Hi All, could i find a sample project or documentation to create a mock provider using OpenAPI specs

matt.fellows
2021-06-02 01:20
what have you read so far and tried to do?

matt.fellows
2021-06-02 01:23
Are you referring to Pactflow?s bi-directional contracts feature, or something else?

sheyan.rizfee
2021-06-02 01:24
read this https://pactflow.io/blog/contract-testing-using-json-schemas-and-open-api-part-1/ We would have a consumer who will be a Polling service which will hit the provide.. Devs have provide me the openapi specs to create a mock service.

matt.fellows
2021-06-02 01:25
We don?t have a mock service for OpenAPI specs

matt.fellows
2021-06-02 01:25
What gave you the impression in that article that we do? Perhaps I need to update/clarify it?

matt.fellows
2021-06-02 01:26
Pactflow has some tools for this space: https://pactflow.io/blog/bi-directional-contracts/

matt.fellows
2021-06-02 01:26
but it doesn?t provide a mock using an OAS

sheyan.rizfee
2021-06-02 01:26
sure will have a look

matt.fellows
2021-06-02 01:26
It provides contract testing capability that let?s you use the OAS as a contract

tjones
2021-06-02 11:16
```let foo = { a: [{ id: 'test'}] } like(foo)``` I think this will not match if your provider returns: ```{ a: [{ id: 'test'}, {id: 'test'}] }``` whereas the eachLike version will pass.

matt.fellows
2021-06-02 11:18
it should, because the like matcher cascades to all elements, including arrays

jaspal.gill
2021-06-02 15:23
has joined #pact-js

wenqiglantz
2021-06-02 18:19
has joined #pact-js

ch.toimbetov
2021-06-02 21:46
has joined #pact-js

kyle.florence
2021-06-03 04:57
@kyle.florence has left the channel

xyz1kind
2021-06-03 05:03
has joined #pact-js

aftab.shamim2020
2021-06-03 06:02
has joined #pact-js

slu.mendozaharold
2021-06-03 10:33
has joined #pact-js

todd.lemmonds
2021-06-03 18:38
Hello Everyone - I'm having a couple issues getting everything setup that hopefully someone has some ideas on.

todd.lemmonds
2021-06-03 18:40
1. in the example-consumer project, I keep getting the following error

todd.lemmonds
2021-06-03 18:40
? example-consumer git:(master) ? make test ========== STAGE: test (pact) ========== npm run test:pact > consumer@0.1.0 test:pact /Users/tlemmonds/Workspace/example-consumer > cross-env CI=true react-scripts test --testTimeout 30000 pact.spec.js FAIL src/api.pact.spec.js ? Test suite failed to run TypeError: Cannot read property 'endsWith' of undefined 10 | url = process.env.REACT_APP_API_BASE_URL; 11 | } > 12 | if (url.endsWith("/")) { | ^ 13 | url = url.substr(0, url.length - 1) 14 | } 15 | this.url = url at new API (src/api.js:12:13) at Object.<anonymous> (src/api.js:48:16) at Object.<anonymous> (src/api.pact.spec.js:2:1) Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.806s, estimated 3s Ran all test suites matching /pact.spec.js/i. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! consumer@0.1.0 test:pact: `cross-env CI=true react-scripts test --testTimeout 30000 pact.spec.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the consumer@0.1.0 test:pact script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/tlemmonds/.npm/_logs/2021-06-03T18_39_49_610Z-debug.log make: *** [test] Error 1

todd.lemmonds
2021-06-03 18:41
Once I comment out lines 12 to 15, everything works

todd.lemmonds
2021-06-03 18:42
~2. Second issue is when I run the npm start command to startup the api, they api just shows the sad panda~

todd.lemmonds
2021-06-03 18:42
we figured this on out

tjones
2021-06-04 00:02
Glad you've solved it! I'm curious where the example came from? I don't think we have a react example, and it would be good to have one

sergio.artero
2021-06-04 10:07
has joined #pact-js

v-gabriel.dantas
2021-06-04 15:26
has joined #pact-js

todd.lemmonds
2021-06-04 16:24
We solved issue #2

todd.lemmonds
2021-06-04 16:24
still wondering about issue 1


leonardo.viana
2021-06-04 18:52
has joined #pact-js

tonynguyenit18
2021-06-04 22:43
Hi @todd.lemmonds For issue number 1 Seem like the code does not receive env variable configured in Makefile, try to add this on top of the file ```#!make include .env```

matt.fellows
2021-06-05 00:11
`make test`

matt.fellows
2021-06-05 00:11
It needs the environment variable, and make adds it by default. Alternatively you may export it

matt.fellows
2021-06-05 00:11
The instructions should say that, if not please raise an issue so we can clarify

todd.lemmonds
2021-06-05 20:30
This worked. Thank you @tonynguyenit18

todd.lemmonds
2021-06-05 20:31
@v-gabriel.dantas ^^

github2
2021-06-06 03:26
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.37_ published by github-actions[bot]

ashish.joshi
2021-06-07 06:09
:thank_you:

yashdev963
2021-06-07 06:51
has joined #pact-js

dimundo
2021-06-07 10:51
hi! i?ve https://github.com/pact-foundation/pact-js/tree/master/examples/messages funny thing, tests are passing for ``` .withContent({ id: like(1), surname: like("rover"), type: term({generate: "bulldog", matcher: "^(bulldog|sheepdog)$"}), })``` and ``` .withContent({ type: term({generate: "bulldog", matcher: "^(bulldog|sheepdog)$"}), })```

dimundo
2021-06-07 10:52
am i doing something wrong ? ```export function dogApiHandler(dog: any): void { if (!dog.id && !dog.name && !dog.type) { throw new Error("missing fields") }``` wrong/not existing fields doesnt fail

tjones
2021-06-07 10:53
Is your second test skipped still? (it starts off skipped in the example)

dimundo
2021-06-07 10:53
skipped, yes

tjones
2021-06-07 10:53
then it?s not being run :slightly_smiling_face:

tjones
2021-06-07 10:56
If that?s not the problem, can you share the whole test?

dimundo
2021-06-07 10:57
just cloned

dimundo
2021-06-07 10:57
uncommented 2nd test ? `npm run test:consumer` ? 2 tests are passing

tjones
2021-06-07 10:58
Yep, you?re right.

dimundo
2021-06-07 10:59
volkswagen tests ?

tjones
2021-06-07 10:59
volkswagen?

dimundo
2021-06-07 10:59
always green :slightly_smiling_face:

tjones
2021-06-07 11:00
Heh. Ok, so > am i doing something wrong ? I don?t know, but your understanding matches mine, if you are, we?re both doing it.

tjones
2021-06-07 11:00
I?m just making dinner, I?ll take a look after


tjones
2021-06-07 11:06
oh wait

tjones
2021-06-07 11:06
the consumer code is wrong

tjones
2021-06-07 11:06
``` if (!dog.id || !dog.name || !dog.type) {``` ^ Should be this

tjones
2021-06-07 11:08
Good find! Fixed in master.

dimundo
2021-06-07 11:11
super, it is

tjones
2021-06-07 11:13
Oh man, this is amazing :joy:


dimundo
2021-06-07 11:16
anyone connected with both ws and scala here mayebe? #pact-scala-itv is quite silent :disappointed:


dimundo
2021-06-07 11:17
websockets

tjones
2021-06-07 11:17
I know that the scala pact implementation is a fair bit behind the rest of them

dimundo
2021-06-07 11:17
:disappointed:

tjones
2021-06-07 11:18
Last time I did scala, we used pact-jvm in groovy to trigger the scala consumers

tjones
2021-06-07 11:18
or maybe that was the provider (it was a while ago, sorry)

tjones
2021-06-07 11:18
Try asking in #general or #pact-jvm

dimundo
2021-06-07 11:20
will try in jvm, hoping noone will kick me because of spam :slightly_smiling_face:

dimundo
2021-06-07 11:20
thank you again :slightly_smiling_face:

tjones
2021-06-07 11:21
I don?t think that?ll happen if you?re asking questions about pact. And, you?re welcome!

tjones
2021-06-07 11:21
(we haven?t really had trouble with spammers, so I think we don?t have any automated moderating tools)


dimundo
2021-06-07 11:52
will talk to our scala guys ( not sure if they will be happy about groovied java :smile: )

i.pinzari
2021-06-07 17:27
has joined #pact-js

pedroefajardo_pactio
2021-06-07 17:55
ok, so,sI finally had time to finish one GraphQL consumer test and it is being published to a Dockerized version of the Broker, everything running on local as of now. Now I am ready to run the provider side of the tests. I understand better now what you meant above by ?framework-free? approach. Add a test-only state change endpoint to the provider code, specify what the end point is in the consumer side Run the provider Run the verifier Cool. The other question i have is regarding provider state. If I set the provider state, for example to return `query { user { name age } }` this is what the provider will return when the interaction in the Pact is executed. How does this test against what the provider will actually return? Say the provider changed the return to: `query { user { lastName age } }` since I am ?injecting? the provider state and this provider state is what the provider verifier would see and return wouldn?t the tests pass always?

caiquedpfc
2021-06-07 18:57
Hello everyone, I'm having some problems generating my contract test in javascript, I put the problem I'm facing on stackoverflow, in case anyone knows how to solve the link to my question on stackoverflow is below. In short, I'm getting Missing requests error and error Cross origin http://localhost forbidden when I run npm run test:consumer. https://stackoverflow.com/questions/67876713/pact-io-getting-missing-requests-error-and-error-cross-origin-http-localhost

gurkiratguliani
2021-06-07 19:36
has joined #pact-js

matt.fellows
2021-06-07 22:06
Is this just a standard jest test or are you actually running in a browser?

caiquedpfc
2021-06-08 00:24
Hi Matt, how are you? I hope you are well :smile: this just a standard jest test

matt.fellows
2021-06-08 00:54
hmm

matt.fellows
2021-06-08 00:55
cors error seems non pact related then

matt.fellows
2021-06-08 00:55
that being said, there is a ?cors? setting you could try adding to see if it helps (i.e. it would allow the `OPTIONS` request)

matt.fellows
2021-06-08 01:39
Can you please show the code for this? ```import { request } from './requests';```

matt.fellows
2021-06-08 01:39
I assume it?s an axios import

matt.fellows
2021-06-08 01:40
```axios.defaults.adapter = require('axios/lib/adapters/http');``` happens after importing your `viewApi` code, so the default adapter may not actually have any impact on the imported axios client

matt.fellows
2021-06-08 01:44
I?ve posted an answer, but I think just adding `cors: true` will fix it in your case

billal.patel
2021-06-08 10:55
Hi there, I am having some trouble which I haven?t seen before. Any ideas:

krishna.ramnk
2021-06-08 13:24
has joined #pact-js

sagar.kharab
2021-06-09 00:32
has joined #pact-js

sagar.kharab
2021-06-09 00:38
Hi @matt.fellows: I think I am having same issue so just to confirm my consumer let say called A and I am setting up pact using ```pact_oauth = Consumer('Consumer').has_pact_with(Provider('Provider'), host='my.real.deployed.host.name' version='3.0.0', port=443, use_mocking_server=True)``` In this case if likely to happen that the request will hit the real server and not the mock setup for this e.g. ```exp_response = { "access_token": "token", "expires_in": 120, "token_type": "Bearer" } parameter = {} (pact. given('Many people exists in database') .upon_receiving('a request for token') .with_request('POST', '/oauth/token', body=parameter, headers={'content-type': 'application/json'}) .will_respond_with(200, body=exp_response))``` Any guidance will be great, Please let me know if there are any queries.

matt.fellows
2021-06-09 00:40
you need your consumer test to communicate to the mock server, not the real one

matt.fellows
2021-06-09 00:41
that means you must have control over the API client that makes the call, and configure it during the test phase to point at the pact mock server, not the real one

sagar.kharab
2021-06-09 00:48
I understand but the test uses a dependency, thst makes an external call and that external call is configured weirdly that it can't be overridden straight forward so just wondering that if my pact declaration has the host name as same host name, it's not going to hit mock but hit actual url?

matt.fellows
2021-06-09 00:49
This looks like a consumer test. You can?t configured the host to be your server, because your server is not Pact, so it cannot receive the messages

matt.fellows
2021-06-09 00:49
Is this Python code?

matt.fellows
2021-06-09 00:50
perhaps worth asking in there if there is a way to intercept the request during test and redirect to Pact instead

sagar.kharab
2021-06-09 00:51
yea it is python code. I just searched for actual url and found this post closest. I will head over there

abubics
2021-06-09 02:43
"Checksum rejected" is probably the key takeaway there. Maybe check that the `.tar.gz` file is a valid archive? Do you always get the same error?

david.vancouvering
2021-06-09 03:36
has joined #pact-js

david.vancouvering
2021-06-09 03:41
Hey, all! Really great to see a Slack channel. I am running a pact-js consumer test, but I keep getting an error saying connection refused when my test tries to connect to the mock server. And then the Pact verifier fails saying the expected method was never called. I have tried both V2 and V3 with same result. My Google research told me to try turning on debug logs and to run the mock service from the command-line. Did those, nothing in the logs, and the service runs fine from the command-line. I stopped the test in the debugger when my test runs, and checked to see if there was a service listening on the configured port. There was not. Here is my Pact configuration: ``` const provider = new PactV3({ consumer: "viewitem_nodestar", provider: "viexpio", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });``` Here is my test: ``` before(() => { provider .given(`item id ${itemId} exists`) .uponReceiving("a request for the VLS module") .withRequest({ method: "GET", path: `/experience/listing_details/v2/module_provider/${itemId}`, headers: {Accept: "text/event-stream"} }) .willRespondWith({ status: 200, headers: {"Content-Type": "text/event-stream"}, body: EXPECTED_BODY }); }); it('It does nothing yet', async (done) => { try { await provider.executeTest(async () => { const arg = {req: baseRequest, res: baseResponse}; expsvcio.responseHandler(arg, {}); try { await baseResponse.on('finish', function (response) { console.log(response); done(); }); } catch (e) { console.log(e); } }); } catch (e) { console.log(e); } });```

david.vancouvering
2021-06-09 03:42
Here's the error I get: ```Error: Test failed for the following reasons: Test code failed with an error: Mock server failed with the following mismatches: 0) The following request was expected but not received: Method: GET Path: /experience/listing_details/v2/module_provider/100750056032 Headers: Accept: text/event-stream RuntimeError: Re-thrown: Host: http://localhost:8081, error: connect ECONNREFUSED 127.0.0.1:8081```

uglyog
2021-06-09 03:43
Run with LOG_LEVEL=debug and see what the logs are

matt.fellows
2021-06-09 03:43
I don't see where you actually start the mock server? I.e. setup)

david.vancouvering
2021-06-09 03:43
Yea I did that, and the log is empty :disappointed:

david.vancouvering
2021-06-09 03:44
``` const provider = new PactV3({ consumer: "viewitem_nodestar", provider: "viexpio", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });```

matt.fellows
2021-06-09 03:44
Also the code in the before block is a promise, you should return it or await ir

matt.fellows
2021-06-09 03:44
That doesn't start it

david.vancouvering
2021-06-09 03:44
OK. I am new to nodejs and promises are breaking me

david.vancouvering
2021-06-09 03:44
Oh

david.vancouvering
2021-06-09 03:44
one sec

matt.fellows
2021-06-09 03:44
`setup()`

david.vancouvering
2021-06-09 03:44
I'm using V3

matt.fellows
2021-06-09 03:44
Ah

david.vancouvering
2021-06-09 03:44
There is no setup as far as I can see

david.vancouvering
2021-06-09 03:45
I upgraded to V3 to see if the problem would get resolved

matt.fellows
2021-06-09 03:45
My apologies I didn't notice that

david.vancouvering
2021-06-09 03:45
Let me try returning in the before

david.vancouvering
2021-06-09 03:45
Same errors

david.vancouvering
2021-06-09 03:46
If it's helpful, no pact file is being written to my pacts directory either, although the directory does get created

uglyog
2021-06-09 03:46
Regardless, `provider.executeTest` should print something out if the `LOG_LEVEL` environment variable is set to something

david.vancouvering
2021-06-09 03:46
I have it set to debug :disappointed:

david.vancouvering
2021-06-09 03:47
``` const provider = new PactV3({ consumer: "viewitem_nodestar", provider: "viexpio", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });```

david.vancouvering
2021-06-09 03:47
Oh LOG_LEVEL env variable I was unaware of that

david.vancouvering
2021-06-09 03:47
Let me set that

matt.fellows
2021-06-09 03:47
so which part of your code actually sends the request to `localhost:8081/experience?`

uglyog
2021-06-09 03:48
@matt.fellows we need to fix that log config

matt.fellows
2021-06-09 03:48
yeah

david.vancouvering
2021-06-09 03:48
```[2021-06-09T03:47:49Z DEBUG pact_mock_server::mock_server] Started mock server on 0.0.0.0:8081 [2021-06-09T03:47:49Z DEBUG pact_mock_server::server_manager] Shutting down mock server with ID 26475568fac948778d125eb1b1932167 - MockServerMetrics { requests: 0 } [2021-06-09T03:47:49Z DEBUG pact_mock_server::mock_server] Mock server 26475568fac948778d125eb1b1932167 shutdown - MockServerMetrics { requests: 0 } Error: Test failed for the following reasons:```

matt.fellows
2021-06-09 03:48
it?s on the TODO

david.vancouvering
2021-06-09 03:48
So it started, and then it immediately shut down ?

matt.fellows
2021-06-09 03:48
I?m not sure this does what you think it does ``` await baseResponse.on('finish', function (response) { console.log(response); done(); });```

david.vancouvering
2021-06-09 03:48
Haha tell me about it

david.vancouvering
2021-06-09 03:48
I think it both does and does not do what I think it does, because I don't understand it lol

matt.fellows
2021-06-09 03:48
that looks like you?ve combined an event handler (i.e. the `.on`) bit, and promises

david.vancouvering
2021-06-09 03:49
So I am using an internal library which is based on event emitters

matt.fellows
2021-06-09 03:50
What I think is happening, is that the `it` block fires immediately returns and then the mock service shuts down, but then your api client issues the call, but the server is shut down by then

matt.fellows
2021-06-09 03:50
`async (done)`

matt.fellows
2021-06-09 03:50
also that doesn?t look rigth :stuck_out_tongue:

david.vancouvering
2021-06-09 03:50
Haha I am so sorry you guys I have been flailing with promises and events

matt.fellows
2021-06-09 03:50
yes, both by themselves are confusing, let alone combined

david.vancouvering
2021-06-09 03:51
From what I can see looking at our code, I send the GET request, and the result is published as an event, which is processed, and the data is put into a response object. That response object itself is an event emitter which emits a 'finish' event when it gets the final result from our internal client.

matt.fellows
2021-06-09 03:51
my suggestion - comment out the event code for now. Use a standard HTTP library (e.g. axios) and get the pact test to pass.

matt.fellows
2021-06-09 03:51
that way you?re only spinning one or two plates

david.vancouvering
2021-06-09 03:51
Ah interesting

matt.fellows
2021-06-09 03:51
once it passes, get your code in there, and iterate until it works

matt.fellows
2021-06-09 03:51
too many moving parts and new ideas = :exploding_head:

david.vancouvering
2021-06-09 03:52
I am pretty sure that the service is working. I think where I'm stuck is how do I make sure I wait until the event completes before I exit the test method

david.vancouvering
2021-06-09 03:52
I was trying to use async/await but apparently that doesn't work for events

david.vancouvering
2021-06-09 03:52
I did lots of digging on how to write tests against events but could find nothing useful on the interwebs

david.vancouvering
2021-06-09 03:54
But I'll do as you suggest, and we'll see. Turning on the LOG_LEVEL let me see the service start, which gives me confidence that it's not Pact but the way I'm writing my test

david.vancouvering
2021-06-09 03:54
One question I have: I would expect, when I break in my test code, that the mock service should be running. But when I do, it is not. Do you know why that might be?

david.vancouvering
2021-06-09 03:55
"break" meaning "stop in my debugger inside my test method"

matt.fellows
2021-06-09 03:55
I suspect there are reasons for that relating to the event loop and the execution into the rust engine

matt.fellows
2021-06-09 03:55
```it('It does nothing yet', () => { provider.executeTest(() => { return new Promise((resolve, reject) => { const arg = {req: baseRequest, res: baseResponse}; expsvcio.responseHandler(arg, {}); baseResponse.on('finish', function (response) { // check response to make sure it works OK / finish the unit test resolve("it all did what I hoped it would do...") // reject("things went badly, fail the test") }); }) }); });```

matt.fellows
2021-06-09 03:56
something like that (^^ untested, but hopefully gives you an idea to go about wrapping an event emitter into a promise)

david.vancouvering
2021-06-09 03:56
Ah...

david.vancouvering
2021-06-09 03:56
So what I see you saying here is that mocha knows how to handle Promise objects and will do the right thing

matt.fellows
2021-06-09 03:56
(updated to show the failure case)

matt.fellows
2021-06-09 03:57
yes, most frameworks natively handle promises

david.vancouvering
2021-06-09 03:57
ah ok somehow I missed that when studying mocha, that makes a lot of sense though

david.vancouvering
2021-06-09 03:57
OK thanks Matt, much appreciated, let me give this a go

matt.fellows
2021-06-09 03:57
`async/await` is simply sugar for handling promises, ultimately it gets converted into `thing().then(anotherThing).then(?)`

david.vancouvering
2021-06-09 04:06
That was great, it got rid of the connection refused error and the verification errors. But what's weird is that even if I don't call my internal client code to send an HTTP request, Pact still doesn't report any errors. Shouldn't it fail saying the expected request was not sent to the mock service?

matt.fellows
2021-06-09 04:08
oh my badness, Let me move that code into an IDE and fix the promise error I gave you :stuck_out_tongue:

matt.fellows
2021-06-09 04:09
(we need to return the `provider.executeTest(?)` bit)

david.vancouvering
2021-06-09 04:09
oh I can fix that

david.vancouvering
2021-06-09 04:10
There we go

matt.fellows
2021-06-09 04:10
cool

matt.fellows
2021-06-09 04:10
error showing up?

david.vancouvering
2021-06-09 04:10
```RuntimeError: Re-thrown: Host: http://localhost:8081, error: {"error":"Unexpected-Request : Request { method: \"GET\", path: \"/experience/listing_details/v2/module_provider\", query: Some({\"shippingServiceCode\": [\"item547fca9d06:g:20UAAOSwQ9ldG5Ne\"], \"variationId\": [\"1234567\"], \"itemId\": [\"100750056032\"], \"modules\": [\"VLS\"], \"vero\": [\"false\"]}), headers: Some({\"connection\": [\"close\"], \"accept\": [\"text/event-stream\"], \"user-agent\": [\"service-instruments-ebay/4.9.5 (x64-darwin) node/14.15.4\"], \"host\": [\"localhost:8081\"], \"x-ebay-consumer-id\": [\"urn:ebay-marketplace-consumerid:31be3645-70d4-467d-a381-1d97473133f4\"], \"content-type\": [\"application/json\"], \"x-ebay-client-app-name\": [\"r1vinode\"], \"x-ebay-tf-authorization\": [\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRldmtpZCIsIng1dSI6ImludGVybmFsOi8vZGV2Y2VydCJ9.eyJyZWFsbSI6ImRldiIsImF1ZCI6WyJmaWRlbGl1cyIsInBhdHJvbnVzIl0sImluc3RhbmNlcyI6WyIxOTIuMTY4Ljg2LjIzMiJdLCJpYXQiOjE2MjMyMTE3ODMsIm5iZiI6MTYyMzIxMTc4MywiZXhwIjoxNjIzMjk4MTgzLCJpc3MiOiJ0cnVzdGZhYnJpYyIsInN1YiI6InIxdmlub2RlIn0.V8ja1GEhiBEALWTdA3jMhvBC5VyqfQq_4bihXS-zKRLbRApZLSNbLLQ3z7AEJg43MLrsOrkCX5QocENsbaIqBVWtjXdRARjsD81j2ifdk01aI8RGD5R8CwxxgSRlqJElOz5cYyMymfg8xUtrXncFbgPdJxYiHZmx9IU_hdX6AgGFe9eTMRESGU5jGDley4HkCOnoc4lWqb_qpUvntjWvX3x7HCdFfEj5RBhIX5fBKU3ImIQ8OjcQP9oUywS_wnbzY-rpf3wHO9-a9n0dSQOUUEVmM6U09S6mjDyBeYTqdjD1xOBras4szxu7mJSeBgiSTTFC6VtBYJBu_zGIGjYkZw\"]}), body: Empty, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }"}```

david.vancouvering
2021-06-09 04:11
Now we're talking.

david.vancouvering
2021-06-09 04:11
One thing that's concerning - at the bottom of the error it seems to say the MatchingRules is empty ({})

matt.fellows
2021-06-09 04:11
:ok_hand:

david.vancouvering
2021-06-09 04:11
Shouldn't that have the rules I set up prior to running the test?

david.vancouvering
2021-06-09 04:12
``` before(() => { provider .given(`item id ${itemId} exists`) .uponReceiving("a request for the VLS module") .withRequest({ method: "GET", path: `/experience/listing_details/v2/module_provider/${itemId}`, headers: {Accept: "text/event-stream"} }) .willRespondWith({ status: 200, headers: {"Content-Type": "text/event-stream"}, body: EXPECTED_BODY }); });```

matt.fellows
2021-06-09 04:12
what is in `EXPECTED_BODY` ?

david.vancouvering
2021-06-09 04:12
It's a wad of JSON

matt.fellows
2021-06-09 04:12
any pact matchers in it?

david.vancouvering
2021-06-09 04:12
Yes

david.vancouvering
2021-06-09 04:12
``` const EXPECTED_BODY = { chunks: [ { "type": "DATA", "id": like("123"), "data": { "modules": { "VLS": { "_type": "VLSViewModel", "listing": like({ "listingId": "300017681384", "version": 0, "title": { "content": "a title" } } ) } } } } ] };```

matt.fellows
2021-06-09 04:13
:thinking_face:

david.vancouvering
2021-06-09 04:13
But it looks like the server rejected the incoming request as being unexpected

matt.fellows
2021-06-09 04:13
Let?s see what happens when it passes

david.vancouvering
2021-06-09 04:13
So I am not sure how the body plays into it

david.vancouvering
2021-06-09 04:14
Oh ah I see more errors below, where Pact is saying "I didn't get this GET request, but I got this unexpected one"

david.vancouvering
2021-06-09 04:14
So I think I'm good

david.vancouvering
2021-06-09 04:15
Sweet. Once I get this working it's going to be a big win.

david.vancouvering
2021-06-09 04:15
Great tool you all have, solves a major problem!

matt.fellows
2021-06-09 04:18
:raised_hands::raised_hands::raised_hands:

david.vancouvering
2021-06-09 04:29
Which do you recommend right now in terms of overall stability and support - standard pact-js or V3? For example, I'm trying to find information on how to do a regex for the query string and all the docs and examples I can find are for the (v2) pact-js

matt.fellows
2021-06-09 06:45
All of the examples/tutorials will currently be v2 because it?s the current stable

matt.fellows
2021-06-09 06:45
as per the note in the readme, V3 is production ready in the sense that it works. But the API is likely to change, so if you can handle a bit of refactoring you could stick with the V3 version

nuno.pik
2021-06-09 06:58
has joined #pact-js

tjones
2021-06-09 08:15
Usually we see this when there?s a proxy that is blocking the download (or causing the download to respond with a login page)

billal.patel
2021-06-09 08:51
Thanks guys. It somehow resolved itself so must have been an internet or temporary permissions issue

tjones
2021-06-09 09:16
Sorry, I didn?t see this. The log level you need is `debug`, not trace. The documentation was wrong and has now been corrected.

tjones
2021-06-09 09:17
(also there was a bug with incorrectly passing `trace` down to the pact ruby service. But it doesn?t matter, because `trace` isn?t really used for anything that you?d need)

tjones
2021-06-09 10:08
(I mean, we should still fix that)

natashakdykes
2021-06-09 16:06
has joined #pact-js

torbjorn.vatn
2021-06-09 17:30
has joined #pact-js

s.goel
2021-06-10 08:57
has joined #pact-js

kondal.ramidi
2021-06-10 16:13
has joined #pact-js

dimundo
2021-06-10 18:06
hi! i?m checking ( again :smile: ) message tests examples ``` describe("receive dog event", () => { it("accepts a valid dog", () => { return messagePact .given("some state") .expectsToReceive("a request for a dog") .withContent({ id: like(1), name: like("rover"), type: term({ generate: "bulldog", matcher: "^(bulldog|sheepdog)$" }), }) .withMetadata({ "content-type": "application/json", }) .verify(synchronousBodyHandler(dogApiHandler)) }) })``` any options to verify also `metadata` in `dogApiHandler` ?

matt.fellows
2021-06-10 21:05
not in Pact JS at the moment sorry

matt.fellows
2021-06-10 21:06
oh, this is a consumer test

matt.fellows
2021-06-10 21:06
If you could please raise an issue, it should be doable I think

richard
2021-06-11 00:13
has joined #pact-js


jwcarman
2021-06-11 14:23
has joined #pact-js

hello370
2021-06-11 14:58
has joined #pact-js

david.vancouvering
2021-06-11 23:23
Hey, I am trying to write a consumer test for a server-sent event (SSE endpoint). In this case the HTTP code is 200, the Content-Type response header is `text/event-stream` and the response body is of the form ```data: {some: "json"}\n\n```

david.vancouvering
2021-06-11 23:24
My question is: how do you do matching of the body when it's not JSON but a raw string with newlines that happens to contain JSON embedded in it?

david.vancouvering
2021-06-11 23:25
I tried to put the newlines directly in the sample above but Slack keeps getting rid of them

david.vancouvering
2021-06-11 23:26
Here's the Pact file that is generated with a successful run, but notice there is no matching logic in the response, so if the provider doesn't respond exactly with the same data the provider verification test will fail :disappointed: ``` "response": { "body": "data: { \"modules\": { \"VLS\": { \"_type\": \"VLSDataModule\",\"viewListingServiceResponse\":\"anything\",\"meta\":{\"name\":\"VLS\"}}},\"meta\":{\"pageTitle\":\"VI\",\"pageTemplate\":{\"_type\":\"PageTemplate\",\"templateId\":\"VI\"}}}\n \n ", "headers": { "Content-Type": "text/event-stream", "transfer-encoding": "chunked" }, "status": 200 }```

david.vancouvering
2021-06-11 23:27
So say I want to match `anything` to any string. Do I need to make the whole thing a big regex?

david.vancouvering
2021-06-11 23:54
I used `regex` for now, lmk if there is a better approach

david.vancouvering
2021-06-12 02:28
Regex sadly only takes you so far. I want to express that the response can contain an array of one or more items. I can't use any of those cool matchers to express that. :disappointed:

matt.fellows
2021-06-12 03:15
Yeah the matchers only work for JSON (and in some cases XML) payloads

matt.fellows
2021-06-12 03:15
One option would to be to write a little adapter on either side of the tests to convert into your different format

vikrant82
2021-06-12 12:16
has joined #pact-js

thanuxxxx
2021-06-14 02:18
Hi everyone, I have a field which may contains zero or more elements (as an array) can I use `eachLike` from `Matches`?

matt.fellows
2021-06-14 03:04
No you have to write two tests. EachLike has a minimum of one element


thanuxxxx
2021-06-14 03:06
Got it. I just fond that article, and it make sense. Thank you

matt.fellows
2021-06-14 04:39
:+1:

daniel.bubenheim
2021-06-14 08:05
has joined #pact-js

joaoproenca
2021-06-14 10:15
has joined #pact-js

thanuxxxx
2021-06-14 13:54
Is this also true for a scenario where a field is always exists but the value can be an empty array or non-empty array?

matt.fellows
2021-06-14 14:09
Yep

matt.fellows
2021-06-14 14:10
If we never test one of those scenarios we can't be confident the contract is safe

leonardo.viana
2021-06-14 15:24
@matt.fellows, did the behavior of `eachLike` change with V3? I ask because if you look at the documentation for Pact JS V3, you will see that there?s a new `MatchersV3.atLeastOneLike` which seems to differ with respect to `MatchersV3.eachLike` exactly because it also validates that there?s a least 1 item in the list: https://github.com/pact-foundation/pact-js#pact-js-v3 ```eachLike: Applies the type matcher to each value in an array, ensuring they match the template. Note that this matcher does not validate the length of the array, and the items within it. atLeastOneLike: Behaves like the eachLike matcher, but also applies a minimum length validation of one on the length of the array. The optional count parameter controls the number of examples generated.```

thanuxxxx
2021-06-14 16:20
I have a response object with nested objects, how should I verify that? I mean do to do a `toHaveProperty` for each and every property in the response?

e.pittaluga.b
2021-06-14 16:34
has joined #pact-js

npatil
2021-06-14 17:28
has joined #pact-js

david.vancouvering
2021-06-14 19:57
Thanks, Matt. I'm not following the adapter approach. Oh you mean run a small passthrough server that converts the JSON payload from the mock service to an SSE payload. I'd need to do the same thing for the provider side, where I convert the SSE payload to JSON so the verifier works. Maybe enhance the Pact mock service and Pact client to support pre- and post- filter plugins. Would that be an interesting pull request for y'all?

thanuxxxx
2021-06-14 20:55
Why I am getting this error `pact-node@10.12.2: Pact Binary Error: WARN: Only the first item will be used to match the items in the array at $['body']['tipSuggestions'].` 1. When I delete the pact folder, then run the tests, I don't see the error (first time) I am using Pact with Jest

matt.fellows
2021-06-14 21:49
Can you please share the code?

matt.fellows
2021-06-14 21:49
I'm guessing you're passing an array of items to EachLike with different values

matt.fellows
2021-06-15 00:20
`eachLike` should also have had a minimum of 1


matt.fellows
2021-06-15 00:20
`atLeastOneLike` makes it clearer what it does, because there are new matchers that limit the max etc.

dimundo
2021-06-15 06:11
hi! if app is consumer of n pacts, it means, that in ci/cd one must run `can-i-deploy` for each consumer ? any wildcards/lists/arrays/extra params/name it available ?

dimundo
2021-06-15 06:15
lets say there is frontend part, which is ? api consumer ? message consumer so, 2 pacts in total, to check

dimundo
2021-06-15 06:16
this checks only API part `"can:i:deploy:consumer": "pact-broker can-i-deploy --pacticipant 'APIConsumerJSApp' --pacticipant 'APIProviderScalaApp' --latest ....",`

dimundo
2021-06-15 06:17
so, either 2 checks or ? ?

matt.fellows
2021-06-15 06:18
Do you deploy both consumers at the same time?

matt.fellows
2021-06-15 06:19
Usually that check is in the CD pipeline for the app that's being deployed

dimundo
2021-06-15 06:19
its a single app

dimundo
2021-06-15 06:19
so - yes

matt.fellows
2021-06-15 06:19
That's unusual

matt.fellows
2021-06-15 06:19
Why deploy them together?

matt.fellows
2021-06-15 06:19
But it doesn't matter

dimundo
2021-06-15 06:20
why ? frontend, which utilizes regular APIs + communication over websockets

matt.fellows
2021-06-15 06:20
In your case I'd need to check the args, that might not automatically pick up its dependencies (i.e. providers)

matt.fellows
2021-06-15 06:21
Just double check. You might need to actually call the command twice

abubics
2021-06-15 06:22
historically, the message consumer can't be bundled with the http consumer, so even though it's conceptually one consumer, it's split into 2 contracts . . . right?

dimundo
2021-06-15 06:22
2 contracts - right, 1 app - right

dimundo
2021-06-15 06:23
but if app gets APIs from n providers ? we are in microservices era

abubics
2021-06-15 06:25
I'm just clarifying for what seems like some confusion on Matt's end ("That's unusual" & "Why deploy them together?")

dimundo
2021-06-15 06:26
looks like for n pacts/contracts, one must do n checks for `"can:i:deploy:consumer"` with each pact pair

abubics
2021-06-15 06:28
you should only need to do multiple if the pacticipant has multiple handles (2 consumer identifiers in this case)

abubics
2021-06-15 06:29
in the usual case, a particular codebase only has one identifier, so it only needs to specify itself once


dimundo
2021-06-15 06:30
`consumers: List[String]` list here sounds logical - like i?m provider of list consumers - lets check them all

dimundo
2021-06-15 06:32
js consumer pacts folder

dimundo
2021-06-15 06:34
so i publish them and provider fetches them and checks both

dimundo
2021-06-15 06:37
but looks like i need to make 2 checks `"can:i:deploy:consumer:messages"` and `"can:i:deploy:consumer:api"`

dimundo
2021-06-15 06:38
yeah right, from one side it could be handy to check in one bunch, from other side - error message if something fails is more obvious in discrete checks

matt.fellows
2021-06-15 06:41
From `pact-broker help can-i-deploy` ```#### Recommended usage - allowing the Pact Broker to automatically determine the dependencies Prerequisite: if you would like the Pact Broker to calculate the dependencies for you when you want to deploy an application into a given environment, you will need to let the Broker know which version of each application is in that environment. How you do this depends on the version of the Pact Broker you are running. If you are using a Broker version where deployment versions are supported, then you would notify the Broker of the deployment of this application version like so: $ pact-broker record-deployment --pacticipant Foo --version 173153ae0 --environment test This assumes that you have already set up an environment named "test" in the Broker. If you are using a Broker version that does not support deployment environments, then you will need to use tags to notify the broker of the deployment of this application version, like so: $ pact-broker create-version-tag --pacticipant Foo --version 173153ae0 --tag test Once you have configured your build to notify the Pact Broker of the successful deployment using either method describe above, you can use the following simple command to find out if you are safe to deploy (use either `--to` or `--to-environment` as supported): $ pact-broker can-i-deploy --pacticipant PACTICIPANT --version VERSION [--to-environment ENVIRONMENT | --to ENVIRONMENT_TAG ] --broker-base-url BROKER_BASE_URL If the `--to` or `--to-environment` options are omitted, then the query will return the compatiblity with the overall latest version of each of the other applications. Examples: Can I deploy version 173153ae0 of application Foo to the test environment? $ pact-broker can-i-deploy --pacticipant Foo --version 173153ae0 \ --to-environment test \ --broker-base-url https://my-pact-broker```

dimundo
2021-06-15 06:42
yes, i read https://docs.pact.io/pact_broker/can_i_deploy/ , but its for simple 1:1 case :slightly_smiling_face:

matt.fellows
2021-06-15 06:42
So you?ll need two calls in your case. Two consumers (because of the messages limitation) talking to _n_ providers

matt.fellows
2021-06-15 06:42
If you specificy multiple `--pacticipant` then it will not automatically detect the dependencies: ```#### Alternate usage - specifying dependencies explicitly If you are unable to use tags, or there is some other limitation that stops you from using the recommended approach, you can specify one or more of the dependencies explictly. You must also do this if you want to use the `--all TAG` option for any of the pacticipants. You can specify as many application versions as you like, and you can even specify multiple versions of the same application (repeat the `--pacticipant` name and supply a different version.) You can use explictly declared dependencies with or without the `--to ENVIRONMENT_TAG`. For example, if you declare two (or more) application versions with no `--to ENVIRONMENT_TAG`, then only the applications you specify will be taken into account when determining if it is safe to deploy.....```


dimundo
2021-06-15 06:44
oh, pardon me :disappointed:

matt.fellows
2021-06-15 06:45
BUT

matt.fellows
2021-06-15 06:45
conflicting docs is bad, I?m just readig what you sent - hold that thought :laughing:

matt.fellows
2021-06-15 06:46
phew, all good - we are consistent. This bit alludes to the bigger problem with specifying dependencies manually

matt.fellows
2021-06-15 06:46
TL;DR - just specify the application you want to deploy, and let the broker work out the rest

lucas.rolle
2021-06-15 06:48
has joined #pact-js

dimundo
2021-06-15 06:48
this is `1:many` case

dimundo
2021-06-15 06:49
still, very usefull for bunch of different api providers :+1: ( in my case )

dimundo
2021-06-15 06:51
`messages`+`api`s creates `many:many` case ( sadly, we are not living in a perfect world )

dimundo
2021-06-15 06:51
but, i?ve got the idea, thank you very much :pray:

matt.fellows
2021-06-15 06:54
Yeah, that?s a problem/limitation with the framework (that?s to be fixed in v4 of the spec, but for now we live in this world)

matt.fellows
2021-06-15 06:54
Perhaps raise a request on http://pact.canny.io?

matt.fellows
2021-06-15 06:54
(and double check if it?s already been requested)

caoilte
2021-06-15 11:36
has joined #pact-js

sreid
2021-06-15 11:46
has joined #pact-js

thanuxxxx
2021-06-15 13:37
``` tipSuggestions: eachLike( { id: like('526BKHDR76G7E'), name: like('Best Service Ever!'), percentage: like(30), }, {min: 4} ),```

thanuxxxx
2021-06-15 13:41
I only see the error when min is greater than 1

thanuxxxx
2021-06-15 13:54
I think that might be a bug because I used to have `PactfileWriteMode` is `update`, after I change to `overwrite` I don't see the error

caoilte
2021-06-15 14:43
@caoilte has left the channel

leonardo.viana
2021-06-15 15:57
I noticed that the `exampleValue` within `fromProviderState` in Pact JS V3 beta is currently defined with a data type of `string`: https://github.com/pact-foundation/pact-js/blob/e0aa360efd7995dc9c5f330fa6f450525e67b54d/src/v3/matchers.ts#L450 However, this prevents us from using non-string data types within TypeScript tests, like a number, similarly to what is being done in this JavaScript example: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/provider-state-injected/consumer/transaction-service.test.js#L45 It seems to me that the data type should be defined as `any`, not `string`, otherwise that greatly limits the data types used for replacements. Is this a bug?

danielabbitt
2021-06-15 17:12
has joined #pact-js

tom.borglum
2021-06-15 17:29
has joined #pact-js

thanuxxxx
2021-06-15 18:15
Any Idea why few of my pact tests fails occasionally `with 30000 ms timeout for Pact` & `Pact verification failed - expected interactions did not match actual.` ?

mathias.duesterhoeft
2021-06-15 19:08
Hi there, I am trying to use pact-js `10.0.0-beta.37` with typescript `4.2.4` - and `tsc --build` in my project gives a lot of those errors: ```node_modules/@pact-foundation/pact/src/messageConsumerPact.d.ts:4:25 - error TS2307: Cannot find module 'common/jsonTypes' or its corresponding type declarations. 4 import { AnyJson } from 'common/jsonTypes'; ~~~~~~~~~~~~~~~~~~ node_modules/@pact-foundation/pact/src/v3/xml/xmlElement.d.ts:1:25 - error TS2307: Cannot find module 'v3/matchers' or its corresponding type declarations. 1 import { Matcher } from 'v3/matchers';``` In `matchers.ts` the import is actually `import { AnyJson, JsonMap } from 'common/jsonTypes';` see https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/dsl/matchers.ts#L7 I am not sure why the absolute path import is not working in my project. But also pact-js seems to be mixing both relative and absolute import. Is this a good idea. Any help is highly appreciated

matt.fellows
2021-06-15 23:26
Thanks for the PR. I think we?ll just do that for consistency.

matt.fellows
2021-06-15 23:26
I can?t recall the intricacies of the TS compilation process, but makes sense to be as ?import? friendly as possible

matt.fellows
2021-06-15 23:30
cc @tjones, I recall a similar situation recently so may have more context

tjones
2021-06-16 00:06
occasional failures are usually because of some kind of promise mishandling. Check your code to make sure that you are correctly passing promises back to jest's `it` etc.

thanuxxxx
2021-06-16 00:07
Yes, there was an issue of promise handling. Thank you

leonardo.viana
2021-06-16 00:48
Just to followup on this. I changed my local pact-js V3 beta installation to use `any` instead of `string` for the `exampleValue` parameter of `fromProviderState` and that gets rid of the TypeScript failure in the consumer side and allows me to define something like: ```.withRequest({ method: 'PUT', path: ..., body: { updated_at: MatchersV3.fromProviderState('${updated_at}', 1623700550085), }, })``` However, the provider tests still fail because it still replaces my `updated_at` variable with a `string` instead of `number` (even though I return a number in `stateHandlers`) and our provider expects that field to be a number. Is there any way to tell pact-js V3 to replace a field value with a `number`, not `string`? Any help is greatly appreciated.

mathias.duesterhoeft
2021-06-16 06:44
Thanks for having a look - the build was failing in the PR - but I am a little bit lost lost there - does not look like the build error is related to my change. `Error: Cannot find module '@pact_foundation_greet/pact'`

michael.branders
2021-06-16 06:57
has joined #pact-js

tjones
2021-06-16 07:27
Yep, completely unrelated. Looks like the branch is broken, I?ll fix that (and I?ve merged your change)

tjones
2021-06-16 07:27
Thanks for the PR!

bethskurrie
2021-06-16 07:35
@tonynguyenit18 just wanted to follow up with you on this fix. Have you found that it's working the way you want it to now?

tjones
2021-06-16 07:56
We?ve just released jest-pact `0.9.1` with support for Jest 27 :tada:

jedlicka
2021-06-16 10:12
has joined #pact-js

leonardo.viana
2021-06-16 11:59
I?m still stuck on this dynamic replacement of a number. @matt.fellows, @tjones, sorry to bother you guys, but do you if it?s possible in Pact JS V3 to do the kind of number replacement I explained above?

matt.fellows
2021-06-16 12:33
:wave:

matt.fellows
2021-06-16 12:33
hmm I?m not sure sorry, it?s a pretty new feature

matt.fellows
2021-06-16 12:36
Ah yes. Sorry for some reason slack collapsed the first half of the conversation

matt.fellows
2021-06-16 12:36
I was just checking that example, and it does what you want

matt.fellows
2021-06-16 12:37
Could you please raise an issue? Easily fixed

matt.fellows
2021-06-16 12:37
for now, you?ll need to TS brute force your way through with a cast

matt.fellows
2021-06-16 12:37
We can do better than an any (because it doesn?t accept an any), but it?s also not limited to strings

leonardo.viana
2021-06-16 12:51
Thanks @matt.fellows. I raised the following issue for this: https://github.com/pact-foundation/pact-js/issues/696

jpasse
2021-06-16 13:45
has joined #pact-js

tonynguyenit18
2021-06-16 14:43
@bethskurrie I?m waiting for the release. Have you release it if yes what version it?s?

jan.malkiewicz
2021-06-16 14:48
has joined #pact-js

akennedy
2021-06-16 21:40
Hey all, I'm having an issue whereby the request path used during the call via the consumer needs to be different than the request path used when calling the provider directly. Specifically, an id needs to be appended when calling the provider directly, but the consumer automatically appends that id, so my consumer contract just has a simple path, e.g. `/forms` Since the consumer contract uses the unappended path, is there any way to some how add this required appended id at a later point? Any other ideas as to how to make this work?

matt.fellows
2021-06-16 22:10
If the consumer automatically appends it, wouldn?t it be in the contract then?

matt.fellows
2021-06-16 22:10
Is the issue you don?t have control over it on the consumer test?

akennedy
2021-06-16 22:49
The resulting contract shows the unappended path `/forms` . When I go to run provider-verify, I get a 500 error response because it's using the path `/forms` with the error that it's missing the appended id. There's something that happens outside of my test in the consumer service that appends the id before the request hits the provider API.

akennedy
2021-06-16 22:50
If the consumer contract could save the appended id I should be set, I just can't set up the interaction beforehand to include the id, it must remain `/forms`

bethskurrie
2021-06-16 22:52
@tonynguyenit18 are you using the OSS broker? It's out in Pactflow SAAS.

tonynguyenit18
2021-06-16 23:22
@bethskurrie Yep I?m using OSS Broker. Do you have plan to release this fix for let OSS Broker users?

matt.fellows
2021-06-16 23:54
I?m just confused as to how your client sends the parameters but you can?t add that to your test?

matt.fellows
2021-06-16 23:54
> here?s something that happens outside of my test in the consumer service like a proxy or something?

akennedy
2021-06-17 00:06
It does it in the function I'm using to make the call: ```async getForms(companyId) { const forms = await this.get(`/forms?company_id=${companyId}`); }``` This is in the consumer repo outside of my test. I then call getForms with a companyId

matt.fellows
2021-06-17 00:19
What does your test do? It should be calling `getForms`

matt.fellows
2021-06-17 00:20
That's the thing that makes the API call so should be the target of your pact unit test

matt.fellows
2021-06-17 00:20
If you're not testing that function you're not testing the real code and your test will get out of sync

akennedy
2021-06-17 00:28
I think the issue this whole time was with my interactions file and not with my test itself. Looking into adding `query:` after `path:`and I think that might do the trick :sweat_smile:. Thanks for the help!

matt.fellows
2021-06-17 00:44
excellent!

matt.fellows
2021-06-17 00:44
glad you worked it out :stuck_out_tongue:

jeen.broekstra
2021-06-17 06:13
has joined #pact-js

minijb225
2021-06-17 06:44
has joined #pact-js

dimundo
2021-06-17 08:05
hi! I have such pact config ``` const messagePact = new MessageConsumerPact({ consumer: "MessageConsumerJSApp", dir: path.resolve(process.cwd(), "pacts"), pactfileWriteMode: "update", provider: "MessageProviderScalaApp", logLevel: "info", })```

dimundo
2021-06-17 08:07
> export declare type PactfileWriteMode = ?overwrite? | ?update? | ?merge?; setting to overwrite/merge makes `Error: thrown: "Could not find command \"merge\".`

dimundo
2021-06-17 08:07
`Error: thrown: "Could not find command \"overwrite\".`

matt.fellows
2021-06-17 08:08
I think I know what it is

matt.fellows
2021-06-17 08:08
for message pact though, just drop it - it doesn?t support that flag

matt.fellows
2021-06-17 08:08
(it always merges)


matt.fellows
2021-06-17 08:08
it should be a different type, and that option shouldn?t be present, basically

dimundo
2021-06-17 08:09
then other question comes - if i rename `expectsToReceive` param, then both interactions are in the pact :disappointed: so one must delete pact before running tests

matt.fellows
2021-06-17 08:12
yes, you must clear out the pacts directory beforehand

matt.fellows
2021-06-17 08:12
If that?s not document, then we must have removed it - apologies if that?s the case

matt.fellows
2021-06-17 08:12
I have to run for dinner etc., but will check in later

dimundo
2021-06-17 08:20
so `"test:consumer": "jest consumer/*-contract.spec.js --env=node",` better to be like `"test:consumer": "rimraf pacts && jest consumer/*-contract.spec.js --env=node",`

matt.fellows
2021-06-17 08:22
Yeah


dimundo
2021-06-17 08:25
but one must remember to run clean, imho inline is better/safer

dimundo
2021-06-17 08:26
sad story about extra dependency :disappointed: could be extra strategy added to pact file (re)creation ?

leonardo.viana
2021-06-17 16:26
I?m having this exact same problem, so I?m glad I found this thread. @matt.fellows, @tjones, is there a GitHub issue that we can use to track the progress on this?


leonardo.viana
2021-06-18 00:03
But, is there an item that tracks this ?state handlers need to wait for promises to resolve? issue specifically?

matt.fellows
2021-06-18 01:00
no

matt.fellows
2021-06-18 01:00
the API itself will be redesigned, so a number of considerations will be there (including ideally support for backwards compatibility with the current stable interface, which supports promises)

matt.fellows
2021-06-18 01:01
I?d like to evolve this discussion into one about the API design: https://github.com/pact-foundation/pact-js/discussions/681

matt.fellows
2021-06-18 05:47
> but one must remember to run clean, imho inline is better/safer Agreed! That was my point above - it?s there, but it should be inline

matt.fellows
2021-06-18 05:48
> sad story about extra dependency :disappointed: could be extra strategy added to pact file (re)creation ? I think we could find a way to support it. Pact message has some challenges that HTTP doesn?t, but if you could please raise a feature request we?ll see what we can do

tomknee1
2021-06-18 08:15
has joined #pact-js

rockin291
2021-06-19 05:18
has joined #pact-js

zainamro1
2021-06-20 17:17
has joined #pact-js

nferrazzano
2021-06-21 05:23
has joined #pact-js

lewis.prescott079
2021-06-21 12:55
has joined #pact-js

github2
2021-06-21 13:10
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.38_ published by github-actions[bot]

tjones
2021-06-21 14:27
@dimundo: For jest-pact, it?s a bit hard, because the test runner doesn?t give the tests much context about how they?re running (they?re quite well isolated). I?d like to export a clean step that you can include in your jest setup, since it allows modules to be used. It would delete your pacts first. However, I?m a bit concerned that it might cause surprise behaviour if people are running only part of their test suite, and I also want to be careful not to delete the wrong thing (which can also be hard in some setups). Suggestions welcome!

github2
2021-06-21 14:35
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v9.16.0_ published by github-actions[bot]


dimundo
2021-06-21 14:40
looks like `clean` step is the way - deterministic result for brave guys ( and gals ) :slightly_smiling_face:

mathias.duesterhoeft
2021-06-21 16:36
Is something broken here - the release artifacts are still missing?

vlad
2021-06-21 18:23
has joined #pact-js

christopher.doherty
2021-06-21 19:01
has joined #pact-js

liorra
2021-06-22 04:17
has joined #pact-js

matt.fellows
2021-06-22 04:22
It looks like there was an issue with the rust build. Some dependency in the chain no longer works with Rust :laughing: . I?ll look at this tomorrow

dimundo
2021-06-22 09:08
Hi anyone seen `command not found: pact-broker` could be due using `yarn` , not `npm` ( and , maybe `pnp` )

stanojevic.boban
2021-06-22 10:20
has joined #pact-js

matt.fellows
2021-06-22 10:34
What are doing when that shows up?

dimundo
2021-06-22 10:49
trying to publish to broker

matt.fellows
2021-06-22 12:41
from the command line or in a JS file?

matt.fellows
2021-06-22 12:41
If you could share the command/code example hat?d be great

matt.fellows
2021-06-22 12:42
I know if you run `npx pact-broker` outside of the directly containing `node_modules` it isn?t supported

miguel.carneiro
2021-06-22 12:51
has joined #pact-js

tjones
2021-06-22 14:16
```npx --package @pact-foundation/pact pact-broker``` :slightly_smiling_face:

tjones
2021-06-22 14:19
@dimundo This usually happens if the binaries weren?t installed. Sometimes that will happen when `npm install` fails and you don?t notice, or if you?re running `npm install --ignore-scripts` (or whatever the yarn equivalents are). Unfortunately, the post-install script isn?t run if the install worked. Try deleting `node_modules/@pact-foundation/pact-node` (or `node_modules/@pact-foundation/pact-core` if you?re on the beta v10) and then rerun `npm install` (or whatever the yarn equivalent is)

tjones
2021-06-22 14:20
If that doesn?t fix your problem, how are you trying to invoke `pact-broker`?

tjones
2021-06-22 14:25
?..we should probably put that in the documentation

dimundo
2021-06-22 14:28
there are no node_modules for yarn

tjones
2021-06-22 14:29
Really? There was last time I used it. I thought it was npm compatible. Where does it download packages?

dimundo
2021-06-22 14:30
some other folder, but probably it is project-related

dimundo
2021-06-22 14:31
workarounded with

dimundo
2021-06-22 14:32
const {Publisher} = require("@pact-foundation/pact") ... new Publisher(opts) .publishPacts()

tjones
2021-06-22 14:34
Ok. I suspect that the postinstall script didn?t run. Google tells me that yarn will respect this, but if you?re using yarn 2, it has a mode called PnP (plug-n-play) that doesn?t have a node_modules location. I can?t easily see what folder you?ll need to clear to get yarn to reinstall the package

dimundo
2021-06-22 14:34
yep, pnp

dimundo
2021-06-22 14:34
`plug-and-pray`

dimundo
2021-06-22 14:35
but it worked from code, which is even better at some point

tjones
2021-06-22 14:35
The page about why they changed it is not super helpful

tjones
2021-06-22 14:39
Sooo it looks like pnp keeps the packages as zips and unpacks them at runtime. But the page about the lifecycle scripts that they support suggests that it will unpack the zip if there is a lifecycle script:

tjones
2021-06-22 14:40
> postinstall is called after a package got successfully installed on the disk. It is guaranteed. and > Postinstall scripts have very real consequences for your users. In most cases Yarn will keep the installed packages in its cache under their archive form, and will instruct Node to load the files directly from there. This leads to much smaller installs, and eventually to Zero-Installs. > Unfortunately postinstall scripts break this model because they signal Yarn that those packages may need to mutate their own directory, forcing them to be extracted into physical locations on the disk and leading to heavier, slower, and less stable installs.

tjones
2021-06-22 14:41
(I find the yarn documentation to mostly be written in terms of complaints about npm, which has always turned me off the project. Yes, this is me complaining about complaints :joy:)

tjones
2021-06-22 14:41
There are also a number of packages listed as incompatible with pnp: https://yarnpkg.com/features/pnp#incompatible

tjones
2021-06-22 14:42
It?s possible that pact should also be on that list? I don?t know what it is about those projects that make them incompatible

tjones
2021-06-22 14:43
Flicking through some of those linked issues, those all look like things we don?t do, though. Hmmm

tjones
2021-06-22 14:43
haha!

tjones
2021-06-22 14:44
Do you get errors on a `yarn install` on a fresh checkout? Do you get the logging output from the download?

tjones
2021-06-22 14:44
We really should just package the download with the dependencies in it

tjones
2021-06-22 14:47
Yarn?s pnp says that it does this: > When using PnP, packages are stored and accessed directly inside the Zip archives from the cache. The PnP runtime (.pnp.cjs) automatically patches Node?s fs module to add support for accessing files inside Zip archives. This way, you don?t have to do anything special: I wonder if that?s a problem if we?re `spawn`ing rather than using `require` or `fs`

tjones
2021-06-22 14:48
Looks like you can turn it off and use `node_modules` - I?d be curious if that solves your issue

tjones
2021-06-22 14:49
they have a list of packages that had to update in order to support this, a list of packages that don?t work at all with pnp, and then they go on to warn you that using node_modules might not work :confused: https://github.com/yarnpkg/berry/tree/master/packages/plugin-node-modules Powerful and innovative indeed :joy:

tjones
2021-06-22 14:50
Also try running the verifier with `logLevel: 'DEBUG'` - it should tell you what command it is trying to run

dimundo
2021-06-22 14:50
>Looks like you can turn it off and use node_modules not sure if our js guys will allow such changes

tjones
2021-06-22 14:54
just trying to build one of my projects with yarn 2, but it?s not in homebrew

tjones
2021-06-22 14:55
oh, I see. You have to explicitly enable it. Is it still experimental?

dimundo
2021-06-22 14:56
nope, moved from demo to poc stage

dimundo
2021-06-22 14:57
so far consumer is working, next step - scala

dimundo
2021-06-22 14:57
and then fine-tuning

tjones
2021-06-22 14:57
Sorry, I meant, is yarn 2 still experimental?

dimundo
2021-06-22 14:58
ah, yes , for some year at least iirc

tjones
2021-06-22 14:59
Ok, I?m unable to run my pact tests with yarn 2 (for a different reason).

tjones
2021-06-22 15:00
My feeling is that yarn is broken rather than pact is broken, but I?m happy to be persuaded otherwise

tjones
2021-06-22 15:01
``` pino tried to access pino-pretty, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound. Required package: pino-pretty (via "pino-pretty") Required by: pino@npm:6.11.3 (via /Users/work/office/temp/remember/.yarn/cache/pino-npm-6.11.3-63b6174ef5-c6fa52d31b.zip/node_modules/pino/lib/)``` ^ This is the logging library that pact uses

dimundo
2021-06-22 15:01
yeah ,also this

tjones
2021-06-22 15:02
That?s the latest version.

tjones
2021-06-22 15:03
My feeling is that yarn?s approach sounds nice in theory, but it fixes problems that I?ve never run into and causes problems that we are now running into.

tjones
2021-06-22 15:04
Let us know if there?s anything we can do to help

tjones
2021-06-22 15:04
I think this is a bug with yarn

tjones
2021-06-22 15:04
from the position they take in the docs, yarn will think it?s a bug with pino

tjones
2021-06-22 15:05
I want pact not to care how you install it

tjones
2021-06-22 15:05
so if there?s something we can do differently to get you going with yarn 2, I?m keen to do it

tjones
2021-06-22 15:08
hmmm. Even though I can?t run the tests, the binary is there: ``` ls .yarn/unplugged/\@pact-foundation-pact-node-npm-10.12.2-cc2bb34b6a/node_modules/\@pact-foundation/pact-node/standalone/darwin-1.88.49/pact/bin/ pact* pact-broker* pact-message* pact-mock-service* pact-provider-verifier* pact-stub-service*```

tjones
2021-06-22 15:09
(see if you have a folder like that)

tjones
2021-06-22 15:13
I just checked our source - we download and check for the binaries relative to the path of the pact-node folder, so we shouldn?t get errors like you?re getting even with pnp. However, I didn?t see the logs from the postinstall script, so it?s possible that if the postinstall fails (eg for firewall or other issues), then yarn is suppressing them?

tjones
2021-06-22 15:14
aaand I can?t run the tests because of the `pino` issue

tjones
2021-06-22 15:16
how did you make yarn get past the `pino` issue? it?s bedtime here, but I?ll check back tomorrow

dimundo
2021-06-22 15:56
we are starting to celebrate here our ~pagan~ ancient https://en.wikipedia.org/wiki/J%C4%81%C5%86i :smile: so we are off till monday :slightly_smiling_face: but i will appear occasionally

srinagasai.krishnasan
2021-06-22 17:35
has joined #pact-js

matt.fellows
2021-06-23 02:31
Looking at this today Mathias

varnit.garg2424
2021-06-23 06:19
has joined #pact-js

tjones
2021-06-23 06:41
So, I tried with that .yarnrc patch, but unfortunately I can?t build my project because I?m using absolute imports + typescript, which yarn?s pnp mode doesn?t respect.

tjones
2021-06-23 06:45
I?m not keen to spend much more time trying to get yarn 2 to build projects that are otherwise configured correctly. If you suspect that pact is the issue, is it possible for you to share a repository where we can reproduce the problem?

tjones
2021-06-23 06:47
Also I hope you are having an excellent J??i, thanks for the interesting link!

dimundo
2021-06-23 06:59
i think pact is ok, this is just another yarn magic (as far tests are created) :)

github2
2021-06-23 07:43
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.39_ published by github-actions[bot]

matt.fellows
2021-06-23 07:58
New release out, artifacts are attaching this time :stuck_out_tongue:


matt.fellows
2021-06-23 07:58
NPM was done for the first release :man-shrugging:

matt.fellows
2021-06-23 07:58
hopefully that all went out nicely!

varun.patil
2021-06-23 12:44
has joined #pact-js

achuljyan
2021-06-23 21:17
has joined #pact-js

sagupta
2021-06-23 21:56
Hello Team, I am facing a error during provider verification step. I have tested the response from API locally in Postman and i am getting the response in `json` format. however when i run the pact provider tests and check the logs , I notice that the response from API as per logs is in `html` format and hence the tests are failing and i get errors for body verification and header verification ``` Failure/Error: expect(header_value).to match_header(name, expected_header_value) Expected header "Content-Type" to equal "application/json; charset=utf-8", but was "text/html; charset=UTF-8" # ./bin/pact:15:in `<top (required)>'``` in the contract , I have mentioned the header `Content-type: application/json; charset=utf-8` in. both request body and response body. Still API is returning in html . Has anyone faced this error and was able to fix it?

sagupta
2021-06-23 22:35
Fixed it , I was missing some hidden headers which postman was adding and when i added those too to the contract , it worked

bethskurrie
2021-06-23 23:23
@tonynguyenit18 yes, there are just a few outstanding things I need to do before I can release it. Sorry - I've had less than my normal amount of time on OSS recently.

mselvakumar
2021-06-23 23:54
has joined #pact-js

srikanth.rachakonda
2021-06-24 02:32
has joined #pact-js

github2
2021-06-24 03:54
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.40_ published by github-actions[bot]

ali.akbar
2021-06-24 06:58
has joined #pact-js

ali.akbar
2021-06-24 07:37
Hello everyone! I'm writing contract based tests with pact-js and jest but I'm seeing an error while following https://www.mariedrake.com/post/contract-testing-with-pact-js-and-jest: ```TypeError: Cannot read property 'verify' of undefined afterEach(() => provider.verify()); ^``` It's all happening bcz of `jsdom` test environment. By default Jest uses `jsdom` to mimic a real browser environment (RBE) in tests. Changing this to `node` may solve the issue here but the `setupTest.js` is using RBE supported code (something like `window.getComputedStyle = jest.fn(() => ({})`) which doesn't work in when you set test environment to `node` and shows the following error: ``` The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/en/configuration#testenvironment-string. Consider using the "jsdom" test environment. ReferenceError: window is not defined 33 | } 34 | > 35 | window.getComputedStyle = jest.fn(() => ({ | ^``` As shown above, the unit tests are written following `jsdom` here so changing the `setupTest.js` may not be possible in my case. More details written in the https://github.com/pact-foundation/pact-js#usage-with-jest of pact-js (also links to https://github.com/pact-foundation/pact-js/issues/10). Does anyone know how can we use `provider.verify()` without changing the Test Environment of jest?

tjones
2021-06-24 08:02
I don?t remember why `jsdom` doesn?t work with Pact, but I think it?s not something we can easily work around - (I?m interested to look into it, as it would solve some problems for angular users). One pattern that?s an easy workaround is to have a separate jest setup for pact, and to run your pact tests separately (eg by naming them `*.spec.pact.ts` or similar)

tjones
2021-06-24 08:03
Pact needs to be able to spin up binaries and in some cases servers, which might be the problem with jsdom

tjones
2021-06-24 08:05
Although, I?m wondering if something else is going on - looking at that example, it should be failing in the `beforeEach` not the `afterEach` if there?s a problem spinning up the mock server.

ali.akbar
2021-06-24 08:26
Yes, strange enough that the test I wrote actually passed. I get a proper and expected response from the mocked server and even the provider is valid during the execution of test (console.log-ed the pact provider object).

tjones
2021-06-24 09:08
So you?re saying it does work?

tjones
2021-06-24 09:11
I?m very confused about how the provider object could be undefined later. I suspect something else is going on.

ali.akbar
2021-06-24 09:14
yes exactly! the test run as expected and I can access provider inside the tests but whenever we try to call `provider.verify()`or `provider.finalize()` this error occurs.

tjones
2021-06-24 09:15
can you share your whole test code?

tjones
2021-06-24 09:15
where is the error coming from?

tjones
2021-06-24 09:15
(as in, is it in your tests, or in something like `jest-pact`, which also contains that line)

tjones
2021-06-24 09:15
are there other errors too?

ali.akbar
2021-06-24 09:37
I had to remove some of the confidential code here: ```const provider = new Pact({ consumer: 'consumer', provider: 'provider', port: 3999, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'INFO', }); const { somethingLike: like } = Pact; describe('*** Service', () => { describe('When a request *** is made', () => { beforeAll(async () => { provider.setup() }); it('should return the correct data', async () => { console.log(provider); const response = await getSomething('some-id'); expect(response).toBeTruthy(); }); afterEach(() => provider.verify()); afterAll(() => provider.finalize()); });``` Running this using `npm test` and it gives me the following errors in terminal: ```console.log Pact { opts: { consumer: 'consumer', cors: false, dir: '***/pacts', host: '127.0.0.1', log: '***/logs/pact.log', logLevel: 'INFO', pactfileWriteMode: 'overwrite', provider: 'provider', spec: 2, ssl: false, port: 3999 }, server: Server { _events: [Object: null prototype] { delete: [Function] }, _eventsCount: 1, _maxListeners: undefined, options: { consumer: 'consumer', cors: false, dir: '***/pacts', host: '127.0.0.1', log: '***/logs/pact.log', pactFileWriteMode: 'overwrite', port: 3999, provider: 'provider', spec: 2, ssl: false, sslcert: undefined, sslkey: undefined }, __running: false, __cliVerb: { cliVerb: 'service' }, __serviceCommand: 'standalone/darwin-1.88.49/pact/bin/pact-mock-service', __argMapping: { port: '--port', host: '--host', log: '--log', ssl: '--ssl', sslcert: '--sslcert', sslkey: '--sslkey', cors: '--cors', dir: '--pact_dir', spec: '--pact_specification_version', pactFileWriteMode: '--pact-file-write-mode', consumer: '--consumer', provider: '--provider', monkeypatch: '--monkeypatch', logLevel: '--log-level' }, [Symbol(kCapture)]: false } } at _callee2$ (src/pact-tests/***.test.jsx:82:15) FAIL src/pact-tests/***.test.jsx (7.43 s) *** Service When a request for *** is made ? should return the correct data (79 ms) ? *** Service ? When a request for *** is made ? should return the correct data TypeError: Cannot read property 'verify' of undefined 84 | expect(response).toBeTruthy(); 85 | }); > 86 | afterEach(() => provider.verify()); | ^ 87 | afterAll(() => provider.finalize()); 88 | }); 89 | at Pact.verify (node_modules/@pact-foundation/src/httpPact.ts:116:8) at Object.<anonymous> (src/pact-tests/***.test.jsx:86:30) ? *** Service ? When a request for *** is made ? should return the correct data Port 3999 is unavailable on address 127.0.0.1 at Server.<anonymous> (node_modules/@pact-foundation/src/common/net.ts:44:18)```

abubics
2021-06-24 10:47
If you're creating your own `const provider` at the top like that, I don't see how it could become undefined in a lower scope / execution context. I've had some lifecycle issues with a provider being undefined outside of `before*` / `after*` functions in jest-pact, but that sounds unrelated (opposite symptom, and different configuration).

tjones
2021-06-24 11:34
``` at Pact.verify (node_modules/@pact-foundation/src/httpPact.ts:116:8)``` ^ I think this is a key symptom. It indicates that the server hasn?t started yet

ali.akbar
2021-06-24 11:35
isn't provider.setup starting the server here?

tjones
2021-06-24 11:37
it should be, but perhaps it is failing. Can you try running with `logLevel: debug`?

tjones
2021-06-24 11:37
Also, is there any other failure output? Sometimes Jest repeats the thrown exceptions at the end of the test run, but there are other errors further up.

tjones
2021-06-24 11:38
oh, this is the problem: ``` beforeAll(async () => { provider.setup() });```

tjones
2021-06-24 11:39
`provider.setup()` is a promise, but you?re not `await`ing it

tjones
2021-06-24 11:40
As an aside, I recommend making `async` without `await` a lint error. The following eslint rule does that: https://eslint.org/docs/rules/require-await

tjones
2021-06-24 11:41
if you check the example you linked, the promise is returned: ``` beforeAll(() => // note no { provider.setup()```

tjones
2021-06-24 11:42
Also, if you upgrade to `9.16.0`. you?ll get a nicer error message than the `undefined` type error you are currently getting

ali.akbar
2021-06-24 11:43
Oh, I already use `.then()` with this. (I removed it bcz I added an interactions which I removed due to confidentiality)

tjones
2021-06-24 11:44
Yes, but you?re not returning the promise

ali.akbar
2021-06-24 11:44
Do I still have to use await if I'm using `setup().then()`?

tjones
2021-06-24 11:45
``` beforeAll( async () => { somePromise } ) // This does not wait for the promise beforeAll(() => somePromise ) // this does, because it is implicitly returning the promise beforeAll( async () => { await somePromise } ) // This does, because it is awaiting```

tjones
2021-06-24 11:46
Yes. You either need to remove the `{` and `}`, (and you can then remove `async`) or you need to add `await`

tjones
2021-06-24 11:46
`.then()` doesn?t do anything other than turn one promise into another

tjones
2021-06-24 11:49
You need to wait for the `provider.setup()` promise to complete before you can use the provider. Jest will wait on any promises that are returned from `beforeAll` before moving on. This is why all the pact example return promises (and also why the example in the blog you linked returns the promise in the `beforeAll`). `await` is just syntax that makes the function return a promise. It lets you write promises in a procedural way (personally I prefer not to use this style)

tjones
2021-06-24 11:49
There?s nothing magic happening with promises unless you use `await`

ali.akbar
2021-06-24 11:50
I'm using await now and it's still giving me the same error.

tjones
2021-06-24 11:50
can you share the code?


tjones
2021-06-24 11:54
Sorry, I mean: ``` beforeAll(async () => { provider.setup() });``` ^ This definitely won?t work ``` beforeAll(async () => { await provider.setup() });``` ^ This should work

tjones
2021-06-24 11:55
So I was interested to confirm what the code looked like after changes

ali.akbar
2021-06-24 11:55
I did the later as you said: ``` beforeAll(async () => { await provider.setup() });```

tjones
2021-06-24 11:58
Hmm, ok. The next step is to add `logLevel: "DEBUG"` and see what the log says

tjones
2021-06-24 11:58
(to `new Pact()` at the top)

ali.akbar
2021-06-24 12:12
Oh, I was using a port which was already in use but you were right, I was missing an `await` here. Didn't know it was a promise before. I can finally make a provider server. :raised_hands: Thanks a lot for such quick responses. I'll let you know if I have any questions.

abubics
2021-06-24 12:12
guess that explains the `Port 3999 is unavailable on address 127.0.0.1` :sweat_smile:

abubics
2021-06-24 12:13
:taco: for @tjones late-night help :3

leonardo.viana
2021-06-24 12:56
Hi team. When successful, our PUT requests return a status of 200 with no body, and when it fails it returns a non-200 status (e.g. 400) and a JSON body with a description of the error (this is standard practice in the industry). Since we want to make sure that the response contains both, the 200 status as well as the null body, we defined the following in the consumer test: ``` .willRespondWith({ status: 200, body: null });``` However, it turns out that if we put a body with a `null` value like that it will simply be left out of the pact contract, so the provider test never actually validates the body and we get the following results: ``` returns a response which has status code 200 (FAILED) has a matching body (OK)``` Now, I can manually add a body with a value of `null` in the contract JSON file, and if I do that things are slightly better because now the provider test knows that the body did not match: ``` returns a response which has status code 200 (FAILED) has a matching body (FAILED) 1.1) has a matching body / -> Expected empty body but received Present(140 bytes, application/json;charset=utf-8) 1.2) has status code 200 expected 200 but was 400``` Unfortunately, however, the output never displays the actual value of the body, which contains the JSON error message that?s extremely helpful in debugging. In other words, what we really want is an output that contains the actual response body, like: ``` 1.1) has a matching body / -> Expected empty body but received {"error":"validation","reason":"invalid input format","details":"invalid type specified for updated_at"}``` We are using the latest Pact JS V3 beta.40: is it possible to do what I describe above, and if not should I file an issue for this?

leonardo.viana
2021-06-24 13:08
BTW, I also tried defining a response body with an empty map `{}` but in beta.39/40 the provider test still thinks that the body matches (even though it doesn?t): ``` returns a response which has status code 200 (FAILED) has a matching body (OK)``` However, using an empty map `{}` in beta.37 seemed to indeed display the JSON body in the output, so I?m wondering why that was removed in more recent versions: ```1.1) has a matching body / -> Expected empty body but received {"error":"validation","reason":"invalid input format","details":"invalid type specified for updated_at"}``` The only thing I?m not sure about yet, is whether having an empty map `{}` will also make the provider test pass in the successful case (I haven?t been able to test a successful PUT request yet due to other blocking issues).

tjones
2021-06-24 14:36
I?m just heading to bed here, but my initial reaction is that the correct response for success with no content is 204 (no content)

tjones
2021-06-24 14:37
Also in pact-js, if you have no body, I think you just leave `body` out of the interaction

tjones
2021-06-24 14:39
PUT is defined to require a body when the response code is 200, see: https://datatracker.ietf.org/doc/html/rfc7231#section-6.3.1

tjones
2021-06-24 14:59
By the way, @ali.akbar, we also have `jest-pact`, which is a jest-specific wrapper that sets all the options and hooks for you: https://github.com/pact-foundation/jest-pact

leonardo.viana
2021-06-24 16:30
I played with this some more, and rather than using `null` or `{}`, the empty body should really be represented with `""`. If you do that almost everything works: the consumer test works and generates a pact with the body set to `""`, the provider test fails (as expected) with a body mismatch, and it even prints the actual body length in the error message: ``` returns a response which has status code 200 (FAILED) has a matching body (FAILED) 1.1) has a matching body / -> Expected empty body but received Present(140 bytes, application/json;charset=utf-8)``` The only thing missing is that the actual body content is not also printed. In failed requests like this, the body content normally contains an error message describing exactly what went wrong, so it?s very useful for debugging the problem. Would it be possible to also print the actual body content in the error message above?

ali.akbar
2021-06-24 17:28
ohhh interesting. I saw it somewhere before but I had some doubts. I'll definitely look at it.

erterpstra
2021-06-24 19:20
has joined #pact-js

tjones
2021-06-25 01:13
I'm sure that can be achieved. Is this with the beta branch or the main release?

tjones
2021-06-25 01:14
Also, note that the consumer pact should be only describing the request that you require. Does your implementation really require an empty body?

tjones
2021-06-25 01:15
> Is this with the beta branch or the main release? I ask because pact-js doesn't produce that error message, it delegates to a different pact core depending on which version you're using.

leonardo.viana
2021-06-25 01:19
This is with the latest pact-js v3 beta.40.

matt.fellows
2021-06-25 02:06
thanks for raising Leonardo

matt.fellows
2021-06-25 02:06
It feels like there are two things here: 1. Improvement to the output reporting (to understand / debug) 2. Update the consumer test

matt.fellows
2021-06-25 02:07
I?m with Tim. If your consumer code doesn?t care if there is/is-not a body for the `200` use case _it should not put an expectation in the contract at all_

matt.fellows
2021-06-25 02:07
Otherwise, if the provider decides later on to put a body there, it will break your contract despite your code not actually caring about it

matt.fellows
2021-06-25 02:08
Put another way, your consumer tests should only put in things it needs, not things it doesn?t need

matt.fellows
2021-06-25 02:09
in your case, it?s not important for there to be a body. So just omit it altogether and be indifferent to any response

abinzahid
2021-06-25 06:12
has joined #pact-js

leonardo.viana
2021-06-25 15:49
@matt.fellows, @tjones, there?s one last thing I want to be clear about here because I think it?s a regression. Up until `beta.37`, if you had a pact that expected an empty map `{}` as the body of the response, but you actually ended up getting something different, the provider test would correctly flag that saying that there was a body mismatch and print the actual response body that was received: ``` returns a response which has status code 200 (FAILED) has a matching body (FAILED) 1.1) has a matching body $ -> Expected an empty Map but received {"details":"Threats policy rules updated_at: invalid type specified \"1623765384870\"","error":"validation","reason":"invalid input format"} 1.2) has status code 200 expected 200 but was 400``` However, starting on the very next version of pact-js v3 beta, which is `beta.39` (given `beta.38` is broken), it no longer flags the body mismatch and simply thinks that the body actually matched: ``` returns a response which has status code 200 (FAILED) has a matching body (OK)``` This seems like a regression that needs to be fixed. Let me know if you?d like me to file an issue for this.

tjones
2021-06-25 16:03
Hmm. I?m not across the changes in the binary between those versions, but this reads more to me like a bug that was fixed- pact interactions definite the minimal expected response that the client needs, not (necessarily) the full response. In a consumer test, you specify the fields that your consumer relies on. The response from the provider can have other fields, but the test only checks for the existence of the fields your consumer requires. If your test specifies an empty json body, then any valid json should pass.

tjones
2021-06-25 16:05
If for some reason your client implementation requires that there be no body at all, then I recommend http 204 as linked above

david.vancouvering
2021-06-26 02:49
Hey. I'm using v3 of pact-js (is that a good idea?) Anyway, I have two tests, and in each test as part of the test itself I set up the provider interaction and then run the test. Both tests call the same endpoint with different query parameter. It looks like Pact is failing the second test because the parameter doesn't match the interaction I defined for the *other* test. Am I correct in understanding that you can't have two interactions to the same endpoint that vary in the value of the query param? If so, how do I go about testing this - the query param controls what response I get back...

uglyog
2021-06-26 03:19
You can, but the interactions need to be defined in separate tests and you must provide a different description for each (the parameter to expectsToReceive)

jchandorkar
2021-06-26 09:01
has joined #pact-js

github2
2021-06-26 13:25
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.41_ published by github-actions[bot]

leonardo.viana
2021-06-26 14:26
@matt.fellows, my stateHandlers no longer work on `beta.41`. I get the following error: ```[2021-06-26 14:19:36.408 +0000] INFO (8851 on C02CG10YMD6W): pact@10.0.0-beta.41: debug request/response logging enabled [2021-06-26 14:19:36.436 +0000] DEBUG (8851 on C02CG10YMD6W): pact@10.0.0-beta.41: incoming request body: { "action": "setup", "params": {}, "state": "is authenticated" } headers: { "content-type": "application/json", "accept": "*/*", "host": "localhost:54464", "content-length": "57" } method: "POST" path: "/_pactSetup" RUNS libs/api-client/src/lib/pnr-policy-pact.spec.ts FAIL libs/api-client/src/lib/pnr-policy-pact.spec.ts (6.521 s) for 'is authenticated' has failed - MismatchResult::Error("Invalid response: error sending request for url (http://localhost:54464/_pactSetup): operation timed out", None)``` My stateHandlers look like this: ``` stateHandlers: { 'is authenticated': () => { token = defaultToken; Promise.resolve(`Valid bearer token generated`) },``` I also tried the following variation, but the end result was the same: ``` stateHandlers: { "is authenticated": { setup: () => { token = defaultToken; return Promise.resolve(`Valid bearer token generated`) } },``` Am I missing something?

matt.fellows
2021-06-26 23:16
Hmm I'll have a look today. The examples definitely test this scenario as do tests

matt.fellows
2021-06-26 23:16
In the first example you're not returning a promise, but the second you do so it should work

leonardo.viana
2021-06-26 23:22
The first one is exactly the same code that used to work up until beta.39. Then I installed beta.40 and it stopped working. So I tried the second way but it also failed with the same error.

matt.fellows
2021-06-26 23:33
Thanks. I'll look today. We made a breaking change in this release to the handlers, as we're still evolving the API into what we'd like it to look like in stable.

matt.fellows
2021-06-26 23:34
Apologies, there will be a few more as we stabilise it (the release notes hopefully clarify this)

matt.fellows
2021-06-26 23:34
But I'll fix/get to the bottom of that bug

matt.fellows
2021-06-27 00:06
I?ve just had 5 minutes, and installed the beta 41 release into the e2e project in pact-js


matt.fellows
2021-06-27 00:07
`cd examples/v3/e2e`

matt.fellows
2021-06-27 00:08
```npm i @pact-foundation/pact@beta npm run test:provider```

matt.fellows
2021-06-27 00:08
There should be 4 pending failures, but the others should work

leonardo.viana
2021-06-27 00:42
Edit for my previous message: it used to work up until beta.40 and stopped working on beta.41. Now, I?m still stuck on this. What exactly does this error mean? ```FAIL libs/api-client/src/lib/pnr-policy-pact.spec.ts (8.557 s) for 'is authenticated' has failed - MismatchResult::Error("Invalid response: error sending request for url (http://localhost:51737/_pactSetup): operation timed out", None)```

matt.fellows
2021-06-27 01:04
That tells me the state handler is not worknig correctly. As mentioned, we changed the implementation for PR #702 to introduce a proxy layer (as per the current main / stable) to allow native JS promises

matt.fellows
2021-06-27 01:04
but obviously not working for you

matt.fellows
2021-06-27 01:04
are you able to share your code?

matt.fellows
2021-06-27 01:11
I?ll see about making the error there clearer - basically, the `/_pactSetup` route is dynamically added by Pact JS. I think Tim raised an issue about clarifying what this does and why it exists, and more importantly, how to debug it

rani.sathya
2021-06-27 04:14
has joined #pact-js

leonardo.viana
2021-06-27 17:17
Just to update on this? I found the issue. Not only did the `stateHandlers` change, but also `requestFilter` has a new signature and requires you to call next at the end. My provider tests started working again after I updated it to: ``` requestFilter: (req, _, next) => { req.headers['authorization'] = `${token}`; next(); },```

matt.fellows
2021-06-27 23:42
Ah, my apologies, I didn?t add that to the release notes - so sorry

matt.fellows
2021-06-27 23:42
I updated the documentation for it though if that?s a concilation :stuck_out_tongue:

matt.fellows
2021-06-27 23:42
(but they also now support promises!)

leonardo.viana
2021-06-27 23:44
Yup, we needed the promises support within stateHandlers and I can confirm that they now work. :wink: The last blocker for us now is just https://github.com/pact-foundation/pact-reference/issues/116, so hopefully that will get fixed soon too. :wink:

matt.fellows
2021-06-27 23:45
yep, please follow that issue and we?ll keep you updated!

david.vancouvering
2021-06-28 02:51
Ah, thank you! That was my mistake

cala.dev_pact
2021-06-28 04:07
has joined #pact-js

robert.rap
2021-06-28 06:34
has joined #pact-js

v-ratngupta
2021-06-28 07:13
has joined #pact-js

e.hallowell
2021-06-28 13:28
has joined #pact-js

david.vancouvering
2021-06-28 17:55
Hey, so I found out the problem was an error in my test. But now I have a new problem. I have two tests in two different `describe` blocks, but both using the same provider. In each test, I set up a different interaction with a different `uponReceiving`. Note I am using `@pact-foundation/pact/v3` What happens, if I run both tests, the second one fails because the mock service didn't get the interaction I set up in the first test. If I run each test separately, both pass. Here is the error: ```The following request was expected but not received: Method: GET Path: /experience/listing_details/v2/module_provider Query String: itemId=100750056032&modules=VLS&shippingServiceCode=abc&variationId=abc&vero=false Headers: Accept: text/event-stream``` Do I need to set up a different *provider* for each test? Thanks!

david.vancouvering
2021-06-28 18:25
Well, I created a new provider for each `describe` and that did the trick...

matt.fellows
2021-06-28 23:18
Thanks David - that?s how the examples do them today. @tjones this would be nice to fix in the interface. It should be doable (it just needs a way to reset itself after `executeTest` I think)

david.vancouvering
2021-06-28 23:19
Thanks, I should have looked at the examples more closely

matt.fellows
2021-06-28 23:19
all good, we?ll ideally fix this so you don?t have to

david.vancouvering
2021-06-28 23:20
:thumbsup:


matt.fellows
2021-06-28 23:37
I think that?s all that is needed

david.vancouvering
2021-06-28 23:37
Sounds great. It's not the end of the world to create a new provider...

matt.fellows
2021-06-28 23:39
anything that makes tests more readable though is welcome from my perspective

matt.fellows
2021-06-28 23:39
you can definitely still create multiple, which will allow you to run tests in parallel, if that?s your thing!

matt.fellows
2021-06-29 02:51
@david.vancouvering minor release going out shortly that will allow you to re-use the `PactV3` instance between tests

matt.fellows
2021-06-29 02:51
thanks for reporting

github2
2021-06-29 03:03
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.42_ published by github-actions[bot]

mishalalexander20
2021-06-29 07:36
has joined #pact-js

mishalalexander20
2021-06-29 07:40
Hey guys, glad to be here. I just have two queries - #1 I am an automation test engineer. I have worked with both APIs and UI. But still I am finding it hard to understand the concepts of contract testing. I have followed several tutorials. The way I understand it is - in contract testing using pact, we are testing both the request and response format using mocks at the same time so that we don't have to do end to end testing. Is this a correct understanding? #2 Does it makes sense of an automation test engineer like myself to pick up contract testing?

dimundo
2021-06-29 07:48
i?m a qa, and i introduced pact to my company, so why not

dimundo
2021-06-29 07:48
as for e2e - you still need to have some happy path e2e

dimundo
2021-06-29 07:49
as there are 100500 other points of failure

mishalalexander20
2021-06-29 07:49
so with contract testing, only happy path e2e is required?

dimundo
2021-06-29 07:49
not only with contract

dimundo
2021-06-29 07:50
there must be also unit and integration tests in place

dimundo
2021-06-29 07:50
testing pyramid , you know :wink:

mishalalexander20
2021-06-29 07:50
lol alright. so basically contract testing is more or less act as integration tests for APIs?

mishalalexander20
2021-06-29 07:51
currently we have unit and e2e tests

dimundo
2021-06-29 07:53
> more or less act as integration tests for APIs? i would say no. with pact you cover only format, but content must be covered in other places, as pact is not for full coverage of all cases

mishalalexander20
2021-06-29 07:54
okay got it. thanks Dmitry.


matt.fellows
2021-06-29 07:55
You can, just know that Pact is a white box testing tool - so you need access to the code base

matt.fellows
2021-06-29 07:56
Yes. Pact doesn?t test functional behaviour, just the contract itself. That link Dmitry shared is :mwah:

matt.fellows
2021-06-29 07:57
see also (if you have the demo pack where those slides came from) the slides on how to remove e2e tests, or our videos

mishalalexander20
2021-06-29 07:57
this makes so much sense.


lukemufc125
2021-06-29 07:57
has joined #pact-js

mishalalexander20
2021-06-29 07:58
I got it. With contract testing, you can reduce the number of tests overall including the ones that you put in on the CI/CD pipeline

mishalalexander20
2021-06-29 07:59
rather than testing individual failure cases, you just test the underlying format or contract for each of those.

mishalalexander20
2021-06-29 08:01
thanks guys Dmitry and Matt; I will work with these and come back.

tjones
2021-06-29 08:18
Yes. This is right. You also have less brittle tests, and clearer feedback about what is wrong when it goes wrong

tjones
2021-06-29 08:18
it?s easier to cover all of the API that you?re actually using (which can be hard in e2e)

tjones
2021-06-29 08:19
for me, I consider contract tests to be unit tests but across the API boundary (because the ?unit? includes the consumer and the provider)

tjones
2021-06-29 08:19
that model means I do ?more? unit tests, and ?fewer? integration tests

tjones
2021-06-29 08:21
> so with contract testing, only happy path e2e is required? We recommend testing every type of response that your consumer needs to understand. Does the consumer code have different behaviour in a 401 vs a 404? Then it?s good to cover both with contract tests. Does it do the same thing for every 4XX? Then just pick one and cover that.

tjones
2021-06-29 08:22
The link that @dimundo shared is spot on (:taco:). I would also add: I think it?s good to have functional _coverage_. As in, the contract tests don?t exist to exercise the functionality, but if they happen to do so in the course of running, that is a happy side effect.

mishalalexander20
2021-06-29 08:23
I am very much interesting in contract testing now. I am getting a better understanding now compared to before. But say, if I am starting today, can you tell me on an average how long will it take me to master contract testing? Given that I have worked with testing tools such as Jest, Supertest, mocha, chai, etc.

mishalalexander20
2021-06-29 08:23
and pretty good at JS as well

tjones
2021-06-29 08:24
You can write useful, valuable tests in a matter of a few hours. To master, I don?t know. I feel like I?m still mastering contract testing.

tjones
2021-06-29 08:24
(and testing in general)

tjones
2021-06-29 08:25
if you?ve used jest and supertest you?ll be well ahead. One of our intros starts off by migrating a supertest mock to pact

tjones
2021-06-29 08:25
let me find it for you

tjones
2021-06-29 08:25
Ah, I misremembered. It?s using `nock`: https://github.com/pact-foundation/pact-workshop-js

tjones
2021-06-29 08:26
The problem with `nock`, `supertest`, `restassured` etc is that you aren?t sharing the mock with anyone. With a mock that you can?t share with the provider you are (as @matt.fellows puts it) ?marking your own exam?.

tjones
2021-06-29 08:27
Most companies doing APIs at scale without contract tests have a postman collection that essentially does the same thing but manually.

mishalalexander20
2021-06-29 08:27
true that

tjones
2021-06-29 08:28
I have a dream to write a postman -> pact adapter (and a pact -> postman)

tjones
2021-06-29 08:28
there?s only so much time in the day

mishalalexander20
2021-06-29 08:28
that would be phenomenal! not kidding!

mishalalexander20
2021-06-29 08:28
I understand

mishalalexander20
2021-06-29 08:29
and thanks a lot for sharing Timothy. The workshop is just perfect for me to work on. Thanks again!

dimundo
2021-06-29 08:29
https://insomnia.rest/ is better postman ( as not asking for registration )

tjones
2021-06-29 08:31
I?ve heard good things, but haven?t had the chance to check it out. To be clear, I mean I?ve heard good thing about insomnia (the software). Not insomnia (the trouble sleeping). No one has anything good to say about that.

tjones
2021-06-29 08:33
@mishalalexander20: I put the postman idea on the feature suggestions - feel free to vote for it here: https://pact.canny.io/feature-requests/p/create-a-postman-collection-from-a-pact

mishalalexander20
2021-06-29 08:43
done!

prash471
2021-06-29 09:43
has joined #pact-js

martijn.hagens
2021-06-29 10:12
has joined #pact-js

miguel.carneiro
2021-06-29 10:23
@miguel.carneiro has left the channel

mikko.s.koskinen
2021-06-29 17:05
has joined #pact-js

ali.akbar
2021-06-29 18:21
Hello. I'm in a scenario where I'm hitting a specific path with a get request. I'm receiving no data while hitting the URL `http://localhost:3997/api/courses/v2/blocks/` : ``` { status: 200, data: {}, headers: undefined, config: { url: 'http://localhost:3997/api/courses/v2/blocks/', method: 'get', headers: { Accept: 'application/json, text/plain, */*' }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus], data: undefined }, request: { responseUrl: 'http://localhost:3997/api/courses/v2/blocks/' } }``` Upon `provider.verify()` I'm seeing the following error: ``` console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:122:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /api/courses/v2/blocks/``` Any troubleshooting ideas or where I might've messed up my configurations?

matt.fellows
2021-06-29 22:44
Please share your code so we can tell

matt.fellows
2021-06-29 22:44
It's possibly a promise not handled correctly, or you're not actually sending the request to the pact mock service

matt.fellows
2021-06-29 22:45
Two most common reasons

zhaoyi0113
2021-06-30 02:13
has joined #pact-js

ali.akbar
2021-06-30 06:45
```describe('When a request for *** is made', () => { let id; beforeAll(async () => { const store = await initializeTestStore({ excludeFetchSequence: true }); id = store.getState().***.id; await provider .setup() .then(() => provider.addInteraction({ uponReceiving: 'a request to fetch ***', withRequest: { method: 'GET', path: '/api/courses/v2/blocks/', headers: { Accept: 'application/json' }, }, willRespondWith: { status: 400, body: { root: 'some string', blocks: { some: 'data' }, }, }, })); }); it('should return the correct data', async () => { const authenticatedUser = getAuthenticatedUser(); const url = new URL(`http://localhost:${port}/api/courses/v2/blocks/`); const response = await getAuthenticatedHttpClient().get(url.href, {}); console.log(response); expect(response).toBeTruthy(); }); afterEach(() => provider.verify()); afterAll(() => provider.finalize()); });```

ali.akbar
2021-06-30 06:48
port is 3997. Common for both pact object and get request I'm making.

matt.fellows
2021-06-30 06:56
what does the pact.log file show?

matt.fellows
2021-06-30 06:56
also, i?d recommend not hard coding the port, this way you reduce the chances of port conflicts

ali.akbar
2021-06-30 06:59
These are from the logs (editing out some confidential info): ```I, [2021-06-30T11:50:23.036359 #600] INFO -- : Registered expected interaction GET /api/courses/v2/blocks/ D, [2021-06-30T11:50:23.036600 #600] DEBUG -- : { "description": "a request to fetch course", "request": { "method": "GET", "path": "/api/courses/v2/blocks/", "headers": { "Accept": "application/json" } }, "response": { "status": 400, "headers": { }, "body": { "root": "block-v1:edX+DemoX+Demo_Course+type@course+block@course", "blocks": { some: "data" } } }, "metadata": null } W, [2021-06-30T11:50:23.106900 #600] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api/courses/v2/blocks/ W, [2021-06-30T11:50:23.106958 #600] WARN -- : Missing requests: GET /api/courses/v2/blocks/ I, [2021-06-30T11:50:23.127032 #600] INFO -- : Cleared interactions```

ali.akbar
2021-06-30 07:00
Also, is there a better way to set ports? Would be awesome to know.

matt.fellows
2021-06-30 07:05
so that?s pretty definitive, it didn?t receive the request

matt.fellows
2021-06-30 07:05
don?t set the port, and one will be generated

matt.fellows
2021-06-30 07:05
the server and port are returned in the `setup()` call

ali.akbar
2021-06-30 07:16
Hmm, so what am I lacking currently? I'm already hitting url as shown in console: ```get http://localhost:3997/api/courses/v2/blocks/```

matt.fellows
2021-06-30 07:39
Can you please share more of the test? I can?t really diagnose without more info

ali.akbar
2021-06-30 07:41
Umm, that's literally it. I haven't written anything other than this at the start: ```const port = 3997; const provider = new Pact({ consumer: 'consumer', provider: 'provider', port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'INFO', });```

matt.fellows
2021-06-30 07:48
is something else running on port `3997`? I can see you?re getting back a `200` but telling pact to return a `400`. So that tells me it?s actually hitting another server

matt.fellows
2021-06-30 07:48
`lsof -i :3997`

matt.fellows
2021-06-30 07:48
if on a mac, that should tell you any processes running that port


ali.akbar
2021-06-30 07:49
No, I don't see anything running on 3997. (ran `lsof -i :3997`)

ali.akbar
2021-06-30 07:50
Yes, I will definitely use the dynamic port allocation once this problem solves. :thumbsup:

matt.fellows
2021-06-30 07:52
I would say do the port allocation thing now, because something is definitely listening on 3997

ali.akbar
2021-06-30 07:53
Right! I'm changing it right now.

ali.akbar
2021-06-30 08:15
I'm a bit confused about maybe a basic contract based testing question now, is this the expected behavior of the tests that I still get no data in response? ```{ status: 200, data: {}, headers: undefined, config: { url: 'http://localhost:53036/api/courses/v2/blocks/', method: 'get', headers: { Accept: 'application/json, text/plain, */*' }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus], data: undefined }, request: { responseUrl: 'http://localhost:53036/api/courses/v2/blocks/' } }``` But the good thing is, the tests are now passing on `provider.verify()` :raised_hands:

matt.fellows
2021-06-30 08:18
I?m confused about `status: 200`. You?re setting it to return `400` - what does `const response = await getAuthenticatedHttpClient().get(url.href, {});` actually do?

matt.fellows
2021-06-30 08:18
I?d also suggest setting the correct content-type header, many http clients won?t read a JSON body unless it is the correct type e.g. `application/json`

matt.fellows
2021-06-30 08:19
I have to run (dinner time here) but will keep an eye open

ali.akbar
2021-06-30 08:23
(Oh, sorry to keep you up late.) `getAuthenticatedHttpClient().get(url.href, {});` makes a get request to a URL. I think I should try axios maybe.

matt.fellows
2021-06-30 09:14
I would recommend getting a minimal viable example with axios working and then adding your client in

matt.fellows
2021-06-30 09:14
Or even starting with the examples in pact JS

matt.fellows
2021-06-30 09:14
Did you give adding the headers a go?

ali.akbar
2021-06-30 09:32
No, I still get the same empty data with 200. I guess you're right. I'll start all over or maybe use pact-jest which might be a bit better for my usage. Thank you so much for your time.

matt.fellows
2021-06-30 09:35
You're welcome! Keen to get to the bottom of that though

matt.fellows
2021-06-30 09:35
I'll give that example a go later replacing it with axios. Should be able to get a working example pretty quickly

ali.akbar
2021-06-30 09:36
Yeah, I'd surely be back with a solution if I find one :smile:

v-gabriel.dantas
2021-06-30 20:23
hey guys, is there any reason why my request body does not show up on my pact file? Without the body, I cant verify my provider

phil.endsley
2021-06-30 20:24
We would need to see how the it's defined, not the generated contract

v-gabriel.dantas
2021-06-30 20:25
@phil.endsley

phil.endsley
2021-06-30 20:30
On my phone, so sorry I can't format better. I don't think you should have the data property under `withRequest`

v-gabriel.dantas
2021-06-30 20:31
no prob man

phil.endsley
2021-06-30 20:31
Should be body instead I think

v-gabriel.dantas
2021-06-30 20:31
hum

v-gabriel.dantas
2021-06-30 20:31
let me see

matt.fellows
2021-06-30 22:52
it should be `body`


abubics
2021-07-01 00:45
`data` might be how it's exposed in your http client (which Pact has no knowledge of)

matt.fellows
2021-07-01 02:09
Yeah, I think axios and others use data

zhaoyi0113
2021-07-01 04:25
Hi guys, I am using the order example from https://docs.pact.io/5-minute-getting-started-guide. When looking at consumer side, I see there is a `orderClient.js` and a test case `will receive the list of current orders`. I don?t understand why we need that in consumer side. I thought consumers only need to publish the pacts json file to provider to run the test case. What is the reason for running test cases in consumers side?

tjones
2021-07-01 05:10
Check out this excellent series of diagrams from the people at Pactflow: https://pactflow.io/how-pact-works/#slide-1

tjones
2021-07-01 05:11
The reason tests exist on the client side (before the pact file is written) is so that we can be sure that the consumer: 1) is able to generate the request that we expect 2) is able to understand the response that we expect

tjones
2021-07-01 05:12
It's this feature that gives pact more deployment confidence than other API mocking tools - because we confirm that the same contract is respected by both sides

tjones
2021-07-01 05:13
If you want more details, we have this in the Pact documentation, too: https://docs.pact.io/getting_started/how_pact_works/

zhaoyi0113
2021-07-01 05:15
great, thanks for that.

sgottipati
2021-07-01 06:02
has joined #pact-js

vshankar
2021-07-01 06:06
has joined #pact-js

e.generalov
2021-07-01 07:19
has joined #pact-js

eduards.klavins
2021-07-01 13:44
has joined #pact-js

eduards.klavins
2021-07-01 13:47
Hey, I am getting some very abstract error from `node-pact` when running this thing with jest in nove environment: do you have a clue what is it? ``` FAIL src/__tests__/onmessage-contract.spec.ts WebSocket consumer tests ? bo.TableState_open (31 ms) ? WebSocket consumer tests ? bo.TableState_open thrown: "" 22 | }) 23 | > 24 | it("bo.TableState_open", async() => { | ^ 25 | return messagePact 26 | .expectsToReceive("bo.TableState") 27 | .withContent({ at src/__tests__/onmessage-contract.spec.ts:24:5 at Object.<anonymous> (src/__tests__/onmessage-contract.spec.ts:16:1) [2021-07-01 12:43:18.751 +0000] INFO (1660 on PCNAME.local): pact@9.16.0: Verifying message [2021-07-01 12:43:18.753 +0000] INFO (1660 on PCNAME.local): pact-node@10.12.2: Creating Message [2021-07-01 12:43:18.754 +0000] INFO (1660 on PCNAME.local): pact-node@10.12.2: Creating message pact [2021-07-01 12:43:18.776 +0000] ERROR (1660 on PCNAME.local): pact-node@10.12.2: errno: -2 code: "ENOENT" syscall: "spawn standalone/darwin-1.88.49/pact/bin/pact-message" path: "standalone/darwin-1.88.49/pact/bin/pact-message" spawnargs: [ "update", "--consumer", "TOSClient", "--pact_dir", "/Users/UNAME/PKG_PATH/pacts", "--provider", "BackofficeAPI", "--pact_specification_version", "3" ] [2021-07-01 12:43:18.779 +0000] WARN (1660 on PCNAME.local): pact-node@10.12.2: Pact exited with code -2. [2021-07-01 12:43:18.779 +0000] INFO (1660 on PCNAME.local): pact-node@10.12.2: Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 1.893 s, estimated 3 s Ran all test suites matching /src\/__tests__\/onmessage-contract.spec.ts/i.```

tjones
2021-07-01 13:50
This is saying that the pact-node install hasn?t been successful. Try removing node_modules and doing `npm install` again.

eduards.klavins
2021-07-01 13:51
I am using yarn berry and pnp - is that combo supported? I dont have any node_modules anymore

tjones
2021-07-01 13:51
This happens if the binary is missing.

tjones
2021-07-01 13:52
It is supported, but lots doesn?t work with berry and pnp

tjones
2021-07-01 13:53
It should install correctly with yarn/berry. But you can?t tell if it worked or not because they suppress all output from scripts.

eduards.klavins
2021-07-01 13:54
I did `yarn cache clean --all` and then `yarn install` again but still getting the same errors. Install goes successfully. :confused:

tjones
2021-07-01 13:54
I forget where the path is that yarn unpacks to, but clean that and do a reinstall

tjones
2021-07-01 13:54
I don?t think it?s the cache

tjones
2021-07-01 13:55
I couldn?t get pact working with yarn pnp because of unrelated issues. My view is that yarn?s experimental release is broken

tjones
2021-07-01 13:55
But, if you have gotten this far, the binary should be there and working

tjones
2021-07-01 13:55
We had a thread about it last week

eduards.klavins
2021-07-01 13:56
Yea, other devs on my team have no issues so I think this could work: > I forget where the path is that yarn unpacks to, but clean that and do a reinstall Will give you an update :wink:


tjones
2021-07-01 13:56
Here?s the thread

tjones
2021-07-01 13:57
My conclusion is: 1) Yarn is broken 2) if there?s something we can change to improve the experience for yarn users please let us know and we?ll do it

tjones
2021-07-01 13:59
Yarn berry keeps the packages zipped unless they have postinstall scripts

tjones
2021-07-01 13:59
So it will unpack pact-node so that it can go get the correct binaries

tjones
2021-07-01 14:00
I think it?s a hidden folder in the project directory, but I am not at my computer to check

eduards.klavins
2021-07-01 14:01
~|~

eduards.klavins
2021-07-01 14:08
Got: `@pact-foundation/pact-node@npm:10.12.2 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/mb/tf9xgkzd0bl2g5_1y2f7fv84jg9s7n/T/xfs-e0e6e6d5/build.log` And those logs say: ```# This file contains the result of Yarn building a package (@pact-foundation/pact-node@npm:10.12.2) # Script name: postinstall Installing Pact Standalone Binary for darwin. Downloading Pact Standalone Binary v1.88.49 for platform darwin from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.49/pact-1.88.49-osx.tar.gz Please note: we are tracking this download anonymously to gather important usage statistics. To disable tracking, set 'pact_do_not_track: true' in your package.json 'config' section. Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error downloading binary from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.88.49/pact-1.88.49-osx.tar.gz: Error: Error while installing binary: Error: self signed certificate in certificate chain at throwError (/Users/eduardsk/Development/games/.yarn/unplugged/@pact-foundation-pact-node-npm-10.12.2-cc2bb34b6a/node_modules/@pact-foundation/pact-node/standalone/install.js:40:11) at /Users/eduardsk/Development/games/.yarn/unplugged/@pact-foundation-pact-node-npm-10.12.2-cc2bb34b6a/node_modules/@pact-foundation/pact-node/standalone/install.js:335:16 at processTicksAndRejections (node:internal/process/task_queues:94:5) ``` What are those cert errors?

2021-07-01 14:08
Please see these instructions on running and accessing a Pact Broker over TLS https://docs.pact.io/pact_broker/advanced_topics/using-tls/

felix.gomez
2021-07-01 14:38
has joined #pact-js

dimundo
2021-07-01 15:17
nice to see a colleague here :smile: @eduards.klavins :hand:

david.vancouvering
2021-07-01 17:07
:thumbsup:

v-gabriel.dantas
2021-07-01 18:44
hey guys, do you know if there is a way to ignore some values from the response provider when I try to verify it?

dimundo
2021-07-01 18:54
wrap with `like` in consumer ?

dimundo
2021-07-01 18:55
but you need to understand what will happen :slightly_smiling_face:

dimundo
2021-07-01 18:55
or regexp power

dimundo
2021-07-01 18:55
( also there are some predefined :wink: )

v-gabriel.dantas
2021-07-01 18:56
cool

v-gabriel.dantas
2021-07-01 18:57
what will happen if I use the `like` function wrapped in my consumer body?

dimundo
2021-07-01 18:59
most probably 1st one will match any int, 2nd any string - depends on consumer https://docs.pact.io/getting_started/matching/

bbako
2021-07-01 20:51
has joined #pact-js

tjones
2021-07-01 23:32
In general, if you need to ignore something from the provider (as in, the consumer doesn't care about it), just don't include it in the pact.

tjones
2021-07-01 23:32
The pact should only contain things the consumer needs, which means that it's not safe to ignore fields

matt.fellows
2021-07-01 23:33
This looks like you have proxies in the way


matt.fellows
2021-07-01 23:35
@tjones actually ran into another proxy problem yesterday. I'll raise an issue for an idea I have to get better visibility into that. But this shows the upside of bundling the package

tjones
2021-07-01 23:40
Yep. We'll still have problems with Yarn 2, but I don't think that's easy to avoid.

tjones
2021-07-01 23:41
The ruby binaries compress really well. I was thinking we could ship them compressed (inside the package) and then uncompress as needed

matt.fellows
2021-07-01 23:48
Makes sense to me.

matt.fellows
2021-07-01 23:48
It would solve problems for people right now

matt.fellows
2021-07-01 23:48
> Yep. We?ll still have problems with Yarn 2, but I don?t think that?s easy to avoid. I don?t know the ins/outs of this. What?s the TL;DR?

v-gabriel.dantas
2021-07-01 23:49
hum, thats a great idea @tjones

v-gabriel.dantas
2021-07-01 23:49
Thanks a lot

phil.armstrong
2021-07-02 06:49
has joined #pact-js

eduards.klavins
2021-07-02 06:51
Can confirm that install works with disabled proxy? :raised_hands: Thanks!

matt.fellows
2021-07-02 06:52
:thumbsup:

matt.fellows
2021-07-02 06:52
gah, proxy!

matt.fellows
2021-07-02 06:54
did you disable it via something like  `no_proxy` and `NO_PROXY` to `localhost,::1,127.0.0.1` ?

matt.fellows
2021-07-02 06:54
I?d like to add to our readme/debugging guide

eduards.klavins
2021-07-02 07:16
I disabled our corporate client tool on startup :shushing_face: :smile:

matt.fellows
2021-07-02 07:16
ahhh :stuck_out_tongue:

eduards.klavins
2021-07-02 07:16
But - I suspect this might work as well - `export NODE_TLS_REJECT_UNAUTHORIZED=0`

matt.fellows
2021-07-02 07:17
possibly

matt.fellows
2021-07-02 07:17
but also :scream:

gargshubham49
2021-07-02 07:21
has joined #pact-js

dimundo
2021-07-02 07:37
yes, we have some ~mitm~ security , sadly

aubilla
2021-07-02 09:58
:wave: I?m trying to write Consumer tests for this client that calls a service that returns a PDF. ```import { all, call, put, takeLatest } from 'redux-saga/effects'; import axios, { AxiosResponse } from 'axios'; import { fetchPdf } from '../actions'; const fetchPdfWorker = function* (action: any) { try { const fileId = action.payload; yield put(fetchPdf.request()); let { data }: AxiosResponse<Blob> = yield call( axios.get, `/api/reporting/rendering-service/render/${fileId}`, { responseType: 'blob' }, ); yield put( fetchPdf.success(data), ); } catch (error) { yield put(fetchPdf.failure(error)); } finally { yield put(fetchPdf.fulfill()); } }; export default function* run() { yield all([ takeLatest(fetchPdf, fetchPdfWorker), ]); }``` I?m following https://docs.pact.io/implementation_guides/javascript/readme guide and https://github.com/pact-foundation/pact-js/blob/master/examples/typescript/test/get-dog.spec.ts example but I have issues injecting the mock url into a Provider that?s not a class but a Generator function. Do you have an example implementation that would be closer to what I have? Sorry for the n00b question but I?m a Java developer and I?ve discovered JavaScript yesterday :eyes:

eduards.klavins
2021-07-02 10:41
Hey, I have an interesting case here I believe - couldn?t find any examples here. I have a REST endpoint that I am fetching via WebWorker off the main thread - my app sends a `worker.postMessage` to initiate the GET request and then later I would listen to a message from webWorker when data has been fetched. How would I go about writing correct pacts for that? https://github.com/pact-foundation/pact-js/blob/master/examples/jest/__tests__/index.spec.js seems quite basic regarding API calls

dimundo
2021-07-02 10:42
you need ? pact for initial message ? pact for get ? pact for 2nd message


dimundo
2021-07-02 10:43
pact doesnt care about side-effects

eduards.klavins
2021-07-02 10:44
Why? WebWorker is not an ?external? body that I need to communicate with. My get request calls are just ?obfuscated? in webworker and i have no way to directly initiate get request in my code without doing it via webworker

dimundo
2021-07-02 10:44
but you expect some message, right ?

dimundo
2021-07-02 10:45
then you need ? pact for initial message ( as a provider ) ? ~pact for get~ ? pact for 2nd message ( as a consumer )


eduards.klavins
2021-07-02 10:47
1. Frontend app sends a message to webworker(who is still part of FE app) to initiate get request. It is a SYNChronous call 2. WebWorker makes `window.fetch` GET request (async) 3. WebWorker posts message back to frontend app (sync)

tjones
2021-07-03 05:34
I don?t have experience with webworkers for this, but those feel like separate concerns

tjones
2021-07-03 05:34
How do you normally test the webworker boundary?

tjones
2021-07-03 05:35
I would write: Pact test within the webworker for the request/response Regular test for the webworker boundary

tjones
2021-07-03 05:36
If you can?t do that, can you wrap the request/response parts of the webworker in a promise for the purpose of testing?

tjones
2021-07-03 05:37
If you?re able to share some code that includes this webworker pattern, we can give more direct help

tjones
2021-07-03 05:40
It?s a bit hard to help you inject the base url, since that?s more an implementation question for you/your engineers (how are you doing it with the real url?)

tjones
2021-07-03 05:41
But in general, I think there are two concerns there- one is the interface to redux, and the other is the api call. I would separate those out, as it will then be much easier to test and reason about

aubilla
2021-07-05 12:26
Thanks Timothy!

vinnys.lins
2021-07-05 13:49
has joined #pact-js

zhaoyi0113
2021-07-06 00:31
Hi There, I am using nodejs pact and I found there is a field `uponReceiving` used in the example when calling `provider.addInteraction` in consumer test case. But I can?t find what this field mean in the doc. Does it mean anything?

matt.fellows
2021-07-06 00:32
It is the test description, used to differentiate the various scenarious you are testing

matt.fellows
2021-07-06 00:32
e.g. `uponReceiving` ?a request to get a user?

matt.fellows
2021-07-06 00:32
the state then allows you to test various scenarios

matt.fellows
2021-07-06 00:33
`given` ?a user with ID 1234 exists? or ?a team with ID 5678 exists?

zhaoyi0113
2021-07-06 00:35
so it is just a description? it doesn?t have much impact on the logic?

tjones
2021-07-06 00:36
It's just a description - it appears in the test summary in the broker

matt.fellows
2021-07-06 00:36
whilst it?s not a functional aspect of the test, it?s important like naming and describing any test is important. Perhaps even more so, because the provider side will use it to understand what?s going on.

tjones
2021-07-06 00:36
You'll need to ensure that the same description isn't used for different requests.

matt.fellows
2021-07-06 00:36
Think of Pact as building up a description of how your system is integrated

tjones
2021-07-06 00:37
as in you can't be like: "a post to create a user" with two different bodies

zhaoyi0113
2021-07-06 00:38
yes for sure, thanks

zhaoyi0113
2021-07-06 00:38
got it, thanks guys.

tjones
2021-07-06 00:41
I usually keep the `uponReceiving` and `withRequest` together - see for example here: https://github.com/pact-foundation/jest-pact#best-practices

zhaoyi0113
2021-07-06 00:42
make sense thanks

talank
2021-07-06 03:52
has joined #pact-js

tausif2909
2021-07-06 04:49
TypeError: Cannot read property 'log Level' of undefined at Verifier V3.validate Configuration Hello, I get this error while running providerVerification.js , How do I resolve it? Below is the complete error:

matt.fellows
2021-07-06 04:49
sounds like a bug, what does your code look like?

tausif2909
2021-07-06 05:08
```D:\git-directory\tag-service\AcceptanceTests\pact>node providerVerification.spec.js http://192.168.99.101:18132 D:\git-directory\tag-service\AcceptanceTests\node_modules\@pact-foundation\pact\src\v3\verifier.js:65 if (this.config.logLevel && !ramda_1.isEmpty(this.config.logLevel)) { ^ TypeError: Cannot read property 'logLevel' of undefined at VerifierV3.validateConfiguration (D:\git-directory\tag-service\AcceptanceTests\node_modules\@pact-foundation\pact\src\v3\verifier.js:65:25) at new VerifierV3 (D:\git-directory\tag-service\AcceptanceTests\node_modules\@pact-foundation\pact\src\v3\verifier.js:36:14) at Object.<anonymous> (D:\git-directory\tag-service\AcceptanceTests\pact\providerVerification.spec.js:97:8) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) at internal/main/run_main_module.js:17:47```

tjones
2021-07-06 05:26
Are you passing options to `new VerifierV3(opts)`?

tjones
2021-07-06 05:27
Which version of pact-js are you using?

tausif2909
2021-07-06 05:49
I am using `const { VerifierV3 } = require('@pact-foundation/pact/v3');`

bethskurrie
2021-07-06 05:49
@tonynguyenit18 this is probably the longest time I've ever gone between Pact Broker releases, but it's finally out. Please upgrade to 2.80.0.0

tausif2909
2021-07-06 05:49
Error got resolved when I have removed all console.log from the file

tausif2909
2021-07-06 05:50
Previously it was like below

tausif2909
2021-07-06 05:50
```console.log(opts.providerBaseUrl); return new Verifier().verifyProviderV3(opts).then(output => { console.log('Pact Verification Complete!'); console.log(output);```

tausif2909
2021-07-06 05:51
Then I passed simply :`return new VerifierV3(opts).verifyProvider();` Then error got resolved

tausif2909
2021-07-06 06:29
Hello, While running the `providerVerification.js` , Its throwing below error :

tausif2909
2021-07-06 06:30
``` node providerVerification.spec.js [2021-07-06 06:25:16.638 +0000] WARN (11148 on tshaikh): pact@10.0.0-beta.42: non-local provider address http://192.168.99.101:18132 detected, setting 'changeOrigin' to 'true'. This property c an be overridden. [2021-07-06T06:25:17Z ERROR pact_verifier] Failed to load pact - Could not load pacts from the pact broker 'https://pact.xyz.net/' - LinkError("Link 'pb:provider-pacts-for-verification' was not found in the response, only the following links where found: \"curies, pb:latest-pact-versions, pb:latest-provider-pacts, pb:latest-provider-pacts-with-tag, pb:latest-tagged-version, pb:l atest-version, pb:pacticipants, pb:provider-pacts, pb:provider-pacts-with-tag, pb:publish-pact, pb:webhooks, self\". URL: 'https://pact.xyz.net/', LINK: 'pb:provider-pacts-for-verification' ") Failures: 1) Failed to load pact - Could not load pacts from the pact broker 'https://pact.xyz.net/' - LinkError("Link 'pb:provider-pacts-for-verification' was not found in the response, only the fol lowing links where found: \"curies, pb:latest-pact-versions, pb:latest-provider-pacts, pb:latest-provider-pacts-with-tag, pb:latest-tagged-version, pb:latest-version, pb:pacticipants, pb:provi der-pacts, pb:provider-pacts-with-tag, pb:publish-pact, pb:webhooks, self\". URL: 'https://pact.xyz.net/', LINK: 'pb:provider-pacts-for-verification'") There were 1 pact failures (node:11148) UnhandledPromiseRejectionWarning: null (Use `node --trace-warnings ...` to show where the warning was created) (node:11148) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promis e which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_u nhandled_rejections_mode). (rejection id: 1) (node:11148) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zer o exit code.```

tausif2909
2021-07-06 06:31
The pactBroker url: `https://pact.xyz.net/` is accessible

matt.fellows
2021-07-06 06:33
What version is it? Are you passing a full URL to a pact file or just the broker URL?

tausif2909
2021-07-06 06:40
```require('bunyan'); require('chai'); require('path'); const request = require('request-promise'); const { version } = require('./../../Service/package.json') //const { Verifier } = require('@pact-foundation/pact'); const { VerifierV3 } = require('@pact-foundation/pact/v3'); // PACT provider verification const opts = { provider: 'flex-tagWIP-service', providerBaseUrl: 'http://192.168.99.101:18132', pactBrokerUrl: 'https://pact.xyz.net/', publishVerificationResult: true, providerVersion: version, stateHandlers: { "All the tags associated with the given assetId will be returned": setup => { // return { assetId: 303 } return Promise.resolve({ assetId: 303 }) }, } }; return new VerifierV3(opts).verifyProvider();``` This is how my code looks like

tjones
2021-07-06 06:40
I don't know what was happening, but I suspect your `opts` was undefined when it was passed to pact. This isn't validated in the `VerifierV3` and it isn't.

tjones
2021-07-06 06:42
Please tell us which version of pact you are using. If you don't know, you can find it with `npm ls @pact-foundation/pact`

tjones
2021-07-06 06:43
Ah, it's in your log: `pact@10.0.0-beta.42`

matt.fellows
2021-07-06 06:43
What version of the pact broker are you running?

matt.fellows
2021-07-06 06:44
That will determine if the feature is supported

tausif2909
2021-07-06 06:49
Sorry, I am not sure which version are you talking about, Do you mean the highlighted one in below screenshot?

matt.fellows
2021-07-06 06:53
No, it looks like you're running your own pact broker. What version is it?

tausif2909
2021-07-06 06:54
or do you mean I need to update the pactBroker version if I am using `pact@10.0.0-beta.42` ?

matt.fellows
2021-07-06 06:55
Yes you might need to. But first it's be good to know what you're on now, it could be a bug

tausif2909
2021-07-06 06:56
```<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.ooyala.flex</groupId> <packaging>jar</packaging> <artifactId>pact-broker-client</artifactId> <version>1.0-SNAPSHOT</version> <name>pact-broker-client</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.6</version> </dependency> <dependency> <groupId>com.jayway.restassured</groupId> <artifactId>rest-assured</artifactId> <version>2.9.0</version> </dependency> </dependencies> </project>``` This is the xml of pact-broker-client

matt.fellows
2021-07-06 06:56
I need the broker version. The screenshot from before is your broker

matt.fellows
2021-07-06 06:58
You can get it from the response headers to any API call, or head to HAL browser and check the version in the header

matt.fellows
2021-07-06 06:59
Sorry on mobile, I'm sure this is documented somewhere on our docs but can't see immediately

tausif2909
2021-07-06 07:04
ok let me find it

tausif2909
2021-07-06 07:05
`x-pact-broker-version: 2.23.4`

tausif2909
2021-07-06 07:19
:point_up_2:@matt.fellows @tjones

matt.fellows
2021-07-06 07:26
Yep that's super old, possibly multiple years. You won't be able to use The new JS client with that version.

matt.fellows
2021-07-06 07:26
You should definitely update to a newer broker because you're missing out on good stuff! Or look at Pactflow if you don't want to manage your own. We do all of that for you :wink:

juri.petersen
2021-07-06 07:29
has joined #pact-js

juri.petersen
2021-07-06 07:34
Hello, I'm trying to get Pact running with Cypress as the testing framework. When invoking ```const provider = new Pact({ consumer: 'Frontend', provider: 'API', port: 8585, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'debug', });``` in a test the error ```1) An uncaught error was detected outside of a test: TypeError: The following error originated from your test code, not from Cypress. > Cannot read property 'replace' of undefined When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. Cypress could not associate this error to any specific test. We dynamically generated a new test to display this failure. at Object.eval (webpack:///./node_modules/@pact-foundation/pact-node/node_modules/mkdirp/lib/use-native.js?:4:25) at eval (webpack:///./node_modules/@pact-foundation/pact-node/node_modules/mkdirp/lib/use-native.js?:12:30) at Object../node_modules/@pact-foundation/pact-node/node_modules/mkdirp/lib/use-native.js (http://localhost:38411/__cypress/src/js/spec-0.js:207:1) at __webpack_require__ (http://localhost:38411/__cypress/src/main.js:64:30) at eval (webpack:///./node_modules/@pact-foundation/pact-node/node_modules/mkdirp/index.js?:6:36) at Object../node_modules/@pact-foundation/pact-node/node_modules/mkdirp/index.js (http://localhost:38411/__cypress/src/js/spec-0.js:141:1) at __webpack_require__ (http://localhost:38411/__cypress/src/main.js:64:30) at Object.eval (webpack:///./node_modules/@pact-foundation/pact-node/src/service.js?:23:14) at eval (webpack:///./node_modules/@pact-foundation/pact-node/src/service.js?:236:30) at Object../node_modules/@pact-foundation/pact-node/src/service.js (http://localhost:38411/__cypress/src/js/spec-0.js:886:1)``` occurs. I am running `"@pact-foundation/pact": "^9.16.0"` . Is this error caused by configuration mistakes?

leolvicario
2021-07-06 07:36
has joined #pact-js

tausif2909
2021-07-06 07:46
Which should be the suitable version for pact-broker?

matt.fellows
2021-07-06 07:47
Well I'd just upgrade to the latest

abubics
2021-07-06 08:15
Firstly, are you doing something like this? https://pactflow.io/blog/cypress-pact-front-end-testing-with-confidence/ Or are you trying to create contracts from UI-driven tests?

juri.petersen
2021-07-06 08:36
At the moment I am trying to test API endpoints in unit tests driven by Cypress. It may look like this https://github.com/pactflow/example-consumer-cypress/blob/master/cypress/integration/test/products.js but without the setup of cypress commands.

juri.petersen
2021-07-06 08:37
Its not really anything but invoking `new Pact()` in a unit test with cypress. But this fails with the given error.

tjones
2021-07-06 08:43
It looks like it?s failing because the OS calls aren?t available during a UI test. I don?t know much about Cypress, but try the guide that Boris linked.

tjones
2021-07-06 08:43
In general, though, I would say that testing API calls through the UI sounds like the kind of integration test that Pact is designed to eliminate.

tjones
2021-07-06 08:44
I think it would be better to test your API layer with Pact outside the context of Cypress.

swoichhaa
2021-07-06 08:46
has joined #pact-js

juri.petersen
2021-07-06 08:50
Thank you for the feedback!

matt.fellows
2021-07-06 09:05
What Tim said

matt.fellows
2021-07-06 09:05
but also?



matt.fellows
2021-07-06 09:06
So you can do it, just make sure you?re not doing it the wrong way (link in that article about a tale of woe to scare you into doing it properly?if you do)

matt.fellows
2021-07-06 09:06
Also, dirty secret, we do this at Pactflow :stuck_out_tongue:

ivo.velthoven174
2021-07-06 09:28
has joined #pact-js

abubics
2021-07-06 09:44
I've skimmed the article and the readme, but I'm a bit confused (maybe reading them properly would resolve :yay:) . . . I initially thought it was saying to generate the pacts through unit tests (as usual), and then use the pact file with the stub provider in the UI tests (to avoid making calls to real APIs). But the readme sounds like it's running the UI tests at the same time as exercising the pact bits to generate the contract.

matt.fellows
2021-07-06 09:46
Could probably make that clearer

matt.fellows
2021-07-06 09:47
you can do it in 3 ways: 1. Do it in the usual way, then use Pact stubs instead of Cypress stubs 2. Do Pact tests in Cypress (using the Pact interface though, not the Cypress interface). That?s what the example repo does, and actuallly what we do in Pactflow 3. Use Cypress mocks, but serialise them to a pact file and use that as the contract

matt.fellows
2021-07-06 09:47
1 is the safest, but arguably not a nice experience for Cypress users

matt.fellows
2021-07-06 09:47
(2) is a decent compromise - best safety guarantees, and still a fairly straightforward experience with Cypress

matt.fellows
2021-07-06 09:47
(3) is the best Cypress experience, but you will make it very hard for your providers, so you shouldn?t do this, unless you *really* know what you?re doing.

matt.fellows
2021-07-06 09:48
OR you are using the https://docs.pactflow.io/docs/workshops/bi-directional/ feature of Pactflow, which reduces the guarantees with the upside of a simpler overall experience (on both sides)

abubics
2021-07-06 09:48
that's a nice breakdown, and I completely agree xD I hadn't even considered (3) before :open_mouth:

matt.fellows
2021-07-06 09:49
I should put that summary into that article

abubics
2021-07-06 09:56
Also :taco: for @matt.fellows, not just useful info to answer the question, but helpful for everyone else in the thread, too!

matt.fellows
2021-07-06 09:59
I?m proctrastinating, I should be reviewing your talk :wink:

matt.fellows
2021-07-06 10:02
Also, updated that article just now

abubics
2021-07-06 10:18
I'm procrastinating, I should be finishing it :joy:

fjtdg
2021-07-06 12:16
has joined #pact-js

juri.petersen
2021-07-06 12:31
Thanks for the helpful answers! I followed https://github.com/pactflow/example-consumer-cypress and after setting up everything and fixing a few errors caused by me, the same error comes up again.

juri.petersen
2021-07-06 12:44
For further context: I am trying to set this up in a vue3 application.

matt.fellows
2021-07-06 13:36
Could you please share your code? This is not a standard use case so we'll need more information

matt.fellows
2021-07-06 13:36
Also apologies, both links I shared were already discussed above. I think because slack collapsed the thread I didn't see it.

matt.fellows
2021-07-06 13:37
Anyhow, happy to take a look at your setup if you can share

matt.fellows
2021-07-06 13:38
It does seem like it's trying to run in a browser environment or at least a non-node environment

matt.fellows
2021-07-06 13:38
Pact needs to run on node

matt.fellows
2021-07-06 13:39
Not running a new Mac M1 chip?

steve.etherington
2021-07-06 16:44
has joined #pact-js

matt.fellows
2021-07-07 04:57
@tausif2909 how did you go with the injected provider states example?

matt.fellows
2021-07-07 04:58
> How do I modify my request to pass the real ${assetId} while running the provider verification in the nodejs You return them in the provider state: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/provider-state-injected/provider/account-service.test.js#L31-L33

tausif2909
2021-07-07 05:13
As suggested by you, I need to update the pact-broker, I have raised the ops ticket to upgrade the same, our ops team is taking care of that, So I need to wait till that time:stuck_out_tongue_closed_eyes:

rosh.mjohn
2021-07-07 07:19
has joined #pact-js

rosh.mjohn
2021-07-07 07:23
Hi there. I'm trying to write consumer driven contract tests in node. For the provider verification step, can we pass in the specific consumer version that needs to be verified with the provider?

matt.fellows
2021-07-07 07:26
Have you read about tags?

rosh.mjohn
2021-07-07 07:37
I'm more concerned about the consumer version number than the tags. I found these verification options in the docs, couldn't find reference to consumer version.

matt.fellows
2021-07-07 07:39
Can you please explain why? It's an unusual use case

dimundo
2021-07-07 07:49
one must not mix consumer version and tag - they are very different beasts

matt.fellows
2021-07-07 07:53
you almost certainly don?t want to use versions. If you need that level of coupling, best just to pass the exact URL of the pact you need to verify (which you can do via webhooks anyway)

matt.fellows
2021-07-07 07:53
See the CI/CD workshop in howtolearn for best practices on integrating to your deployment pipeline

2021-07-07 07:53
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

juri.petersen
2021-07-07 08:22
Its a vue setup. Unfortunately I cant really share it at the moment. I fixed it to where the Pact MockServer is running. Integrations do not work yet but I guess thats going to need fixing on my side.

mahajanalokkumar
2021-07-07 10:41
has joined #pact-js

dawoud.sheraz
2021-07-07 18:50
Hello. A question about writing consumer tests with pact-js and jest. When attempting to add interaction, what is the possibility that test will execute before the interaction can setup? I am using await when adding interaction but from the logs, it seems the test executes before the interaction can setup.

dawoud.sheraz
2021-07-07 18:51
Log sequence: ```INFO -- : Registered expected interaction GET /api/items/ WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api/items/ W, [2021-07-07T23:45:05.208260 #59740] WARN -- : Missing requests: GET /api/items/ I, [2021-07-07T23:45:05.220478 #59740] INFO -- : Cleared interactions```

jyiyng2002
2021-07-07 19:57
has joined #pact-js

splurgeop
2021-07-07 21:48
has joined #pact-js

kapoor.manil
2021-07-07 22:30
has joined #pact-js

matt.fellows
2021-07-07 23:06
badpromise


matt.fellows
2021-07-07 23:07
if you can share the code, we can take a look

matt.fellows
2021-07-07 23:07
but that is the key symptom of incorrect promise handling

abubics
2021-07-08 00:40
Also (aside), if you're using `pact-js` + `jest`, you might want to try `jest-pact` to simplify a little

pashas.2k3
2021-07-08 03:41
has joined #pact-js

dawoud.sheraz
2021-07-08 04:02
thank you, I will confirm the bad promise bit.

vijayanaggella
2021-07-08 05:25
has joined #pact-js

tausif2909
2021-07-08 05:41
Hi there , I have such huge array json response to add matchers on the consumer side, Just need a suggestion what would be a best approach to add matchers fo such long and complex json, Also at provider side it won't be having that many items in the array, Can we add such matcher that it would verify only first item in the array and ignore other elements?

matt.fellows
2021-07-08 05:44
yes, take a look at the `eachLike` matcher. They all appear to have the same structure, so you could just do something like: ``` eachLike({ "displayName": "New Text 2", "name": "metadata-10128.var-text-new-text-2", "fqlName": "metadata-10128.var-text-new-text-2", "filterType": "string", "dataType": "text", "schema": { "id": 10128, "displayName": "Medium" }, "category": "custom", "filterKey": "metadata-10128.var-text-new-text-2" })```

matt.fellows
2021-07-08 05:44
that says the provider must have `1 or more` items that have those keys with the same _type_

ananthshenoy03
2021-07-08 05:46
has joined #pact-js

tausif2909
2021-07-08 05:57
Just one confusion, How it will still generate such huge json on the consumer side?

tausif2909
2021-07-08 06:00
I have the code written like this.... Not sure How to use `eachLike` here

matt.fellows
2021-07-08 06:06
does it need to generate a big one?

tausif2909
2021-07-08 06:10
Yes, Because this json is being used by the acceptance test further, So I cant change it

matt.fellows
2021-07-08 06:11
You can do `eachLike({?}, min)`

matt.fellows
2021-07-08 06:11
where min can be as many as you like

tausif2909
2021-07-08 06:30
ok, thanks @matt.fellows let me try that

matt.fellows
2021-07-08 06:38
FWIW I always wanted to implement a version of `eachLike` that randomises the data on the consumer side (e.g. using something like `faker`) but has the matchers in it for the provider side

matt.fellows
2021-07-08 06:38
@tjones or @bethskurrie can tell me if that?s a stupid idea :point_up:

sai5i.islam
2021-07-08 06:40
has joined #pact-js

tjones
2021-07-08 07:01
I would do as Matt suggested, where the eachLike generates the examples for you.

bethskurrie
2021-07-08 07:01
it would make a new pact each time

bethskurrie
2021-07-08 07:02
if I understand you correctly Matt.

tjones
2021-07-08 07:02
It's worth thinking about what is under test - Pact is about validating that the consumer and the provider can talk to each other. In general (but not always), it's more about validating that the shape of the data is correct, rather than the exact data is correct

bethskurrie
2021-07-08 07:03
It would negate all the benefits of being able to re-use the pact content to have pacts pre-verified.

bethskurrie
2021-07-08 07:03
Personally, I don't like random data in a test, because it makes the expectations very hard to write.

matt.fellows
2021-07-08 08:54
No, I'm suggesting we could return dynamic mocked data but persist a fixed data set into the contract. Admittedly feels like moving away from contract testing a touch, but I've come across cases where each mocked response needs to actually be different from each other - pact will just return X number of the exact same thinf

matt.fellows
2021-07-08 08:55
The dynamic mocked data must obviously be based on the contract definition, so it's essentially a v3 generator

poorvasgokhale
2021-07-08 09:08
has joined #pact-js

suresh.thammishetti
2021-07-08 11:08
has joined #pact-js

zhaoyi0113
2021-07-08 11:31
Hello guys, a quick question about provider verification: when run pact verify in provider side, if there are multiple consumers pacts in the broker, will provider verify runs in parallel or in sequence?

matt.fellows
2021-07-08 11:32
It will run them sequentially. The order of contract (and interactions) within them is non-deterministic

zhaoyi0113
2021-07-08 11:35
oh, it doesn?t run them in the same order from the `pacts file`?

matt.fellows
2021-07-08 11:36
it?s implementation dependent, but it?s best to assume (and design for) that it?s non deterministic

matt.fellows
2021-07-08 11:36
One of the fundamental aspects of pact, is that each interaction should be independent of all others

zhaoyi0113
2021-07-08 11:37
ok I see thanks.

tjones
2021-07-09 03:05
> Admittedly feels like moving away from contract testing a touch, but I've come across cases where each mocked response needs to actually be different from each other - pact will just return X number of the exact same thinf I think a better approach might be: ```eachLike( someTemplate, populatedExampleArray )```

tjones
2021-07-09 03:08
for example: ```eachLike ( { id: integer(), name: string() }, [{id: 1, name: "foo"}, {id: 2, name: "bar"}])```

matt.fellows
2021-07-09 03:21
agree!


zhaoyi0113
2021-07-09 09:11
Hello, I am checking how to pass access token when publishing pacts but this doc https://docs.pact.io/provider/handling_auth doesn't provider much examples. Provider needs to check whether a token in the request's header is valid before processing the request. This token is short live which means it needs to be generated at run time. so it is not possible to put the token as part of `pact`. Is there an example to see how to pass a runtime token in a middleware when provider verifies the pacts?


matt.fellows
2021-07-09 10:00
The JS workshop also covers this scenario

matt.fellows
2021-07-09 10:00
(howtolearn)

2021-07-09 10:00
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-07-09 10:00
I'm keen for feedback as to why they weren't discoverable to you (not a criticism I'm genuinely keen to understand so that we can fix)

michael.katende
2021-07-09 10:41
has joined #pact-js

marcin.baranowski953
2021-07-09 10:42
has joined #pact-js

uladzislau_danilchyk
2021-07-09 10:47
Hi everyone! I have a question regarding verification reports. Is there any possibility to group reports by consumer tag if passed multiple consumer tags or I need to write custom reporter? For example: I run the verification test and pass property `pactbroker.consumerversionselectors.tags` equal to `branch-tag-1,branch-tag-2` . But in reports If some contract of any tag was failed I can't determine for which tag it was failed. I need to open `html report` -> `Standart Output` tab to determine it instead of searching failed tests in `Tests` tab as usual with printed tag along with version. Thanks in advance!

matt.fellows
2021-07-09 10:52
what are these ?tabs? that you are talking about sorry?

zhaoyi0113
2021-07-09 11:09
sorry, I didn?t find it mentioned in this pact-js doc. I only read this doc: https://docs.pact.io/provider/handling_auth.

zhaoyi0113
2021-07-09 11:12
@matt.fellows, a little more thought about this. If I create 3 interaction in consumer side: 1. create an user 2. update the user 3. delete the user If they can run in order, I don?t need to mock any data in provider side. But if they can run in any order, provider has to mock the data for each interaction. That brings a bit effort to provider side.

uladzislau_danilchyk
2021-07-09 11:31
reports generated by Gradle

matt.fellows
2021-07-09 11:33
Ah, that makes more sense. Probably best asking this in the #pact-jvm channel

matt.fellows
2021-07-09 11:54
so why use Pact? Might as well just do end-to-end tests!

bedfordwest
2021-07-10 22:21
has joined #pact-js

ananthshenoy03
2021-07-11 07:41
Hello, I'm trying to get Pact running with VS code as the testing framework. When I run the command npm start in the terminal I get the following error ```react-scripts start sh: 1: react-scripts: not found npm ERR! Linux 4.4.0-190-generic npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start" npm ERR! node v6.17.1 npm ERR! npm v3.10.10 npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! consumer@0.1.0 start: `react-scripts start` npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the consumer@0.1.0 start script 'react-scripts start'. npm ERR! Make sure you have the latest version of node.js and npm installed. npm ERR! If you do, this is most likely a problem with the consumer package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! react-scripts start npm ERR! You can get information on how to open an issue for this project with: npm ERR! npm bugs consumer npm ERR! Or if that isn't available, you can get their info via: npm ERR! npm owner ls consumer npm ERR! There is likely additional logging output above. npm WARN Local package.json exists, but node_modules missing, did you mean to install? npm ERR! Please include the following file with any support request: npm ERR! /home/ananthshenoy/devhome/demopact/example-consumer/npm-debug.log```

ananthshenoy03
2021-07-11 07:56
```ananthshenoy@ubuntu-HP:~/devhome/demopact/example-consumer$ npm t > consumer@0.1.0 test /home/ananthshenoy/devhome/demopact/example-consumer > cross-env CI=true react-scripts test sh: 1: cross-env: not found npm ERR! Test failed. See above for more details. npm WARN Local package.json exists, but node_modules missing, did you mean to install?```

matt.fellows
2021-07-11 08:08
Have you run npm install?

matt.fellows
2021-07-11 08:08
Also VS code is not a test framework, are you running from the terminal in VS code or via the run/debug features l?

ananthshenoy03
2021-07-11 09:21
Yes I have run npm install for which I got the following ```npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/react-scripts/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/jest-haste-map/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/watchpack-chokidar2/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/webpack-dev-server/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN react-scripts@3.4.4 requires a peer of typescript@^3.2.1 but none was installed. npm WARN sass-loader@8.0.2 requires a peer of node-sass@^4.0.0 but none was installed. npm WARN sass-loader@8.0.2 requires a peer of sass@^1.3.0 but none was installed. npm WARN sass-loader@8.0.2 requires a peer of fibers@>= 3.1.0 but none was installed. npm WARN @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.14.5 requires a peer of @babel/core@^7.13.0 but none was installed. npm WARN @babel/plugin-proposal-class-static-block@7.14.5 requires a peer of @babel/core@^7.12.0 but none was installed. npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none was installed.```

ananthshenoy03
2021-07-11 09:21
Yes I'm running the commands via VS code Terminal

ananthshenoy03
2021-07-11 09:23
After running `npm install` I tried running the test `npm t` for which I got the following ```npm t > consumer@0.1.0 test /home/ananthshenoy/devhome/demopact/example-consumer > cross-env CI=true react-scripts test /home/ananthshenoy/devhome/demopact/example-consumer/node_modules/cross-env/src/index.js:23 ) ^ SyntaxError: Unexpected token ) at createScript (vm.js:56:10) at Object.runInThisContext (vm.js:97:10) at Module._compile (module.js:549:28) at Object.Module._extensions..js (module.js:586:10) at Module.load (module.js:494:32) at tryModuleLoad (module.js:453:12) at Function.Module._load (module.js:445:3) at Module.require (module.js:504:17) at require (internal/module.js:20:19) at Object.<anonymous> (/home/ananthshenoy/devhome/demopact/example-consumer/node_modules/cross-env/src/bin/cross-env.js:3:18) npm ERR! Test failed. See above for more details.```

ananthshenoy03
2021-07-11 09:25
I have cloned this demo project https://github.com/pactflow/example-provider into my local and trying to run the sample tests. Looks like I have some issue with installation set up could you guide me on this

matt.fellows
2021-07-11 11:42
what version of node are you running?

matt.fellows
2021-07-11 11:43
You can see the latest GH actions build is running, so the project definitely works: https://github.com/pactflow/example-provider/actions/runs/1013579203

matt.fellows
2021-07-11 11:43
have you made any changes to the project?

firstamit
2021-07-11 14:07
has joined #pact-js

omar554
2021-07-11 21:54
has joined #pact-js

k.deepupardha
2021-07-12 10:23
has joined #pact-js

ananthshenoy03
2021-07-12 10:45
I have following version installed ```@ubuntu-HP:~/devhome/demopact/example-consumer$ node -v``` `v6.17.1`

lumenofor
2021-07-12 10:46
has joined #pact-js

matt.fellows
2021-07-12 10:47
They are very old versions, we don't support 6 so I'm not surprised. Can you update?

matt.fellows
2021-07-12 10:48
It was EOL over 2 years ago

matt.fellows
2021-07-12 10:54
Another thing to note Ananth is that Pact is targeted at developers who have access to the code base and have familiarity writing unit tests

matt.fellows
2021-07-12 10:55
It's not a black box testing tool, so just bear that in mind - strong Dev knowledge of the language you are testing is recommended

ananthshenoy03
2021-07-12 11:55
Upgraded node version to latest `v16.4.2`and tried running the test using command `npm t` ```npm t > consumer@0.1.0 test > cross-env CI=true react-scripts test node:events:371 throw er; // Unhandled 'error' event ^ Error: spawn react-scripts ENOENT at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19) at onErrorNT (node:internal/child_process:480:16) at processTicksAndRejections (node:internal/process/task_queues:83:21) Emitted 'error' event on ChildProcess instance at: at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12) at onErrorNT (node:internal/child_process:480:16) at processTicksAndRejections (node:internal/process/task_queues:83:21) { errno: -2, code: 'ENOENT', syscall: 'spawn react-scripts', path: 'react-scripts', spawnargs: [ 'test' ] } ```

matt.fellows
2021-07-12 12:10
Have you tried removing node modules and reinstalling?

matt.fellows
2021-07-12 12:10
The previous install could be bogus given the old npm

dimundo
2021-07-12 13:13
hi! anyone encountered, that provider tests doesnt update pacts for broker from CI (works normally from local PC) ? consumer tests publishes new pacts from same build from CI

matt.fellows
2021-07-12 13:16
have you enabled publishing of verification results?


dimundo
2021-07-12 13:27
> http://process.env.CI !== undefined > true from logs

dimundo
2021-07-12 13:29
so, if i put explicitly true locally - it handles provider updates

dimundo
2021-07-12 13:49
and one more thing: with `user` account provider cant post verification - is this ok ? works in pact4s ( jvm/scala )

jayr.motta
2021-07-12 13:57
has joined #pact-js

dimundo
2021-07-12 14:21
and the answer is here

dimundo
2021-07-12 14:22
token remained from POC, which used token, and message was buried in DEBUG and having INFO logs nothing happened

doug.shattuck
2021-07-12 20:26
has joined #pact-js

matt.fellows
2021-07-12 22:06
What does that mean, sorry I don't understand the q

matt.fellows
2021-07-12 22:08
I'm incline to say "no" but I'm not quite sure :-)

matt.fellows
2021-07-12 22:17
Hmm I would have thought verification should failed with a rejected promise - are you sure you're not swallowing the exception?

tjones
2021-07-13 01:18
Also, could you share the log section where this error came up as DEBUG? I think it should be at least `WARN`

dimundo
2021-07-13 06:51
so, not much in logs, but warn appears with debug only ( maybe there is something like logback.xml in js ? )

dimundo
2021-07-13 06:56
not sure from where Thor came, but let it stay here

matt.fellows
2021-07-13 06:57
that?s definitely a bug if it?s not throwing an exception

matt.fellows
2021-07-13 06:57
I think pact-node tries to parse this output so perhaps that?s why it?s a `DEBUG` message. I?m surprised it doesn?t actually error though

dimundo
2021-07-13 06:58
maybe due pending ?

dimundo
2021-07-13 06:58
like ?failed? meh, whatever - its a pending one? :smile: havent dig into code still, so just some giggling/speculations

matt.fellows
2021-07-13 06:59
thanks

matt.fellows
2021-07-13 07:00
I hope not, but could be

matt.fellows
2021-07-13 07:00
Just raising an issue now


matt.fellows
2021-07-13 07:01
If you have more detail to add, that would be helpful

dimundo
2021-07-13 07:02
i have a feeling, that swallower promise could be the case

matt.fellows
2021-07-13 07:03
on your side or pact-node?

dimundo
2021-07-13 07:04
im not a js guru, so Promises sometimes makes me sad

dimundo
2021-07-13 07:04
does that looks ok ?

matt.fellows
2021-07-13 07:05
nah that looks OK, pretty sure it?s a problem in the Ruby process actually

matt.fellows
2021-07-13 07:05
```? YN0000: [2021-07-12 13:53:13.025 +0000] DEBUG (1219 on runner-uzumdsnp-project-10-concurrent-1gzcgn): pact-node@10.12.2: You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration. ? YN0000: Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?` in `Pact::ProviderVerifier::CLI::Verify````

matt.fellows
2021-07-13 07:06
It?s exiting with a `0` status code, so pact-node things it?s totally fine

dimundo
2021-07-13 07:06
but why Thor ?

dimundo
2021-07-13 07:06
its some Ruby internal joke ?

matt.fellows
2021-07-13 07:13
Thor is the CLI library it uses


dimundo
2021-07-13 07:16
ah, thought is Tor not Thor, but its Thor

matt.fellows
2021-07-13 07:17
:smile:

sorin_balbae
2021-07-13 07:41
has joined #pact-js

akara
2021-07-13 10:34
has joined #pact-js

nathan.derave
2021-07-13 12:28
has joined #pact-js

matthew.schaad
2021-07-13 21:29
has joined #pact-js

neenad.jadhavgre
2021-07-13 22:30
has joined #pact-js

neenad.jadhavgre
2021-07-13 22:43
Hello there, I am trying to implement Provider tests for a bff service and I wanted to take a look at some examples where the provider response is mocked instead of calling the real services.

matt.fellows
2021-07-13 22:48
Do you mean mocking downstream services of the provider you're testing?


cristian
2021-07-14 06:18
has joined #pact-js

michal.bernhard
2021-07-14 11:16
has joined #pact-js

dawoud.sheraz
2021-07-14 11:38
Hi. Does anyone here have any experience writing consumer tests in a codebase that uses axios-mock-adapter to mock some HTTP operations? In the code that I am working with, there is a wrapper layer responsible for making api calls. The client within the wrapper is mocked via axios-mock-adapter and it seems to be messing with pact-js operations.

koradrop
2021-07-14 13:06
has joined #pact-js

robert.strehli
2021-07-14 13:32
has joined #pact-js

neenad.jadhavgre
2021-07-14 14:15
Yes thank you, this is exactly what I need, but having some examples where this kind of stubbing is implemented would be great.

pedroefajardo_pactio
2021-07-14 17:11
for these two steps: ```1) Set up a state change endpoint in your provider 2) Start the provider with these state change endpoint included``` i understand the why, i don?t understand how it works. say, I: ? Add an endpoint to the provider, how and who passes the expected state handler values? now on the provider side, in the endpoint for Pact, are the expected values received and then what? ? How do I use these values in the provider side when the consumer tests run?

richard.jones254
2021-07-14 23:53
has joined #pact-js

edanielsen
2021-07-15 00:46
has joined #pact-js

abatan.k
2021-07-15 03:48
has joined #pact-js

tjones
2021-07-15 04:11
Pact obviates the need to mock in this way

tjones
2021-07-15 04:12
Mocks for the axios layer mean that you're "marking your own exam", in that you don't know if the mock aligns with the actual provider

tjones
2021-07-15 04:13
A Pact contract is like a mock that you can replay against the provider.

tjones
2021-07-15 04:13
So you would replace the Axios mocks with a pact mock.

mandeep302755
2021-07-15 04:49
has joined #pact-js

mahajanrupali22
2021-07-15 05:46
has joined #pact-js

dawoud.sheraz
2021-07-15 05:51
hmm, that is a tough scenario. The axios mock is for mocking the client and its auth service.

matt.fellows
2021-07-15 10:33
Why are you mocking the client in a pact test? Usually, that's the exact thing you want to unit test (and therefore not mock)

matt.fellows
2021-07-15 10:33
If you need to mock downstream auth, you can do that with pact (or stub it out of it's a separate service, and have a separate pact test to cover that)

matt.fellows
2021-07-15 10:34
What do you use for stubbing now?

matt.fellows
2021-07-15 10:34
Tools like Jest, Sinon etc are pretty standard

dawoud.sheraz
2021-07-15 11:47
So the flow that is happening is like `getCustomClient().get/post/put` . The custom client contains user information and acts as a layer for making api calls with axios. For unit tests, the client information is mocked via a MockAuth service. What I am trying to test via pact is the actual api calls(get/post/put etc.), so I am only adding interactions for that. Since underlying client has some details too, I am not sure if mocking them with pact is the right answer here. Please correct me if I am wrong/missed some context. Thanks

hylke.de.jong
2021-07-15 12:49
has joined #pact-js

efemgy
2021-07-15 14:27
has joined #pact-js

crazycabo350
2021-07-15 18:17
has joined #pact-js

matt.fellows
2021-07-15 23:25
As in, `getCustomClient` makes three calls, and only one of them needs to be mocked by Pact?

matt.fellows
2021-07-15 23:25
Perhaps axios mock adapter isn?t the ideal use here, and other stubbing tools could be used?

matt.fellows
2021-07-15 23:26
But also, from memory, axios mock adapter let?s you configure which calls to stub, so presumably you could exclude the ones that goto Pact

amreenshaik.basha
2021-07-16 04:06
has joined #pact-js

rhian.van.esch
2021-07-16 12:14
has joined #pact-js

wilco.van.esch
2021-07-16 12:30
has joined #pact-js

karl.morrison
2021-07-16 12:56
has joined #pact-js

timothyjabez
2021-07-16 17:23
has joined #pact-js

abatan.k
2021-07-16 18:37
Hello, i am a little bit lost with pact un JS world. I am confuse about which way to go when publishing and checking if we can deploy. In the docs, I see that we wrote a publish-contracts.js file , but to check if we can deploy, we use a docker image. Can we create a script in JS for checking if we can deploy ? I would like to be able to use two command for publishing & check deploy like that: `yarn pact:publish` => `ts-node publish-contracts.ts` `yarn pact:can-ideploy` => `ts-node can-i-deploy.ts`

abatan.k
2021-07-16 20:13
I wanted to delete the message, since i found the class `CanDeploy` on the package `@pact-foundation/pact-node` , but i can't :sweat_smile:

matt.fellows
2021-07-16 22:26
I'd recommend using the CLI for both activities. It's bundled into the JS package already

matt.fellows
2021-07-16 22:26
Personally I don't use the JS interface for publishing / can-i-deploy

abatan.k
2021-07-16 23:14
oh, i did not see the binaries `pact-broker` in the node_modules, did i miss it on the docs ??

matt.fellows
2021-07-16 23:22
It's documented somewhere but probably not very obvious

matt.fellows
2021-07-16 23:22
You could use `npx pact-broker`

matt.fellows
2021-07-16 23:22
That's what I do, and I should update the examples to do also

abatan.k
2021-07-16 23:33
yes, i found it, i will use it then, thx for your help :slightly_smiling_face:

tjones
2021-07-17 03:13
@abatan.k In general, you should only need to use things from pact-node directly if you are writing tooling for pact. Is there somewhere the documentation needs improving?

abatan.k
2021-07-17 19:39
Hello, i would like to know if it's possible to use a matcher for the status code. (I'm using jest-pact) My first interaction use a Matcher like this one: ```willRespondWith: { status: Matchers.regex({ generate: '200', matcher: '[200-299]', }), },``` My second interaction uses a Matcher like this one: ```willRespondWith: { status: Matchers.regex({ generate: '0', matcher: '0|[^200-299]', }), },``` Is that legit or is there any matcher to perform a range check on a status code ??

abatan.k
2021-07-17 19:52
@tjones I think that the doc may be improve indeed. At first glance, when i look at the documentation, on js side, i'm a little bit confuse. If i'm a node developer, i prefer to manage every related test and other tools for testing with some script from package.json. But in the doc, the examples for nodejs, are using docker and a Makefile. Which, imo, are mostly interesting for devops in an organization. But for a single JS developer, he/she would rather use what he/she knows, that means a simple call to `npx pact:publish` which translate to `npx pact-broker publish ...` I think that the same things go for a PHP developer, who prefer to use a command with `composer` to publish and check if he can deploy. All i say, is that to bring down the barrier level when discovering Pact, you should propose to use tools that developers of specific language and environment are used to. And show how in the docs :slightly_smiling_face:

matt.fellows
2021-07-17 22:21
It's not available yet but coming in the next major Pact version

matt.fellows
2021-07-17 22:21
At the moment you need to be specific

abatan.k
2021-07-17 23:22
nice to know, do you have roadmap accessible ? :slightly_smiling_face:

matt.fellows
2021-07-18 02:38
There are kind of a few. We use https://pact.canny.io/ to drive features across the framework, and https://github.com/pact-foundation/pact-specification/tree/version-4 (that?s the latest version) to drive framework level (essentially, what the pact file structure is) changes

tjones
2021-07-18 08:18
As Matt says, at the moment it's not possible to do this. A couple of things to keep in mind though: * In general, you want to only specify what your client needs. So, you don't have to enumerate the whole API (sometimes people try to do this). * However, sometimes you don't care about the content, just that there was a 2XX. Unfortunately, at the moment you'll need to know whether your provider returns a 200 or a 204.

tjones
2021-07-18 08:18
Also, I don't think status 0 is valid. Is your provider really returning that?

tjones
2021-07-18 08:20
A quick google search suggests that status 0 is returned from a few different request libraries, but it seems unlikely that a server is really returning that

abatan.k
2021-07-18 08:21
yes exactly

abatan.k
2021-07-18 08:21
it is returned usually by request librairies

tjones
2021-07-18 08:21
> But in the doc, the examples for nodejs, are using docker and a Makefile. Which example is this?

tjones
2021-07-18 08:22
As far as I am aware, none of the pact-js examples use makefiles



tjones
2021-07-18 08:22
Oh, that's a Pactflow example. I don't know anything about that.


tjones
2021-07-18 08:23
^ @matt.fellows

abatan.k
2021-07-18 08:23
it's not a problem though :wink:

abatan.k
2021-07-18 08:24
i get this status code when the url is not specified, and in my case, the consumer is for the client, and i suppose that any request without 2xx status code is a failed one (from the viewpoint of the user :slightly_smiling_face:)

tjones
2021-07-18 08:25
Thanks. That's part of the Pactflow documentation, I'm afraid - which is outside the Pact OSS sphere. I personally think it's confusing for Pactflow to have their own examples of how to use Pact

tjones
2021-07-18 08:26
@matt.fellows, I think this is another strike in favour of moving the pactflow examples into the main repo.

abatan.k
2021-07-18 08:27
well most of new user of pact (and solo dev) will use pactflow instead of hosting personal pact-broker

abatan.k
2021-07-18 08:28
when i discovered pact, i though that pactflow and pact was the nearly the same thing (or very closely related)

abatan.k
2021-07-18 08:28
like npm and node

tjones
2021-07-18 08:28
Yes, but pactflow is a different entity. I don't work for them, I'm an open source maintainer.

abatan.k
2021-07-18 08:28
oh ok :slightly_smiling_face:

tjones
2021-07-18 08:28
Yes, I agree that this is confusing. I'd really like to clear that up.

tjones
2021-07-18 08:28
I think we can be better at making it clear that there's a difference

tjones
2021-07-18 08:29
and I'd like to see more use of the open source examples (or at least a `examples/pactflow`) in the pactflow documentation.

tjones
2021-07-18 08:31
> If i'm a node developer, i prefer to manage every related test and other tools for testing with some script from package.json. Yes, 100%. After the Pact spec V3 release for Pact-JS I plan to tackle the config issue: https://github.com/pact-foundation/pact-js/issues/602 This will make it much easier to use scripts in package.json

tjones
2021-07-18 08:32
It's possible at the moment - for example, here's a line from one of my personal projects: ``` "pact:publish": "pact-broker publish pacts --consumer-app-version=\"$(absolute-version-from-git-tag)\" --broker-base-url=https://tjones.pact.dius.com.au/ --broker-token=\"$TJONES_PACT_CI_TOKEN\""```

abatan.k
2021-07-18 08:32
In the https://github.com/pact-foundation/pact-js/tree/master/examples/jest you use a publish.js file, which was the thing that lead me to using JS Classes to implement publishing & can-i-deploy :slightly_smiling_face:

tjones
2021-07-18 08:32
Yes. That's a pattern I would really like to remove

tjones
2021-07-18 08:33
I'll make an issue for it

abatan.k
2021-07-18 08:33
Anyway, i see that in the Node documentation, you use the binaries from node_modules, so i guess it's ok :slightly_smiling_face:


tjones
2021-07-18 08:38
> Anyway, i see that in the Node documentation, you use the binaries from node_modules, I'm not sure it's very clear, though. For example, this in the documentation still uses `pact-node` directly: https://github.com/pact-foundation/pact-js#publishing-pacts-to-a-broker

tjones
2021-07-18 08:39
definitely something we should fix

tjones
2021-07-18 08:39
where in the docs are you seeing using the binstubs?


tjones
2021-07-18 08:41
Ah, amazing! I'll link that to the issue

tjones
2021-07-18 08:41
thank you

abatan.k
2021-07-18 08:41
i get there by clicking on _*Complete Example (Node env)*_ on this page https://docs.pact.io/implementation_guides/javascript

tjones
2021-07-18 08:41
I'd really like to update all the examples so they all showcase the same features, too

tjones
2021-07-18 08:41
Thank you!

tjones
2021-07-18 08:42
That example still uses `publish.js` though. So it's a bit of a hybrid

abatan.k
2021-07-18 08:42
your welcome, thx to you to maintain a good project like this one :slightly_smiling_face: it's a pleasure to do contract testing with pact :slightly_smiling_face:

tjones
2021-07-18 08:46
Thank you! You're very welcome, and I'm glad it's a useful tool! I think the pactflow initiative is a very good one (and I use it myself, as you can see from my example), but there are a few places where the concerns have leaked between documentation / examples etc.

tjones
2021-07-18 08:48
So, the pact mock is setting up the actual interaction which will be returned from the actual (mock) server. I suspect that if you want to test the case of incorrect config returning 0 from your framework, then you'll need to do a test that isn't a pact test.

abatan.k
2021-07-18 08:49
ok, i was thinking about that :slightly_smiling_face: thx for the insight :wink:

tjones
2021-07-18 08:49
Letting us know where the confusing bits are is really really useful!

abatan.k
2021-07-18 08:50
yes, of course, and it seems like pact is slowly migrating to v3, so it can ben difficult to maintain perfect documentation :slightly_smiling_face:

matt.fellows
2021-07-18 11:20
Thanks Carere, that?s helpful

matt.fellows
2021-07-18 11:21
@tjones not sure I?m following this: > and I?d like to see more use of the open source examples (or at least a `examples/pactflow`) in the pactflow documentation. I think we?re all agreed of trying to merge the documentation in some form, but I don?t know what you mean by ?more use of the open source examples in the pactflow documentation??

matt.fellows
2021-07-18 11:21
As Tim has said, we?re working on making the difference between Pact and Pactflow clearer

tjones
2021-07-18 11:38
I mean, I'm still not clear on why there are examples of how to use pact-js hosted under the pactflow github

tjones
2021-07-18 11:39
there's a react example there, which I would love to have under the main repo

matt.fellows
2021-07-18 11:41
They are examples of how to use Pact with Pactflow

matt.fellows
2021-07-18 11:41
they are also designed to be mixed and matched with the CI/CD workshop

matt.fellows
2021-07-18 11:42
(hence the Makefile)

matt.fellows
2021-07-18 11:42
Lastly, I use them in sales demos. Having them in one place is helpful for customers/prospects after a call

matt.fellows
2021-07-18 11:42
If we had a single combined set of documentation, I think we could make this work though in a non-confusinsg way

matt.fellows
2021-07-18 11:43
It?s kind of a catch 22.

matt.fellows
2021-07-18 11:43
If we had examples that used Pactflow in our OSS repos, that would further blur the lines (that I guess we?re trying to avoid)

matt.fellows
2021-07-18 11:43
but that wouldn?t be helpful to our Pactflow customers, who want clear examples of how to integrate it into their systems

matt.fellows
2021-07-18 11:45
I don?t really want to be creating another island of information, but the reality is we need documentation that makes it easy for Pactflow customers to work with Pact

matt.fellows
2021-07-18 11:46
My vote is still have all of the Pact + Pactflow documentation at http://docs.pact.io and then make the line less blurry.

matt.fellows
2021-07-18 11:46
I think https://docs.cypress.io/ do it well

matt.fellows
2021-07-18 11:46
(The ?Dashboard? is the commercial bit)

github2
2021-07-18 12:20
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.43_ published by github-actions[bot]

tjones
2021-07-18 12:43
> If we had examples that used Pactflow in our OSS repos, that would further blur the lines I guess my thinking is that it would make the lines clearer, because there would be less "how does Pact work" in Pactflow. Especially as the major difference in the pactflow examples is the use of the broker token.

tjones
2021-07-18 12:44
New users don't know (or care) there's a difference between Pact and Pactflow, but we can help people learn by teaching / showing examples of Pact in OSS land, and having the Pactflow specific stuff only over in Pactflow.

tjones
2021-07-18 12:44
I know I'm a broken record on this. Sorry.

tjones
2021-07-18 12:50
I think it will be less confusing with all the examples in one place.

ppdnguyen
2021-07-18 16:23
has joined #pact-js

cgoodison
2021-07-18 23:56
has joined #pact-js

ivo.velthoven174
2021-07-19 12:13
Hi! Is it just me or is `consumerVersionTags` and `consumerVersionSelectors` `VerifierV3Options` just not working in v3?

sripathi
2021-07-19 12:30
has joined #pact-js

pedroefajardo_pactio
2021-07-19 14:02
good morning I am trying to understand the relationship between a consumer state via addInteraction.state and a Provider?s state via state handlers I create some consumer tests in JavaScript where I add a state via: ```provider.addInteraction({ state: 'product with ID 10 exists', ...``` I have a provider written in a language that is not natively supported by http://Pact.io so: ? Added two endpoints, a POST and a GET. I am hoping to call these via `--provider-states-setup-url` and `--provider_states_url` using the `pact-cli` Questions: ? How does running the verifier exercise the provider states? How does it associate a test with state `1` with a provider state handler `1` on a provider that is written in a language that Pact does not support natively? ? Does it get the expected state from the Pact file and injects it (the state) into the test via the url mentioned above? Does it call the POST before the test with a given expectation is run and then it calls the GETter when the test is run? ? How are `stateHandlers` implemented on the Provider side for a provider written on a language not supported by Pact? ? How does the actual verification work if the expected state is being injected? ? Say the provider state, as defined by the consumer, injects state { ?name?:?pact? } for a state on `get/:userId` but the provider is now returning {?firstName?:?pact?}. Since Pact is injecting the state defined by the consumer test how does it fail the test because the actual implementation of the provider is now returning something different?

matt.fellows
2021-07-19 14:17
I just saw your issue. I'll take a look tomorrow. Can you please show your code example with that bug request too?

matt.fellows
2021-07-19 14:18
The trace definitely shows no tags passing thru to the broker, so there is definitely an issue or invalid config (which probably means a bug if it got that far)

ivo.velthoven174
2021-07-19 14:18
I found the issue in the code!

ivo.velthoven174
2021-07-19 14:18
In the rust native code

ivo.velthoven174
2021-07-19 14:19
.

ivo.velthoven174
2021-07-19 14:22
I'll make a PR otherwise, then you can look at it later and make necessary changes. :slightly_smiling_face:


ivo.velthoven174
2021-07-19 15:13
If you can also look at: https://github.com/pact-foundation/pact-js/pull/712 :slightly_smiling_face: would be great!

calvin.krist
2021-07-19 15:29
has joined #pact-js

vinay.viswanadha
2021-07-19 15:30
has joined #pact-js

brian.mitchell
2021-07-19 15:37
has joined #pact-js

pedroefajardo_pactio
2021-07-19 16:05
I found a link for the Lifecycle of a provider verification at https://github.com/pact-foundation/pact-go#lifecycle-of-a-provider-verification I *think* that answers the question of what gets called when but i still have knowledge gaps on how the request filter (pre) and request filter (post) work. I can?t seem to find documentation with examples about the Pact functions, API documentation, in a single place. Maybe I am looking in the wrong place.

mike.geeves064
2021-07-19 18:07
has joined #pact-js

tjones
2021-07-20 01:56
> I can?t seem to find documentation with examples about the Pact functions, API documentation, in a single place. http://docs.pact.io is the core documentation. That pulls in the readmes from the different frameworks

tjones
2021-07-20 01:59
> How does running the verifier exercise the provider states? If you give a state change URL to the verifier, it sends an http request to the state change URL with the state string in the payload.

tjones
2021-07-20 02:01
If it's a V2 pact, the format is a POST request with the payload: ```{ states: [/* state strings*/] }```

tjones
2021-07-20 02:02
You're right that I don't think this is documented obviously (though I think it is documented somewhere). We should fix that.

tjones
2021-07-20 02:03
> Does it call the POST before the test with a given expectation is run and then it calls the GETter when the test is run? Yes, it calls the POST before the test is run. As far as I am aware, there's is no GET call.

tjones
2021-07-20 02:03
> How are stateHandlers implemented on the Provider side for a provider written on a language not supported by Pact? You use a state change endpoint as above.

tjones
2021-07-20 02:52
> How does the actual verification work if the expected state is being injected? I don't think I understand this question, I'm afraid.

tjones
2021-07-20 02:52
With variables injected from the provider, they come as a map in part of the V3 state setup URL

ben.clare2
2021-07-20 08:16
has joined #pact-js

rafael.moral
2021-07-20 11:48
has joined #pact-js

andrii.rakhimov
2021-07-20 23:06
has joined #pact-js

andrii.rakhimov
2021-07-20 23:11
qq: How do you run one particular test with pact? Currently when I pass any argument with `yarn pact:run` it runs all available pact tests in the repo.

boris.gordon
2021-07-20 23:25
has joined #pact-js

matt.fellows
2021-07-20 23:30
Is this on the consumer or provider side?

matt.fellows
2021-07-20 23:30
On the consumer side, it?s just whatever test framework yiou use

matt.fellows
2021-07-20 23:30
if you have an `it('?.', () => {})` then most support `it.only`

pedroefajardo_pactio
2021-07-22 02:39
ok. The pact tests are now running but failing, which is progress. I am using the Dockerized version of the pact-cli the on state for the one test I have so far is being passed into the provider and now what do I do? How do I use the values being injected? I am to store them in a variable and then what? I am looking for examples on how and what to do. I appreciate your help

tjones
2021-07-22 04:25
To use the states, you need to set up a state handler URL on your service that can be started when the provider is spun up for verification. What that state handler does is up to the architecture you have. Usually a repository is stubbed or populated in the state handler.

github2
2021-07-22 06:35
[pact-foundation/pact-js] New release _https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.44_ published by github-actions[bot]

matt.fellows
2021-07-22 06:53
@ivo.velthoven174 :point_up: thanks and :taco: !

matt.fellows
2021-07-22 06:54
We can get a separate release out for the relative imports when that is merged. Tim seems to be across it, so will leave that for the two of you

tjones
2021-07-22 11:35
Oh! I'm not really across it- I haven't had the chance to look yet. I just want to understand why the types changed in that example, because as I understand it so far, they shouldn't have. My theory is that we made a mistake in the past that is somehow uncovered in this situation.

tjones
2021-07-22 11:35
Probably merging it in and finding out afterwards is ok, since we're still in beta.

ryn.anderson
2021-07-22 17:41
has joined #pact-js

pedroefajardo_pactio
2021-07-22 17:57
forgive me for not understanding the purpose of the state handler. ? If a test passes its expected state; and ? if we are supposed to for example, stub the repository, or populate it in the state handler with the data (state) being passed by the state in preparation for when the test runs. Then what is the advantage of using Pact? Or rather how will Pact know something is different between what the actual Provider is returning if the data that?s being returned is the data that was passed by the test?

pedroefajardo_pactio
2021-07-22 18:44
oh, i think i see maybe, I am supposed to seed the db of the app with the state info passed in so that when the test calls the data is in the db and if for any reason the app has changed the way objects are returned from the endpoint under test then there will be a difference between what?s in the Pact in the broker and what the the app is returning. maybe that?s ^^^^^ how this is supposed to work

schakalabbi
2021-07-22 21:29
has joined #pact-js

tjones
2021-07-23 00:02
Yes, your second example is a better way of thinking about it

tjones
2021-07-23 00:03
the state handler is never "under test". Your state handler is called to set up the state that the interaction requires

tjones
2021-07-23 00:03
Pact is for testing the communication boundary

tjones
2021-07-23 00:04
See the diagrams here to get a clear picture: https://docs.pact.io/getting_started/how_pact_works

uryadov212
2021-07-23 06:21
@uryadov212 has left the channel

consulting
2021-07-23 12:33
has joined #pact-js

pedroefajardo_pactio
2021-07-23 13:27
thanks for your replies.

consulting
2021-07-23 13:33
Hi everybody! I'm new to Contract Testing :slightly_smiling_face: I've been able to make Pact work with Angular using Karma Pact. I'm still having a weird behavior though... and I can't figure it out (even after dissecting every tutorial and example I could put my hand on!) It seems that when I launch "ng test", two instances of the Pact Server are started. Important note: I have only one test (to keep things simple) and it seems to be ran twice: ```$ ng test [2021-07-23 12:42:42.582 +0000] INFO (5112 on ULTIMATE-DROU): pact-node@10.12.2: Creating Pact Server with options: {"cors":true,"spec":2,"port":44332,"consumer":"angular-ui","provider":"weatherforecast","logLevel":"DEBUG","log":"D:\\workspaces\\weather-app\\logs\\pact.log","dir":"D:\\workspaces\\weather-app\\pacts","pactFileWriteMode":"overwrite","ssl":false,"host":"localhost"} [2021-07-23 12:42:42.585 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: Starting pact binary 'standalone\win32-1.88.49\pact\bin\pact-mock-service.bat', with arguments [service --cors true --pact_specification_version 2 --port 44332 --consumer angular-ui --provider weatherforecast --log-level DEBUG --log D:\workspaces\weather-app\logs\pact.log --pact_dir D:\workspaces\weather-app\pacts --pact-file-write-mode overwrite --host localhost] [2021-07-23 12:42:42.590 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: Created 'standalone\win32-1.88.49\pact\bin\pact-mock-service.bat' process with PID: 24380 [2021-07-23 12:42:43.137 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [i386-mingw32] [2021-07-23 12:42:43.139 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: INFO WEBrick::HTTPServer#start: pid=26184 port=44332 23 07 2021 08:42:43.629:INFO [pact]: Pact Mock Server running on port: 44332 23 07 2021 08:42:45.315:INFO [karma-server]: Karma v4.3.0 server started at http://0.0.0.0:9876/ 23 07 2021 08:42:45.315:INFO [launcher]: Launching browsers Chrome with concurrency unlimited 23 07 2021 08:42:45.321:INFO [launcher]: Starting browser Chrome 23 07 2021 08:42:48.110:INFO [Chrome 91.0.4472 (Windows 10.0.0)]: Connected on socket BWIFZ4wuaf-PNBtlAAAA with id 7045608 INFO: 'Setting up Pact using mock service on port: "44332"' Chrome 91.0.4472 (Windows 10.0.0): Executed 0 of 1 SUCCESS (0 secs / 0 secs) Chrome 91.0.4472 (Windows 10.0.0): Executed 1 of 1 SUCCESS (0.205 secs / 0.113 secs) TOTAL: 1 SUCCESS TOTAL: 1 SUCCESS [2021-07-23 12:42:49.649 +0000] DEBUG (5112 on ULTIMATE-DROU): pact-node@10.12.2: ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:7 D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread' ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. @ io_fillbuf - fd:6 D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `eof?' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/httpserver.rb:80:in `run' D:/workspaces/weather-app/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.49/pact/lib/vendor/ruby/2.2.0/gems/webrick-1.3.1/lib/webrick/server.rb:191:in `block in start_thread' [2021-07-23 12:42:49.763 +0000] INFO (5112 on ULTIMATE-DROU): pact-node@10.12.2: Removing all Pact servers. [2021-07-23 12:42:49.763 +0000] INFO (5112 on ULTIMATE-DROU): pact-node@10.12.2: Removing Pact process with PID: 24380``` Here's my karma.conf.js (the pact setup excerpt), with a single provider defined ```pact: [{ //When I use cors: true, it creates a double connection... cors: true, //ssl: true, //Version of the Pact json file that will be generated spec: 2, //This port needs to be aligned with the port we use in the angular service to call the API port: 44332, //So far, consumer can be set to anything... consumer: "angular-ui", //This context name has to be the name of the real API context name provider: "weatherforecast", logLevel: "DEBUG", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "pacts"), }]``` And finally, my pact test: ```import {TestBed} from '@angular/core/testing'; import {HttpClientModule} from '@angular/common/http'; import {PactWeb, Matchers} from '@pact-foundation/pact-web'; import { WeatherService } from './weather.service'; import { Weatherforecast } from './weatherForecast'; import * as path from 'path'; describe('WeatherServicePact', () => { var provider; // Setup Pact mock server for this service beforeAll(() => { provider = new PactWeb({ port: 44332, host: 'localhost', }); // Required if run with `singleRun: false` provider.removeInteractions() });```


matt.fellows
2021-07-23 13:46
I can?t understand why two servers wousld be started though

matt.fellows
2021-07-23 13:47
what do you mean by ?double connection??

matt.fellows
2021-07-23 13:47
(also it?s late here, but saw this so thought I could ask some questions)

consulting
2021-07-23 14:04
What I see in the console output is doubled... so I assumed that it was called twice, probably by two different Pact Server. ```Chrome 91.0.4472 (Windows 10.0.0): Executed 0 of 1 SUCCESS (0 secs / 0 secs) Chrome 91.0.4472 (Windows 10.0.0): Executed 1 of 1 SUCCESS (0.205 secs / 0.113 secs) TOTAL: 1 SUCCESS TOTAL: 1 SUCCESS```

consulting
2021-07-23 14:07
When I look at the console output of the tutorials I ran into, they never have doubles like that.

galante2123
2021-07-23 14:14
has joined #pact-js

consulting
2021-07-23 14:34
yeah... it's just an assumption from my part (still juggling with the concepts... it's probably not the server but the providers that are duplicated). It just feels like the Pact Provider configured in the karma config file and the one in the test file are creating this situation... In the Karma & Jasmine example on Pact-JS GitHub, PactWeb is instantiated with no options (hence using the default 127.0.0.1:1234). I tried to align with that code and config as much as possible in prior attempts to make this work, but I never managed to understand the imports required to be able to instantiate PactWeb as a class defined in Pact like seen in the example: "new Pact.PactWeb".

consulting
2021-07-23 14:37
Wow, I just saw that you are located in Melbourne :slightly_smiling_face: Thanks for taking the time! This is not urgent... we can continue the conversation on monday! I'm working on a POC for one of my client... I've heard about Pact a few years ago, but never got time to experiment it myself :slightly_smiling_face:

dc113604
2021-07-23 14:39
has joined #pact-js


matt.fellows
2021-07-23 22:58
That's does look strange. Are you sure there's no extra process configured to start? Any chance you could share your repo or a reproducible example?

matt.fellows
2021-07-23 22:58
FWIW we are wanting to get rid of pact web entirely going forward


matt.fellows
2021-07-23 23:00
TL;DR can you test using a node based tool like Jest/mocha ?

matt.fellows
2021-07-23 23:00
All good! We're used to the world getting busy when we're going down :rolling_on_the_floor_laughing:

tjones
2021-07-25 02:49
You're welcome! Let us know if you have any further questions.

pedroefajardo_pactio
2021-07-25 03:35
thank you

dsinecos
2021-07-26 04:49
has joined #pact-js

mebenhoeh
2021-07-26 05:20
has joined #pact-js

consulting
2021-07-26 07:39
Thanks for all this information! (I was camping this weekend, hence the delay)

matt.fellows
2021-07-26 07:42
no worries, hope it was fun!

consulting
2021-07-26 07:43
I'll look into your alternatives (Jest and Mocha) :slightly_smiling_face: Not being integrated in Karma is not a big deal for me because on most project I worked where Angular was involved, Node was also around). I'll have to ask around and see if that's a problem for them (I'm fairly new to the company)

matt.fellows
2021-07-26 07:45
yeah, I?ve noticed Angular people tend to be pretty keen on staying in the Jasmine/Protractor/Karma (whatever it is these days) env

matt.fellows
2021-07-26 07:45
But honestly, not sure how we?re going to make it work with the latest version of Pact

consulting
2021-07-26 07:46
I mean, I love having that Karma deamon running in the background keeping me honest with having the green bar :slightly_smiling_face:

consulting
2021-07-26 07:47
Angular still very popular... are you aware if people have found other alternatives?

consulting
2021-07-26 08:18
I red the full post you referenced up there... and the suggestion from the team. I tried to use Pact-JS only, doing the setup and finalize by hand but when run using ng test (ultimately Karma), it was complaining that I was missing a bunch of properties on a Browser option (which could be set in the packages.json file)... fixing one would make me stumble on another one :smile:

consulting
2021-07-26 08:26
so my understanding is that even if I don't use Karma-pact and pact-web, and I try to manage the pact server myself, it will still be a problem if I run the test with Angular's default test runner. If that's about right, then I see three options: ? Continue to try to run Pact-JS in Angular with Karma as a test runner (because I was possibly almost there?!) ? Or I could try to run my Angular service in a test suite implemented in Mocha or Jest, injecting my dependancies by hand (or maybe the TestBed would still work... I have no clue.. it's too late / early for me :slightly_smiling_face:) ? Or delegate to a BFF (in Node, Java or some other language supported by Pact) to then be able to test the integration

consulting
2021-07-26 08:27
I'll try to catch some sleep, but I would love to hear your thoughts later :slightly_smiling_face: Thanks again for your precious feedback!

consulting
2021-07-26 14:00
I'm trying to figure out why people using React don't seem to have the same problem? (Unfortunately, I never used React, being a fan of Angular since early 2010!)

matt.fellows
2021-07-26 14:15
React tests run in node, which has access to the filesystem

matt.fellows
2021-07-26 14:15
Karma runs out of node, so it cannot for e.f. start a server so the interface needs to be decoupled from the server

matt.fellows
2021-07-26 14:17
> > Or I could try to run my Angular service in a test suite implemented in Mocha or Jest, injecting my dependancies by hand (or maybe the TestBed would still work... I have no clue.. it's

matt.fellows
2021-07-26 14:17
That's what I'm suggesting

matt.fellows
2021-07-26 14:18
You can do it as per the examples, it just seems like there is an issue

matt.fellows
2021-07-26 14:18
But long term it's probably going to go as an option

matt.fellows
2021-07-26 14:19
Not sure if this is helpful? https://github.com/niklas-wortmann/ngx-pact

dsmileb
2021-07-26 16:06
has joined #pact-js

consulting
2021-07-26 16:12
Thanks for all your feedback Matt! If I can make this work, I'll try to contribute something in the form of a tutorial or a podcast :slightly_smiling_face:

hazel.wright
2021-07-26 19:04
has joined #pact-js

matt682
2021-07-27 01:32
has joined #pact-js

tjones
2021-07-27 04:55
`TestBed` will still work, although to be honest, I don't really know why you'd need it for a consumer test


tjones
2021-07-27 04:56
(it's not exactly angular, but nestjs uses a lot of patterns from angular, as I understand it)

tjones
2021-07-27 04:57
> If I can make this work, I'll try to contribute something in the form of a tutorial or a podcast :slightly_smiling_face: Yes please!! It would be awesome if we could have some angular examples in the `examples` folder. This is a common question, and I'm not really an angular person

tjones
2021-07-27 04:57
happy to help out if you need

dawoud.sheraz
2021-07-27 11:25
For the sake of update, axios mock adapter mocking was intervening with pact-js mocking. Once I tried without axios mock adapter, the pact mock server was hit by the client. Although now I am seeing network error/CORS issue. The pact logs now show the interaction has been hit, which was not happening previously.

matt.fellows
2021-07-27 11:45
You should be able to disable your HTTP client from sending CORS requests on non browser environments, pact also has a CORS flag you can enable to respond to cors requests

consulting
2021-07-27 12:42
Thanks Timothy! I'm not too worried about the TestBed... it's a nice to have. I've been busy in meeting most of my time yesterday, so I didn't progress much... :disappointed: It seems that Mocha has not made it's way into Angular's fan heart lol There are 1 or 2 decent ressource and they use Webpack, which I'm not familliar with. There seems to be more people using Jest than Mocha with Angular... I might try that way if I can't succeed with Mocha. Right now, when I try to run my pact test, it says that it "can't use import statement outside a module" (Angular side problem). Angular seems to need some form/part of DOM to be able to launch properly, which seems to be fixed using jsdom... that's my next target :slightly_smiling_face:

matt.fellows
2021-07-27 12:49
Yeah I think Jest is the hipster kid on the block, mocha was more the first popular node based one (after Jasmine, which is what Karma uses from memory)

matt.fellows
2021-07-27 12:51
sounds like you?re on the right track

consulting
2021-07-27 13:01
yes you are right, Karma uses Jasmine. I went straight to Mocha to save time (I thought lol) because I've used it with Node in the past.

consulting
2021-07-27 15:35
Almost there! I fix most of the issues... I'm stuck with mocha not being able to see my Angular service (custom dev, not internal). All other imports are working.

consulting
2021-07-27 15:37
I had those before when I was missing thirdparty dependencies... but now that it's a local service that I created, I'm mystified :slightly_smiling_face: So close!

nathan.derave
2021-07-27 16:34
Hey there ! I?m having some issues to figure out how to define the Pact specification of nested payloads. I?m not 100% clear of when to use `like` in conjunction with `eachLike` etc. Here is an example payload that should be legit: ```const expected = { id: 'cc812d76-b5af-4a1b-a7be-e63115e19bbd', recommendations: [{ is_external: false, list_position: 0, rankings: [{ brands: ['pzc', 'abcd'], image_url: 'https://something.com'}), followable: { followed: true, id: 'article_location_abcd', stats: { df: 12636.0, idf: 6.05343245, n_recent_articles: 59.0}, display_forms: [{ language: 'nl', text: 'Verinigd Koninkrijk'}, {...}]}, {...}]}, {...}] }``` Some observations about the example payload above: ? `recommendations` is a list of complex objects ? `rankings` as well (and is part of one `recommendation`) ? `display_forms` is also a list (and is part of one `ranking`) Hence, here is my Pact specification of the expected payload: ```const expected = { id: like('cc812d76-b5af-4a1b-a7be-e63115e19bbd'), recommendations: eachLike({ is_external: false, list_position: 0, rankings: eachLike({ brands: eachLike('pzc'), image_url: 'https://something.com'}), followable: { followed: true, id: 'article_location_abcd', stats: { df: 12636.0, idf: 6.05343245, n_recent_articles: 59.0}, display_forms: eachLike({ language: 'nl', text: 'Verinigd Koninkrijk'}) } }) }``` The problem is that, when I verify the Pact on the provider side, some errors are raised because there are more than 1 element in `rankings` or in `brands` .. I can?t really figure out what wrong in my way to use `eachLike`and `like` .. Here is below an extract of the error raised in the verification: ```Description of differences -------------------------------------- * Actual array is too long and should not contain "pzc" at $.recommendations[0].rankings[0].brands[1] * Actual array is too long and should not contain a Hash at $.recommendations[0].rankings[1]```

matt.fellows
2021-07-28 01:15
that looks like the right setup to me, could you please share the resulting pact file?

matt.fellows
2021-07-28 02:03
It might be my eyes, but it looks like you are running the project in `d:` , but the import is trying to find a file in `c:`

consulting
2021-07-28 02:06
wow

consulting
2021-07-28 02:07
I wanted to clean that up... it bit me in the a$$ before I was able to find time to do it :slightly_smiling_face: Thanks Matt, it's a great lead!

consulting
2021-07-28 02:08
In the mean time, I got desperate with Mocha, so I tried to move on to Jest... It turns out that I found an example that works with Angular, Pact and Jest! Tomorrow (I'm in Montreal, Quebec :slightly_smiling_face: ), I'll try to start a new project from scratch with Jest and see if I understood everything that's at stake! Interesting fact: with Jest, none of the problems faced with Mocha seems to be present (no need to use a shim to fake a DOM and fix zone.js, no ESM to load modules, ...)

matt.fellows
2021-07-28 02:14
I think Jest uses Jasmine under the hood (I may be wrong about that) so could explain some of those compatibilities

consulting
2021-07-28 03:09
unfortunately, the `c:` reference was indeed wrong BUT also an old capture (sorry, my bad)... I use relative path since the beginning and that was an attempt to figure out why "./weather.service" could not be loaded... I also tried using required() instead of import... thinking Mocha is meant for a Node world and it could help... but it didn't change anything.

consulting
2021-07-28 03:10
I'll focus on Jest tomorrow to be able to tackle the provider side and Pact Broker and have something to show at work :slightly_smiling_face:

vbhardwaj.eminent
2021-07-28 05:15
has joined #pact-js

nathan.derave
2021-07-28 07:13
Hey @matt.fellows! Thanks for having a look (and thanks for Pact generally speaking, it?s huge man). Here is the resulting Pact file (there are a bit more stuffs in there as I defined other interactions and there are other fields as well): ```{ "consumer": { "name": "Recommendations Gateway" }, "interactions": [ { "description": "Fetch recommendations", "providerStates": [ { "name": "Has recommendations" } ], "request": { "headers": { "content-type": "application/json", "x-api-key": "asdf" }, "matchingRules": { "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "/api/recommendations/.+" } ] } }, "method": "GET", "path": "/api/recommendations/asdf" }, "response": { "body": { "context_id": "cc812d76-b5af-4a1b-a7be-e63115e19bbd", "recommendations": [ { "external_rankings": false, "followable": { "display_forms": [ { "language": "nl", "text": "Verinigd Koninkrijk" } ], "followed": true, "id": "article_location_verenigd-koninkrijk", "source": "article", "stats": { "df": 12636, "idf": 6.05343245, "n_recent_articles": 59 }, "type": "location", "value": "verenigd-koninkrijk" }, "list_position": 0, "rankings": [ { "brands": [ "pzc" ], "image_url": "https://cdn.businessinsider.nl/wp-content/uploads/2021/02/602f006e97cf0.png", "item_url": "https://cdn.businessinsider.nl/wp-content/uploads/2021/02/602f006e97cf0.png", "list_position": 2, "publication_date": "2021-05-27T06:50:54.835Z", "short_id": "edd20ce", "suggested_brand": "ad", "title": "Kijktips voor de donderdagavond", "type": "article" } ] } ] }, "headers": { "content-type": "application/json" }, "matchingRules": { "body": { "$": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*[*].followable.display_forms": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*[*].rankings": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.*[*].rankings[*].brands": { "combine": "AND", "matchers": [ { "match": "type" } ] } } }, "status": 200 } }, { "description": "Fetch recommendations", "providerStates": [ { "name": "Something went horribly wrong" } ], "request": { "headers": { "content-type": "application/json", "x-api-key": "asdf" }, "matchingRules": { "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "/api/recommendations/.+" } ] } }, "method": "GET", "path": "/api/recommendations/asdf" }, "response": { "status": 503 } }, { "description": "Fetch recommendations", "providerStates": [ { "name": "recommendations not found" } ], "request": { "headers": { "content-type": "application/json", "x-api-key": "asdf" }, "matchingRules": { "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "/api/recommendations/.+" } ] } }, "method": "GET", "path": "/api/recommendations/asdf" }, "response": { "status": 404 } } ], "metadata": { "pactJs": { "opts:port": "6234", "version": "10.0.0-beta.44" }, "pactRust": { "version": "0.9.4" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "Guide Ranker" } }```

matt.fellows
2021-07-28 07:15
Thanks for the kind words :pray:

matt.fellows
2021-07-28 07:16
Is the consumer and provider both Pact JS?

matt.fellows
2021-07-28 07:16
It looks like the consumer is being produced by the new beta interface (produces a v3 pact file), but the provider is being verified by the old one, which only supports v2 pacts.

matt.fellows
2021-07-28 07:17
One option is to set the spec version to 2 (i don?t think that?s currently supported, but is easy to add and can do that for you quickly)

matt.fellows
2021-07-28 07:17
if the provider is also Pact JS, you just need to verify it with the v3 interface too

miguel.panelo
2021-07-28 07:29
has joined #pact-js

nathan.derave
2021-07-28 07:37
Aaah yes okay that?s true indeed. Consumer is JS and Provider is verified with Python. That definitely must be it. Now is see in the first lines of the https://github.com/pact-foundation/pact-python docs that it currently supports v2 specs only.

nathan.derave
2021-07-28 07:40
So I guess we can either tweak the consumer spec version generation (and that would require a PR for the ability to do it - thanks for proposing) OR I can switch my provider verification process to use the https://github.com/pact-foundation/pact-provider-verifier CLI. Is that correct ?

otaviio
2021-07-28 07:57
has joined #pact-js

matt.fellows
2021-07-28 09:21
Yep, I'd use the newer one which supports v3 though: https://docs.pact.io/implementation_guides/rust/pact_verifier_cli/

matt.fellows
2021-07-28 09:21
The other one is essentially what you're using now

matt.fellows
2021-07-28 09:21
Can you please raise a feature request on pact JS to be able to set the spec version?

matt.fellows
2021-07-28 09:22
I'll get to it this week

nathan.derave
2021-07-28 09:43
Cool I?ll make my verification to use the latest CLI Docker image ! Thanks for the support @matt.fellows. I?ll also open the feature request !


patrice.krakow
2021-07-28 10:00
has joined #pact-js

nathan.derave
2021-07-28 12:08
Running the verification with https://hub.docker.com/r/pactfoundation/pact-ref-verifier solved my issue !

david.simpson
2021-07-28 12:51
has joined #pact-js

e.alderson004
2021-07-28 17:17
has joined #pact-js

jdalessandro
2021-07-29 07:27
has joined #pact-js

eric.tang1
2021-07-29 16:22
has joined #pact-js

antklim
2021-07-29 22:25
has joined #pact-js

toffer.lim87
2021-07-30 03:51
has joined #pact-js

toffer.lim87
2021-07-30 03:59
Hello. I have a question regarding if Pactflow supports WebSocket APIs in API Gateway? The reason why I am asking is that, I been trying to Verify my Consumer contract and I am getting some error. I have a full AWS Credentials for our Service and have the correct config. I have tried using both localhost and a live api endpoint that my team is using. Also, we are using jest to run both Consumer and Provider pact test. If you can please point me to a documentation that would be awesome. Thank you! ```Error making request - SocketError getaddrinfo: nodename nor servname provided, or not know , attempt 1 of 3 ..... .....```

matt.fellows
2021-07-30 04:46
It doesn't support websockets

matt.fellows
2021-07-30 04:46
Is this a consumer or provider test?

matt.fellows
2021-07-30 04:47
I should say, it doesn't communicating over websockets, but you can test a websockets integration using message pact

tjones
2021-07-30 05:31
This looks like a configuration error that is unrelated to Pact. If you can share your code, we can check to see if it's a Pact problem.

aphronio
2021-07-30 13:42
has joined #pact-js

toffer.lim87
2021-07-30 18:13
Sorry. I cannot share any code because its the property of the company.

toffer.lim87
2021-07-30 18:34
And that is for the Provider Test. Thank you for the answers. =)

matt.fellows
2021-07-30 22:44
How about you make an example that shows the problem without showing your code?

matt.fellows
2021-07-30 22:44
It's hard to give advice without detail

matt.fellows
2021-07-30 23:10
The exception shows you haven't given a valid provider address to the verifier and/or it doesn't know how to communicate to the provider

fabio882
2021-08-01 19:31
has joined #pact-js

mike.key
2021-08-02 03:01
has joined #pact-js

eddie
2021-08-02 04:08
has joined #pact-js

michel.neufeglise
2021-08-02 12:57
Hi. Did anyone else also encounter a ruby binary error on windows, it is saying that GEM_HOME and GEM_PATH can not be found but there is a ruby 2.6.0 installation with those paths present on the windows machine

tjones
2021-08-02 22:11
Hmm. Can you post the exact error?

tjones
2021-08-02 22:12
It could be the long path issue - Ruby on windows isn't able to read paths longer than around 260 characters (even in windows 10 where long path support is native)

tjones
2021-08-02 22:13
You can test this by moving the project to a very short path

tjones
2021-08-02 22:14
Which version of pact-node do you have? (it will be in the logs, or you can get it with `npm ls @pact-foundation/pact-node`)

matt.fellows
2021-08-02 22:23
You don?t need Ruby on the machine for it to work Michel

matt.fellows
2021-08-02 22:26
Might be worth checknig if you have any other Ruby env vars about, and removing them

matt.fellows
2021-08-02 22:26
removing the bundler cache dir (`rm -rf ~.bundle` ) fixed it for another user

consulting
2021-08-03 15:16
Here's the tutorial on youtube that helped me figuring it out for the Angular side: https://www.youtube.com/watch?v=OZz7UyHnyKg

matt.fellows
2021-08-04 01:12
Thanks for sharing, just added to our docs site (will take 10 mins or so to update)

consulting
2021-08-04 03:57
I just started from scratch to have something as clean as possible. For the ui, I used Angular'S Tour of Heroes tutorial as a clean base. Comparing with that tutorial, other than using Jest, the notable change that needs to be made to a vanilla Angular project is setting these properties to *true* in *tsconfig.spec.json* *"emitDecoratorMetadata": true,* *"experimentalDecorators": true*

consulting
2021-08-04 03:57
Also, changing these didn't apply until a restart of the server... which made it harder for me to pin point :slightly_smiling_face:

matt.fellows
2021-08-04 04:00
The more angular examples/resources the better. Perhaps we should add a basic one on the JS repo or elsewhere once we have a working one

consulting
2021-08-04 04:02
I'm almost done with mine... I can share it to you in Github once it's "decent". Could serve as is or as a base to some other examples you guys would want to create

consulting
2021-08-04 04:03
Thanks again for your support Matt! It felt great knowing I could bounce ideas with you when things got a bit rough :smile:

matt.fellows
2021-08-04 04:09
you?re welcome!

tylerkron
2021-08-04 14:02
has joined #pact-js

thanuxxxx
2021-08-04 17:41
Question about `Matchers` I have a response like this ```"categories": { "additionalProp1": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp2": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp3": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 } }``` so `additionalPropX` is repeating (at least one or more). Do we have any method like `eachLike`


thanuxxxx
2021-08-05 01:17
Do pact V3 support with PactWithJest?


thanuxxxx
2021-08-05 01:23
Cool thank you!!

marvin.kienitz
2021-08-05 07:20
has joined #pact-js

danieljak
2021-08-05 10:09
has joined #pact-js

consulting
2021-08-05 12:59
Hi Matt, Now that I'm testing the provider, I see some differences on the body structure pertaining to matchers. Here's my response: ```"response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::SomethingLike", "contents": [ { "id": 1, "name": "Superman" }, { "id": 2, "name": "Batman" }, { "id": 3, "name": "Ironman" } ] } }``` As you can see, in my case, the matcher information it stuffed inside the body of the response. When I compare my contract with the one generated by the tutorial I shared with you earlier in this conversation, it's looking much closer to what is shown during your part 3 video (pactflow youtube channel): ```"response": { "status": 200, "headers": { }, "body": [ { "id": "1", "make": "Tesla", "model": "S" }, { "id": "2", "make": "BMW", "model": "3Series" } ], "matchingRules": { "$.body": { "match": "type" } } }``` Having this information in the body is messing up with my provider contract test (I feel that attribute "json_class" and "content" should be outside of "body"). Any idea why I get this structure in my contract? (version maybe?) Interesting fact: even though I copied the package.json file from the tutorial, I get slightly different versions in package.lock.json for pact (me:9.16.0, tutorial:9.14.0) and pact-node (me:10.13.1, tutorial: 10.11.1)

matt.fellows
2021-08-05 13:02
I?ve seen that problem before, one moment


matt.fellows
2021-08-05 13:03
It?s one of those ?intermittent? problems, but should be solved in the latest version

univ.anirudh
2021-08-05 13:22
has joined #pact-js

univ.anirudh
2021-08-05 13:28
Hi, I've been trying to understand the scope of the provider implementation of a pact test. https://docs.pact.io/consumer/contract_tests_not_functional_tests according to the last point in this, whether the provider does the "right" thing with the request should be left to the provider's functional tests. What I understand from this is, we would ignore (or mock) out the layer beyond the handler/validator function for a pact. So no db/networking interaction. Is that the correct way to think about it?

thanuxxxx
2021-08-05 15:51
I am getting *Error* `No value provided for required options '--pact-helper'` after switching to `jest-pact/v3` any idea?

thanuxxxx
2021-08-05 15:54
Even just copied/pasted this example code .. ```import { pactWith } from 'jest-pact/v3'; import { MatchersV3 } from '@pact-foundation/pact/v3'; import api from 'yourCode'; pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, (interaction) => { interaction('A request for API health', ({ provider, execute }) => { beforeEach(() => provider .given('Server is healthy') .uponReceiving('A request for API health') .withRequest({ method: 'GET', path: '/health', }) .willRespondWith({ status: 200, body: { status: MatchersV3.like('up'), }, }), ); execute('some api call', (mockserver) => api(mockserver.url) .health() .then((health) => { expect(health).toEqual('up'); }), ); }); });```

james.perepiczka
2021-08-05 16:29
has joined #pact-js

j3rry.wan9
2021-08-05 21:44
has joined #pact-js

tjones
2021-08-05 23:05
Which versions are you uising?

thanuxxxx
2021-08-05 23:40
npm i -D @pact-foundation/pact@10.0.0-beta.16 jest-pact@0.9.0-beta.v3

thanuxxxx
2021-08-06 01:19
I copied from pact docs


sadikshahidain
2021-08-06 02:14
has joined #pact-js

consulting
2021-08-06 12:49
I tried with the latest version and I still have the same problem. I also tried to use 99% of the package.json file from the tutorial, expecting to get the same result as them, but didn't work either.

consulting
2021-08-06 12:49
I cleared npm cache just in case before doing any of those attempts

consulting
2021-08-06 12:57
did the same process of cleaning cache and re-installing everything with the tutorial and it still works

consulting
2021-08-06 12:57
both end up using "_id": "@greet_bot/pact@9.16.0",

matt.fellows
2021-08-06 12:58
That?s just Bizarre.

consulting
2021-08-06 12:58
yup

matt.fellows
2021-08-06 12:58
have you cleared the previous pact file out beforehand? (just thinking of things we can do here()

matt.fellows
2021-08-06 12:58
also, Windows/OSX/Linux?

consulting
2021-08-06 12:58
I'll try to compare everything in their config files (again) maybe I missed something

consulting
2021-08-06 12:59
windows 10

consulting
2021-08-06 12:59
by clearing the pact file, you mean deleting the contract generated? yes

consulting
2021-08-06 13:00
and I notice that this problem is also visible in the logs: ```I, [2021-08-06T08:47:30.499567 #25560] INFO -- : Registered expected interaction GET /heroes D, [2021-08-06T08:47:30.500567 #25560] DEBUG -- : { "description": "a request to get all the heroes", "providerState": "heroes exist", "request": { "method": "GET", "path": "/heroes" }, "response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::SomethingLike", "contents": [ { "id": 1, "name": "Superman" }, { "id": 2, "name": "Batman" }, { "id": 3, "name": "Ironman" } ] } }, "metadata": null } I, [2021-08-06T08:47:30.546849 #25560] INFO -- : Received request GET /heroes```

matt.fellows
2021-08-06 13:01
hmm thanks. The log I think always shows it that way (I maybe wrong abotu that though)

matt.fellows
2021-08-06 13:07
If you could possibly create a repo that we can use to reproduce the problem, we can definitely look into it

consulting
2021-08-06 13:12
I'll give it one more try... if I'm not successful, I'll take your invitation :slightly_smiling_face:

matt.fellows
2021-08-06 13:13
Thanks. I feel your frustration!

consulting
2021-08-06 13:16
I'm alright :slightly_smiling_face: no worries! I just can't wait to be able to make it work from both consumer and provider side AND have the broker working as well. The sad thing is that I have to do this on my spare time, which is pretty thin lately :disappointed:

consulting
2021-08-06 13:59
(just keeoing notes here so you know what I did so far in case yuou finally end up looking at it :slightly_smiling_face: )

consulting
2021-08-06 14:00
I deleted all the files from the tutorial folder except the node_moduels folder. Copied my files in that tutorial folder. Ran ng Serve to compile things and then ng test to generate a new contract. Result: same.

consulting
2021-08-06 14:00
Last thing I want to compare is how I build my interactions...

consulting
2021-08-06 14:19
Interactions are exactly the same. Ok, I'll take your proposal :slightly_smiling_face:

consulting
2021-08-06 14:19
I officially need help :relaxed:


univ.anirudh
2021-08-06 15:00
Bump on this, any help would be highly appreciated

thanuxxxx
2021-08-06 15:39
It works with `"@pact-foundation/pact": "10.0.0-beta.17"`

consulting
2021-08-06 16:44
I FOUND IT!!!!!!!!!!!!!!!!!!

consulting
2021-08-06 16:46
I was trying to produce different versions of the contract... so when I changed from spec:1 to spec:2, the structure of the contract was as expected (without the "json_class" and "content" extra key and WITH the matchingRules key!)

consulting
2021-08-06 16:49
looking back at the tutorial, they are using spec:3, which explains why it was working for them.

consulting
2021-08-06 16:50
here's the conclusion. When instantiating a new Pact : ? Without "spec" option, generated contract will be ok ? With "spec" option greater than 1 and smaller than 10, generated contract will be ok ? With "spec" *starting* with 1 (1, 10-19, 100-199, etc), generated contract will be malformed

consulting
2021-08-06 17:05
Note also that in the generated contract, the version number doesn`t reflect the value passed when instantiating the new Pact, having the spec starting with 1. In other words, for 1, 11, 14, 129, etc... you will have this version number appearing: ```, "metadata": { "pactSpecification": { "version": "1.0.0" } }```

consulting
2021-08-06 17:05
and it's defaulted to "2" when no spec is provided.

consulting
2021-08-06 17:06
that's it men! hope this helps! I'll just use spec:2 to be able to move forward!

ganginenik
2021-08-06 18:14
has joined #pact-js

matt.fellows
2021-08-06 22:08
We did an AMA on this that might be helpful https://docs.pact.io/help/amas/#north-america-2

matt.fellows
2021-08-06 22:09
I usually mock out 3rd party systems, but not code within the provider unless it's more convenient

matt.fellows
2021-08-06 22:09
Its not that you can't do functional testing as a side effect, it's just not Pact's primary goal

matt.fellows
2021-08-06 22:21
oh my goodness!

matt.fellows
2021-08-06 22:21
We should just prevent other versions from being specified there

matt.fellows
2021-08-06 22:22
`spec: 1` is old now, and pretty much noone would be using that

matt.fellows
2021-08-06 22:23
`spec: 3` using the current version of JS would also have no effect

matt.fellows
2021-08-06 22:23
so you?re right, `2` is where it?s at (you?re not using the new beta)

consulting
2021-08-07 00:50
I thought it was meant for the users to specify their version of the contract

consulting
2021-08-07 00:50
now I get it, thanks!

consulting
2021-08-07 00:56
lol "spec" would have been a bad name for what I thought it was meant... I should have understood earlier :relaxed: I notice that the effect of that value is undeniable at the end of the generated contract ```"metadata": { "pactSpecification": { "version": "2.0.0" } }```

consulting
2021-08-07 01:16
I'm all good now! I created an account of Pactflow, published consumer and provider, everything works! I just need to add another consumer for the same provider to make things a bit more interesting, clean everything up and I'll be good for my demo :)

matt.fellows
2021-08-07 01:48
Awesome to hear Pascal, thanks for that persistance

matt.fellows
2021-08-07 01:49
FYI I also updated https://github.com/pact-foundation/pact-js/issues/719 as a result of this thread

univ.anirudh
2021-08-07 06:33
So, for example, if I was testing a contract that required pre-existing data, the correct way to do it would be to set up the state required (insert records in db etc), run the contract test (which would trigger validations etc throughout the flow) but not verify whether the correct side effects occurred?

tjones
2021-08-07 11:39
There's no one correct way to do this, as such

tjones
2021-08-07 11:39
A lot depends on how your architecture is

tjones
2021-08-07 11:40
For example, I prefer to mock the repository layer in your service, since that's typically expressed in business language

tjones
2021-08-07 11:40
So, you can say `"when user with Id 1 exists -> getUser(1) will return (<some specific business object>)"`

tjones
2021-08-07 11:41
I find that more convenient than describing it in terms of insert statements etc

tjones
2021-08-07 11:42
Can you try with a more recent version?

thanuxxxx
2021-08-07 16:42
works with this version "@greet_bot/pact": "10.0.0-beta.44", I think I also had to clean node_module.

tjones
2021-08-08 13:08
Possibly a broken version. I'll update the documentation.

tjones
2021-08-08 13:12
Thanks for letting us know!

tjones
2021-08-08 13:13
There's nothing in the specific version from the documentation. jest-pact will work with any version of the beta pact-js branch.

tjones
2021-08-08 13:13
(I suspect the problem in this case was to do with that version of the beta branch, not jest-pact)

brentbarker9
2021-08-09 19:01
Hi, question: I'm having this issue: https://github.com/pact-foundation/karma-pact/pull/21/commits/f7a565dbe5789da7618ad80450fff213d8066ccd but the last karma-pact version was published in 2019. (https://www.npmjs.com/package/@pact-foundation/karma-pact) how can I get the latest version with that fix?

brentbarker9
2021-08-09 19:02
Of course after I ask the question I see that it is tagged with v2.3.1

brentbarker9
2021-08-09 19:02
hmm

brentbarker9
2021-08-09 19:09
```[2021-08-09 19:06:54.195 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Starting pact binary 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service', with arguments [service --port 3160 --consumer angular-project --provider edie --log-level DEBUG --log /home/dev/ui/angular-project/pacts/stubserver-integration.log --pact_dir /home/dev/ui/angular-project/pacts --host localhost --pact-file-write-mode overwrite] [2021-08-09 19:06:54.208 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Created 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service' process with PID: 1933 09 08 2021 13:06:54.220:ERROR [karma-server]: Server start failed on port 9876: Error: connect ECONNREFUSED 127.0.0.1:3160 [2021-08-09 19:06:58.933 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] INFO WEBrick::HTTPServer#start: pid=1933 port=3160 [2021-08-09 19:06:54.195 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Starting pact binary 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service', with arguments [service --port 3160 --consumer angular-project --provider edie --log-level DEBUG --log /home/dev/ui/angular-project/pacts/stubserver-integration.log --pact_dir /home/dev/ui/angular-project/pacts --host localhost --pact-file-write-mode overwrite] [2021-08-09 19:06:54.208 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: Created 'standalone/linux-x64-1.88.61/pact/bin/pact-mock-service' process with PID: 1933 09 08 2021 13:06:54.220:ERROR [karma-server]: Server start failed on port 9876: Error: connect ECONNREFUSED 127.0.0.1:3160 [2021-08-09 19:06:58.933 +0000] DEBUG (1738 on laptop): pact-node@10.13.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] INFO WEBrick::HTTPServer#start: pid=1933 port=3160``` this is the error I get with node 12.11, it works with node 12.10

leonardo.viana
2021-08-09 20:02
Hi all. I?m using the latest version of pact-js v3 beta (10.0.0-beta.44) to write our provider tests and I?m having a little issue. All the tests run and pass, and the results are even successfully published to the broker, but at the very end we get the crash below, which has pact-foundation/pact/native/index.node in one of the paths (we are running tests with jasmine on nodejs 10): ```FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope 1: 0x8dbaa0 node::Abort() [node] 2: 0x8dbaec [node] 3: 0xad81ba v8::Utils::ReportApiFailure(char const*, char const*) [node] 4: 0xe95d67 v8::internal::HandleScope::Extend(v8::internal::Isolate*) [node] 5: 0xaecbfc v8::Isolate::GetCurrentContext() [node] 6: 0x8a8665 node::EmitAsyncDestroy(v8::Isolate*, node::async_context) [node] 7: 0x7f91b2d826e2 [/git/pnr-policy/node_modules/@pact-foundation/pact/native/index.node] 8: 0xa43fc5 [node] 9: 0xa4833f [node] 10: 0xa59028 [node] 11: 0xa48c7b uv_run [node] 12: 0x8e6255 node::Start(v8::Isolate*, node::IsolateData*, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&) [node] 13: 0x8e44a2 node::Start(int, char**) [node] 14: 0x7f91ba3a9f45 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6] 15: 0x89ed45 [node] Aborted (core dumped) ``` Could this be a bug in the pact native library?

george.south
2021-08-09 21:51
@george.south has left the channel

uglyog
2021-08-09 23:00
No, that looks like a V8 issue when shutting down

brentbarker9
2021-08-09 23:51
`@pact-foundation/pact-node@10.12.2` works just fine

brentbarker9
2021-08-09 23:51
All other js libs are latest for me

brentbarker9
2021-08-09 23:51
```npm install --save-dev @pact-foundation/pact-web@latest @pact-foundation/pact-node@10.12.2 @pact-foundation/karma-pact@latest @pact-foundation/pact@latest```

xiaoyewang
2021-08-10 01:13
has joined #pact-js

tjones
2021-08-10 01:16
V8 doesn't normally have issues, though. Are we (or neon) maybe not cleaning up something?

uglyog
2021-08-10 01:19
Possibly. It looks like an async destroy is not running correctly

mfellows_admin
2021-08-10 02:52
has joined #pact-js

tjones
2021-08-10 05:37
@leonardo.viana: Nodejs 10 has passed EOL - do you still get this error with a Maintenance (12) or Active LTS (14) version?

tjones
2021-08-10 05:38
Also, if you're able to reproduce this in a repo we can take a look and make sure it's not us.

tjones
2021-08-10 05:42
Ah, are you asking for a release of karma-pact? We can certainly do this. The reason it wasn't released before is that package hasn't been migrated to github actions, and travis no longer runs our build pipelines.

tjones
2021-08-10 05:43
However, we're considering dropping support for pact-web and karma-pact - if this is something you need, I'd love your thoughts here: https://github.com/pact-foundation/pact-js/issues/626

tjones
2021-08-10 05:44
I will try to manually release karma-pact tonight

vbhardwaj.eminent
2021-08-10 06:56
Hi, Reaching out to know your thoughts on the approach which I am planning to follow on consumer side:   1. Test and publish pact using MSW mock 2. Use swagger mock validator to validate the mocks 3. Deploy to test/prod   My thinking behind this is that it will give faster feedback and release to test/prod. Whereas, the other approach where I am suppose to call the provider to validate the contract will be slower.


matt.fellows
2021-08-10 06:59
also, how are you goinng to validate your swagger is compatible with your API?

matt.fellows
2021-08-10 06:59
but yes, that?s doable

vbhardwaj.eminent
2021-08-10 07:05
thanks for suggesting msw-pact, I will have a look

tjones
2021-08-10 07:06
This looks awesome, @yousafn!!

matt.fellows
2021-08-10 07:13
How are you planning on managing the contracts?

vbhardwaj.eminent
2021-08-10 07:19
through versions

vbhardwaj.eminent
2021-08-10 07:19
I have done the implementation of swagger on service which automatically generates the `swagger-ui/index.html#`, which I assume will be correct.

vbhardwaj.eminent
2021-08-10 07:21
i can get the json from swagger

tjones
2021-08-10 07:43
Just be careful with swagger-mock-validator as at best it can give you a "maybe" rather than a "yes" for compatibility


qingyuliu
2021-08-10 09:27
has joined #pact-js

leonardo.viana
2021-08-10 15:14
I forgot to mention yesterday, but the issue disappeared after I upgraded nodejs from 10.14.0 to 10.24.1.

brentbarker9
2021-08-10 16:49
Sorry I believe the problem is in pact-node, not karma-pact after investigating the problem further. We are actively using karma-pact though

dhairyapatel071996
2021-08-10 20:06
has joined #pact-js

beem132
2021-08-10 21:21
has joined #pact-js

rfang
2021-08-11 00:49
has joined #pact-js

tjones
2021-08-11 01:26
Ok. Can you try an earlier version of pact-node?

tjones
2021-08-11 04:49
:man-shrugging: Maybe it was a V8 issue after all

tjones
2021-08-11 04:51
It might also be an issue with neon (which we use for the bindings where the issue was), because you're using an outdated version of node. Neon supports "the latest Node version and all LTS releases"

vbhardwaj.eminent
2021-08-11 07:09
very interesting conversation @tjones, I read it once, very deep and technical. I will have to go through it few more times to understand it completely. But according to me the jest of it is that one should understand clearly the trade offs with swagger mock validator. Thanks for sharing!

subhashnarla
2021-08-11 07:29
has joined #pact-js

tjones
2021-08-11 09:40
That's exactly right.

jkdihenkar
2021-08-11 10:43
has joined #pact-js

christian.kampka
2021-08-11 10:51
has joined #pact-js

ashwinparthasarathy30
2021-08-11 11:23
has joined #pact-js

andrew.jensen
2021-08-11 16:18
has joined #pact-js

pedroefajardo_pactio
2021-08-11 16:49
@andrew.jensen

tjones
2021-08-11 22:51
Thinking about this some more, I?m curious to know where the two endpoints understanding came from- I believe we only have one state handler endpoint, so perhaps we need to update some of the documentation

vivekkurhe1993
2021-08-12 03:44
has joined #pact-js

vbhardwaj.eminent
2021-08-12 05:00
Hi, How can I send the path variable while writing the Pact interactions so that I can read them on the provider side? My consumer is in React-JS-Jest and provider in springboot and java. I know in java I will receive the params in `(Map<String, Object> params)` but as of now it is coming as empty. My consumer side pact interaction looks like this

matt.fellows
2021-08-12 05:10
Normally you would just setup a provider state so that you can deal with (what I assume is the ID): `18297`

matt.fellows
2021-08-12 05:11
The current main version of PactJS doesn?t have that capability though, you need to use the beta (see this example: https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/provider-state-injected)

matt.fellows
2021-08-12 05:11
IMO it?s a bit of a code-smell, so you should question if you really need to use it before you do

vbhardwaj.eminent
2021-08-12 05:19
my provider is consumed by both web and mob, if I can get the path variables from pact broker and in provider I can use `(Map<String, Object> params)`, then I would not need to hard code on provider side. As of now I am hard coding on provider side - `this.xxxxxx.xxxxxxxxComponentByCategoryId("WEB", 18297L);` My intention is to achieve this on provider side `@State(value = "ccccccccc", action = StateChangeAction.SETUP)` `public void retrieveDSL(Map<String, Object> params) {` `this.xxxxxx.xxxxxxxxComponentByCategoryId((String)params.get("client"), ((Number)params.get("categoryId")).longValue());` `}`

matt.fellows
2021-08-12 05:20
the example I shared above answers this

matt.fellows
2021-08-12 05:20
it?s only available in the new beta package though

vbhardwaj.eminent
2021-08-12 05:22
I am bit reluctant to go for beta

matt.fellows
2021-08-12 05:27
:man-shrugging:

matt.fellows
2021-08-12 05:27
We?re working to get it out of beta, but that will take some time

vbhardwaj.eminent
2021-08-12 05:27
that means provider has to hard code the arguments until we get v3 for consumer (in case I am not ready for beta)

matt.fellows
2021-08-12 05:27
that?s what provider states are for anyway

vbhardwaj.eminent
2021-08-12 05:29
are you suggesting that one should not use (Map<String, Object> params), instead hard code it so that the test data is loosely coupled

matt.fellows
2021-08-12 05:30
I?m just saying that?s how you do it without injecting provider state values (which is what you?re asking about)

matt.fellows
2021-08-12 05:30
we just call them provider states ?given that resource with ID 12345 exists? is the state, your state handler makes sure that resource exists or the stub is setup etc.

vbhardwaj.eminent
2021-08-12 05:38
I think I got your point, with Pact we are not targeting to assert exact values. The moment we start focusing on exact match of values the test will become brittle and will not be manageable. As long as data type and field name are matched, consumer and provider should be happy, pact will be successful.

matt.fellows
2021-08-12 05:38
that general point is indeed correct

matt.fellows
2021-08-12 05:39
but you have identified one of the scenarios where exact values matter - in this case, on the provider side the test _will_ need to send a request to path `/xxxxxx/18297` so the state handler must know how to prep that

vbhardwaj.eminent
2021-08-12 05:41
I have learnt this after today's discussion, now I will use matcher to be flexible on the path variables

matt.fellows
2021-08-12 05:42
The matcher only works on the consumer side though, not the provider side

matt.fellows
2021-08-12 05:42
(matchers on the request only apply to the consumer, matchers on the response only apply to the provider)

vbhardwaj.eminent
2021-08-12 05:43
thankfully I got that point after playing alot with your pact Js workshop

matt.fellows
2021-08-12 05:43
great!

vbhardwaj.eminent
2021-08-12 05:43
ahh, finally I have started speaking your Pact language:grinning:

vbhardwaj.eminent
2021-08-12 05:43
I am feeling happy

matt.fellows
2021-08-12 05:43
:rolling_on_the_floor_laughing:

aakbar
2021-08-12 06:05
has joined #pact-js

tm.buga
2021-08-12 08:55
has joined #pact-js

yanivhad
2021-08-12 08:58
has joined #pact-js

francois.fernandes
2021-08-12 11:55
has joined #pact-js

christian.kampka
2021-08-12 13:04
I have a question about how to construct the path attribute of the provider interaction. The api sais it can be either a string or a MatcherResult, but it is obviously not as simple as `/product/${Matchers.like(5)}` Can anyone offer some guidance on this?

matt.fellows
2021-08-12 13:06
It?s rare you need a matcher on the request path, can you not control which path your unit test is sending the request to?

christian.kampka
2021-08-12 13:08
No, I can control it well. Maybe I missunderstood the purpose of the matchers. My understanding is that a matcher is used so that consumer and producer do not need to "match" on the excat value that is matched but only the "type"

christian.kampka
2021-08-12 13:09
but now that I think about it, I see how that is useful for the response but using it for paths is actually hard to fathm

matt.fellows
2021-08-12 13:11
Yeah, as soon as you stop to think about it you realise it only helps the consumer unit test, so most times not needed

matt.fellows
2021-08-12 13:12
the request to the provider can?t have a matcher, it needs to be a real one (there is a feature to inject a provider state value there, but that?s a separate thing altogether)

christian.kampka
2021-08-12 13:17
So if I understand it correctly, if I use `body: Matchers.like({foo: 1, bar: 2})` the producer has to fulfull the structure of the object, eg. `{foo: 2, bar: 3}` would match while `{foo: 2, bar: "adsf"}` would not, correct?

christian.kampka
2021-08-12 13:18
if so, is that check "deep", eg. does it match nested objects ?

christian.kampka
2021-08-12 13:24
OR - would I actually have to specify every very concretely, eh: `{foo: http://Matchers.int(1), bar: http://Matchers.int(2)}` ?

matt.fellows
2021-08-12 13:25
no, the matcher cascades

matt.fellows
2021-08-12 13:25
it will cascade until you stop it, by using a different matcher

matt.fellows
2021-08-12 13:26
even if the property value is an array, it now expects an array of objects that have the same structure

christian.kampka
2021-08-12 13:27
maybe I am missing something, but it sounds like `body: Matchers.like(expectedObject)` is what I want in the majority of all cases

tjones
2021-08-12 13:39
Yes, this is correct

tjones
2021-08-12 13:39
(but not always)

christian.kampka
2021-08-12 13:40
As always :smile:

tjones
2021-08-12 13:40
examples include where you need specific strings, like: ```{ type: "some_string_you_switch_on" otherProperty: Matchers.like(...) }```

christian.kampka
2021-08-12 13:40
thanks, guys, much apprechiated

tjones
2021-08-12 13:42
or where you want to have eg dates

tjones
2021-08-12 13:43
while we're on the topic, I don't think this is well documented, but we also have `Matchers.extractPayload()`, in case you want to strip the matchers off an example

tjones
2021-08-12 13:45
this is handy for the case where the object you get out of the client is the same as the json payload. ```const body = Matchers.like(/*whatever */); .... setup interaction using body it("returns the expected payload", () = { expect(yourApi.someCall()).toEqual(Matchers.extractPayload(body)); })```

christian.kampka
2021-08-12 13:45
that one I already found :slightly_smiling_face:

tjones
2021-08-12 13:46
awesome. I want to tidy up the docs so people don't have to use the source

christian.kampka
2021-08-12 13:47
something like this probably won't work, right? ```{ ...Matchers.like(fullObject), type: "some_string_you_switch_on" }```

christian.kampka
2021-08-12 13:49
I mean it works on the unit test level, but the pact matching rules don't seem to grasp it


tjones
2021-08-12 13:49
I think that won't work

tjones
2021-08-12 13:49
but that's a really nice example.

tjones
2021-08-12 13:49
I wonder if we can make a DSL to improve that case

tjones
2021-08-12 13:50
sorry, let me be more specific - that won't work.

tjones
2021-08-12 13:52
You can do this though: ```Matchers.like({ ...fullObject, type: Matchers.term({ generate: "some_string_you_switch_on", matcher: "some_string_you_switch_on"}) })```

tjones
2021-08-12 13:52
with the caveat that `matcher` is a regex, so you might have to escape some things in the string, depending.

tjones
2021-08-12 13:54
Maybe we could make that nicer with the following (unimplemented) examples: ```{ ...Matchers.likeEachProperty(fullObject), type: "some_string_you_switch_on" }``` and ```Matchers.like({ ...fullObject, type: Matchers.exactString("some_string_you_switch_on") })```

tjones
2021-08-12 13:54
Maybe `eachPropertyLike`

christian.kampka
2021-08-12 13:56
That would be really cool :slightly_smiling_face:


brentbarker9
2021-08-12 16:39
yep, the earlier versions of pact node work (`10.12.2` and lower). The breaking change was introduced in `10.13.0`

thanuxxxx
2021-08-12 19:40
@matt.fellows for this response ```"categories": { "additionalProp1": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp2": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 }, "additionalProp3": { "id": "string", "items": [ "string" ], "name": "string", "sortOrder": 0 } }``` I have something like this ``` categories: eachKeyLike('XXXXXXXXXXXXX', { id: string('XXXXXXXXXXXXX'), items: atLeastOneLike('FFFFFFF'), }),``` That will address one nested object but what about all of others? What about min, and max repeats

matt.fellows
2021-08-12 22:29
That function doesn?t have min/max like the others, but is ?at least one?

thanuxxxx
2021-08-12 22:40
Excellent!! Thank you :relaxed:

tjones
2021-08-13 00:33
Can you try `karma-pact@3.0.0` ?

tjones
2021-08-13 00:35
and `pact-node@10.13.3`

johnathan.gilday
2021-08-13 16:40
has joined #pact-js

leonardo.viana
2021-08-13 17:44
Hi all. Very quick question? One can specify which pacts the provider verifies via `consumerVersionSelectors`. However, if `consumerVersionSelectors` is *not* provided, which pact(s) are verified by default?

ben.kaiser
2021-08-13 17:47
has joined #pact-js

johnathan.gilday
2021-08-13 20:03
@johnathan.gilday has left the channel

dbekman
2021-08-13 20:51
has joined #pact-js

matt.fellows
2021-08-14 00:11
Depends on what other options are sent

matt.fellows
2021-08-14 00:12
It may just grab the latest pacts

matt.fellows
2021-08-14 00:12
The output in the verifier will tell you what it selected and why

leonardo.viana
2021-08-14 00:16
Latest pact for same branch as the provider branch?

matt.fellows
2021-08-14 00:18
No, latest pact for that consumer

matt.fellows
2021-08-14 00:18
What config are you sending? Is this a hypothetical question?

matt.fellows
2021-08-14 00:19
You almost certainly don't want to verify only latest

matt.fellows
2021-08-14 00:28
Check the test output tho, it will explain what pacts have been selected and why

chen
2021-08-15 09:34
has joined #pact-js

tom.willmott
2021-08-16 13:47
has joined #pact-js

franklin.lucena89
2021-08-16 16:52
has joined #pact-js

leonardo.viana
2021-08-16 19:55
Hi all. I?m seeing some interesting things regarding pact file creation in pact-js v3 beta and I?m wondering if it?s expected. I?ll describe the 2 cases I?m seeing: 1. Let?s say I have 2 consumer tests, and I?ve run them such that the pact file has already been generated locally with both interactions. Now, let?s say that I edit the `uponReceiving` string slightly in one of those tests and re-run them. It turns out that pact will actually add a *third* interaction with the updated `uponReceiving` string to the existing pact file. I was expecting pact to simply regenerate the pact (e.g. overwrite the existing file) with the `uponReceiving` string updated in the appropriate interaction (meaning, the pact file would still have 2 interactions, rather than 3). 2. Again, let?s say I have 2 consumer tests, and I?ve run them such that the pact file has already been generated locally with both interactions. Now, let?s say I change a boolean value in the request body of one of them from true to false, and re-run them. It turns out that pact will *not* regenerate the pact file, which will still have the old true value for the boolean. The common thread here seems to be that pact files may not be re-generated properly if they already exist. Should I file an issue for this?

matt.fellows
2021-08-16 22:42
you need to remove any pact files before running the pact tests

matt.fellows
2021-08-16 22:43
It?s not clear though, so an issue being raised would be great thanks

matt.fellows
2021-08-16 22:43
We may be able to address it, but at least, making it clearer for now would be ideal

uglyog
2021-08-16 22:52
Changing the `uponReceiving` changes the key of the interaction, so Pact will think it is a different interaction. A clean before the tests are run will fix this issue.

leonardo.viana
2021-08-16 23:14
I get it that removing pact files before running tests avoid these issues. Is there any value, though, in doing for example, what?s described in issue 2 above (namely *not* updating the existing pact file with the new body values)? I was just wondering why doesn?t Pact overwrite existing pact files automatically, or at least provide an option to do so. For example, in `PactV3Options` there could be a boolean field, called something like `overwrite` , which when set to `true` would automatically overwrite any existing pact file with the one generated by the current run.

matt.fellows
2021-08-16 23:15
yep, that?s an option. Can you please raise a request as per above? I think there are a few things we can do

uglyog
2021-08-16 23:20
The second one must be a defect.

uglyog
2021-08-16 23:22
By default, the option is to merge the test interaction into the pact file. The reason for this is some people like to split the the tests up into multiple separate tests. In this case, if overwrite was the default then the second interaction will always replace the first one.

abatan.k
2021-08-16 23:31
Hello all :slightly_smiling_face: When im testing my provider, Pact complain about a JSON string, Pact doesn't parse JSON before checking against my consumer contract ??

uglyog
2021-08-16 23:33
It uses the content type to determine how to parse the body


matt.fellows
2021-08-17 00:40
can you please elaborate more on the error you?re getting @abatan.k?

leonardo.viana
2021-08-17 01:30
@tjones, I saw your comment about `pactfileWriteMode` and it?s good to see that something like that exists. I do see it defined as part of the `PactOptions` interface: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/dsl/options.ts#L50 However, I do not see a similar option for the equivalent `PactV3Options` interface: https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/v3/pact.ts#L11 Is this something that will be added later?

matt.fellows
2021-08-17 01:56
That?s why we asked you to create the issue :slightly_smiling_face:

abatan.k
2021-08-17 02:25
@matt.fellows I got this error: ``` + "name": "Tether", + "symbol": "USDT" + } + }, + { + "id": "bcf198d0-7342-46d7-995f-e7886097fb9d", + "base": { + "id": "f33e7a5c-b38b-46de-b047-e4bc47366a8a", + "name": "0x", + "symbol": "ZRX" + }, + "quote": { + "id": "9a3a2bfb-522f-4d1c-a766-7eb62147fe80", + "name": "Tether", + "symbol": "USDT" + } + } + ] + } +] Description of differences -------------------------------------- * Expected a Hash but got a String ("[\n {\n \"id\": \"9b685255-2cb8-4f4a-8b41-4f231f78aabc\",\n \"name\": \"Binance\",\n \"pairs\": [\n {\n \"id\": \"42fd3c6e-bfce-429a-b76e-c2d00de68e5b\",\n \"base\": {\n \"id\": \"fe84d516-9336-46a4-a35f-b3e0e7f9140b\",\n \"name\": \"Bitcoin\",\n \"symbol\": \"BTC\"\n },\n \"quote\": {\n \"id\": \"9a3a2bfb-522f-4d1c-a766-7eb62147fe80\",\n \"name\": \"Tether\",\n \"symbol\": \"USDT\"\n }\n },\n {\n \"id\": \"2d50f549-07cb-4ca5-8f08-bf3b354c501a\",\n \"base\": {\n \"id\": \"4c49c19a-19b3-42b3-a031-cee8f07e84fa\",\n \"name\": \"Ethereum\",\n \"symbol\": \"ETH\"\n },\n \"quote\": {\n \"id\": \"9a3a2bfb-522f-4d1c-a766-7eb62147fe80\",\n \"name\": \"Tether\",\n \"symbol\": \"USDT\"\n }\n },\n {\n \"id\": \"2ebc0d2f-f647-4f13-a983-052aa81eea62\",\n \"base\": {\n \"id\": \"818185aa-d255-40f4-b41d-6291cdda0570\",\n \"name\": \"Bitcoin Cash\",\n \"symbol\": \"BCH\"\n },\n \"quote\": {\n \"id\": \"9a3a2bfb-522f-4d1c-a766-7eb62147fe8```

abatan.k
2021-08-17 02:25
I put juste a portion of it, but you can imagine the rest :slightly_smiling_face:

abatan.k
2021-08-17 02:30
I use Azure function, and in the docs, azure says that what im return from my azure function, is passed to `JSON.stringify` so i added the proper Headers to the response, bu i still get this error

abatan.k
2021-08-17 02:30
How can i make PACT use `JSON.parse` to do the comparison with my consumer contract ??

matt.fellows
2021-08-17 02:32
what does your pact file look like, can you pleaes share?

matt.fellows
2021-08-17 02:32
You probably need to add an expected `content-type` of `application/json` in the conumer test

abatan.k
2021-08-17 02:37
ok i didn't rebuild my typescript codebase sorry :sweat_smile:

abatan.k
2021-08-17 02:37
but now, i got this error `Expected a Hash but got a Array`

abatan.k
2021-08-17 02:37
Here is the body of my consumer test

abatan.k
2021-08-17 02:38
```body: Matchers.eachLike({ id: Matchers.uuid(), name: Matchers.string("Binance"), pairs: Matchers.eachLike({ id: Matchers.uuid(), base: Matchers.like({ id: Matchers.uuid(), name: Matchers.string("Bitcoin"), symbol: Matchers.string("BTC"), }), quote: Matchers.like({ id: Matchers.uuid(), name: Matchers.string("Ethereum"), symbol: Matchers.string("USDT"), }), }), }),```

abatan.k
2021-08-17 02:44
@matt.fellows it seems that my body is interpreted like a hash instead of an array, do you have an hint for this problem ?

abatan.k
2021-08-17 02:44
Im using Matchers.eachLike tho

matt.fellows
2021-08-17 02:45
can you please share the pact file

abatan.k
2021-08-17 02:46
@matt.fellows do you mean the JSON generated by PAct ?

abatan.k
2021-08-17 02:46
Here it is :slightly_smiling_face:

matt.fellows
2021-08-17 02:48
looks ok to me

matt.fellows
2021-08-17 02:48
what?s the verification failure look like now?

abatan.k
2021-08-17 02:50
``` + "name": "Zilliqa", + "symbol": "ZIL" + }, + "quote": { + "id": "9a3a2bfb-522f-4d1c-a766-7eb62147fe80", + "name": "Tether", + "symbol": "USDT" + } + }, + { + "id": "bcf198d0-7342-46d7-995f-e7886097fb9d", + "base": { + "id": "f33e7a5c-b38b-46de-b047-e4bc47366a8a", + "name": "0x", + "symbol": "ZRX" + }, + "quote": { + "id": "9a3a2bfb-522f-4d1c-a766-7eb62147fe80", + "name": "Tether", + "symbol": "USDT" + } + }, + ] + }, +] Description of differences -------------------------------------- * Expected a Hash but got an Array ([{"id"=>"9b685255-2cb8-4f4a-8b41-4f231f78aabc", "name"=>"Binance", "pairs"=>[{"id"=>"42fd3c6e-bfce-429a-b76e-c2d00de68e5b", "base"=>{"id"=>"fe84d516-9336-46a4-a35f-b3e0e7f9140b", "name"=>"Bitcoin", "symbol"=>"BTC"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"2d50f549-07cb-4ca5-8f08-bf3b354c501a", "base"=>{"id"=>"4c49c19a-19b3-42b3-a031-cee8f07e84fa", "name"=>"Ethereum", "symbol"=>"ETH"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"2ebc0d2f-f647-4f13-a983-052aa81eea62", "base"=>{"id"=>"818185aa-d255-40f4-b41d-6291cdda0570", "name"=>"Bitcoin Cash", "symbol"=>"BCH"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"0f27666f-3abb-4808-aa1c-f507a48cb6d8", "base"=>{"id"=>"441ba66a-8747-4885-9096-a143355d1945", "name"=>"XRP", "symbol"=>"XRP"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"ea995e47-9a08-44a9-9815-2ea0b88eace5", "base"=>{"id"=>"d7f4e0c4-8333-47b6-aa41-014e7665bc6e", "name"=>"EOS", "symbol"=>"EOS"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"6d53be8f-c002-43bc-b493-ebe65f858418", "base"=>{"id"=>"e8f71c79-be55-4ec2-a21c-2aee803185f1", "name"=>"Litecoin", "symbol"=>"LTC"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"d0bfbdd7-998e-45a1-bf5f-cf0f001d8147", "base"=>{"id"=>"83c930ae-0a1e-4de3-a4ef-133975e524fa", "name"=>"TRON", "symbol"=>"TRX"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"ca4b3fe8-8cd3-4289-afc5-45ebf300e89d", "base"=>{"id"=>"e39af3cc-9cfc-4070-86d2-568881cc51a0", "name"=>"Ethereum Classic", "symbol"=>"ETC"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"ff8c3828-cc72-41f7-b5cd-89e7f00ca0d3", "base"=>{"id"=>"a7999fef-d03b-4ff8-a385-991bd9d3dc35", "name"=>"Chainlink", "symbol"=>"LINK"}, "quote"=>{"id"=>"9a3a2bfb-522f-4d1c-a766-7eb62147fe80", "name"=>"Tether", "symbol"=>"USDT"}}, {"id"=>"432d922f-4501-450e-8d00-7d43e441e372", "base"=>{"id"=>"4d3c27b5-e```

abatan.k
2021-08-17 02:50
It says to me that it is expecting a Hash but got an Array

matt.fellows
2021-08-17 02:51
can you please share the full output? You?ve truncated some important part of the logs

abatan.k
2021-08-17 02:56
```? kansu git:(master) ? yarn jest test/contract/fetch-metadata.spec.ts yarn run v1.22.11 warning package.json: No license field $ /home/carere/Projects/ashiso/kansu/node_modules/.bin/jest test/contract/fetch-metadata.spec.ts [2021-08-17 02:54:56.977 +0000] INFO (1978 on carere-silver): pact@9.16.0: Verifying provider [2021-08-17 02:54:56.983 +0000] INFO (1978 on carere-silver): pact-node@10.13.3: Verifying Pacts. [2021-08-17 02:54:56.984 +0000] INFO (1978 on carere-silver): pact-node@10.13.3: Verifying Pact Files FAIL Contract test/contract/fetch-metadata.spec.ts (6.747 s) Pact Verification ? should validate the expectations of Consumer (5003 ms) ? Pact Verification ? should validate the expectations of Consumer thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 11 | }; 12 | > 13 | it("should validate the expectations of Consumer", (done) => { | ^ 14 | new Verifier(opts).verifyProvider().then(() => { 15 | done(); 16 | }); at test/contract/fetch-metadata.spec.ts:13:3 at Object.<anonymous> (test/contract/fetch-metadata.spec.ts:3:1) at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13) at runJest (node_modules/@jest/core/build/runJest.js:387:19) at _run10000 (node_modules/@jest/core/build/cli/index.js:408:7) at runCLI (node_modules/@jest/core/build/cli/index.js:261:3) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 6.805 s, estimated 7 s Ran all test suites matching /test\/contract\/fetch-metadata.spec.ts/i. ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. at Object.getCodec (node_modules/iconv-lite/lib/index.js:65:27) at Object.getDecoder (node_modules/iconv-lite/lib/index.js:127:23) at getDecoder (node_modules/raw-body/index.js:45:18) at readStream (node_modules/raw-body/index.js:180:15) at getRawBody (node_modules/raw-body/index.js:108:12) [2021-08-17 02:55:02.317 +0000] WARN (1978 on carere-silver): pact-node@10.13.3: Pact exited with code 1. (node:1978) UnhandledPromiseRejectionWarning: Error: INFO: Fetching pacts for kansu from https://ashiso.pactflow.io with the selection criteria: latest for tag master INFO: Reading pact at https://ashiso.pactflow.io/pacts/provider/kansu/consumer/uebuapuri/pact-version/fe9c2dd8a04a567f754ec092e9c4ff93f6ac318b/metadata/c1tdW3RdPW1hc3RlciZzW11bbF09dHJ1ZSZzW11bY3ZdPTI5 DEBUG: The pact at https://ashiso.pactflow.io/pacts/provider/kansu/consumer/uebuapuri/pact-version/fe9c2dd8a04a567f754ec092e9c4ff93f6ac318b is being verified because the pact content belongs to the consumer version matching the following criterion: * latest version tagged 'master' (39cd0f5-master) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which has status code 200 (FAILED - 1) has a matching body (FAILED - 2) includes headers "Content-Type" which equals "application/json; charset=utf-8" (FAILED - 3) Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which has status code 500 (FAILED - 4) has a matching body (FAILED - 5) includes headers "Content-Type" which equals "application/json; charset=utf-8" (FAILED - 6) Failures: 1) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which has status code 200 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is healthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 2) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is healthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 3) Verifying a pact between uebuapuri and kansu Given server is healthy Ashiso's metadata with GET /api/metadata returns a response which includes headers "Content-Type" which equals "application/json; charset=utf-8" Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is healthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 4) Verifying a pact between uebuapuri and kansu Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which has status code 500 Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is unhealthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 5) Verifying a pact between uebuapuri and kansu Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which has a matching body Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is unhealthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 6) Verifying a pact between uebuapuri and kansu Given server is unhealthy Ashiso's metadata with GET /api/metadata returns a response which includes headers "Content-Type" which equals "application/json; charset=utf-8" Failure/Error: set_up_provider_states interaction.provider_states, options[:consumer] Pact::ProviderVerifier::SetUpProviderStateError: Error setting up provider state 'server is unhealthy' for consumer 'uebuapuri' at http://localhost:32969/_pactSetup. response status=415 response body= <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>UnsupportedMediaTypeError: unsupported charset &quot;UTF-8&quot;<br> &nbsp; &nbsp;at /home/carere/Projects/ashiso/kansu/node_modules/body-parser/lib/read.js:83:18<br> &nbsp; &nbsp;at invokeCallback (/home/carere/Projects/ashiso/kansu/node_modules/raw-body/index.js:224:16)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:77:11)</pre> </body> </html> 2 interactions, 2 failures Failed interactions: * Ashiso's metadata given server is healthy (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="b0c2a8697b51aa6628ecf7cced2c37d3b17f72a4") * Ashiso's metadata given server is unhealthy (to re-run just this interaction, set environment variable PACT_BROKER_INTERACTION_ID="09f814d10deae36237682ce2425128735fcfb8ca") (Use `node --trace-warnings ...` to show where the warning was created) (node:1978) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:1978) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.```

abatan.k
2021-08-17 02:57
now i get this error, and i don't know how i can prevent the timeout error, i tried to return the promise, i used async / await, i used done callback, but neither of those fix the issue

abatan.k
2021-08-17 02:57
And i know that my request takes 64ms usually, so i don't know how it can go timeout by Jest

matt.fellows
2021-08-17 02:58
3 test runs and 3 different errors - we need to get a consistent set of failures here

matt.fellows
2021-08-17 02:58
how have you increased the timeout?


matt.fellows
2021-08-17 02:59
```--testTimeout 30000```

matt.fellows
2021-08-17 02:59
something like that should work

abatan.k
2021-08-17 03:01
ookkkaaayy i understand now :slightly_smiling_face:

abatan.k
2021-08-17 03:01
the problem comes from my 2nd test, when i check if my server is unhealthy

abatan.k
2021-08-17 03:02
im waiting for an HASH like {error:'...', message:'...'}

abatan.k
2021-08-17 03:02
the first test passes, the second no, that why i get this error

abatan.k
2021-08-17 03:02
the timeout helped me indeed :slightly_smiling_face:

abatan.k
2021-08-17 03:03
thx for the good advice, i'll go back to my code in order to fix this :slightly_smiling_face: sorry if i made you waste some time :sweat_smile: thx for your help, and your availability :slightly_smiling_face:

matt.fellows
2021-08-17 03:04
haha all good

matt.fellows
2021-08-17 03:04
it looks like you?ve either just woken up or have been working a little too hard - either way, get some sleep and/or :coffee: :laughing:

abatan.k
2021-08-17 03:07
haha good advice indeed, but i know why i wa stuck on this, and this is because i was lazy on my TDD, after finishing my command side :sweat_smile: (I'm in a CQRS architecture actually)

abatan.k
2021-08-17 03:07
An i decided to test my consumer with my real implementation instead of my in-memory :slightly_smiling_face:

abatan.k
2021-08-17 03:07
And that's why i got the problem with my timeout ^^

abatan.k
2021-08-17 03:08
because if i was with my inmemeory implementation, it would be blazing fast, and the logs would be shorter

abatan.k
2021-08-17 03:08
So my bad :sweat_smile: im gonna write thoses test for my query side :rolling_on_the_floor_laughing:

matt.fellows
2021-08-17 03:09
yep, definitely easier against local and less issues - why we prefer this over e2e tests!

matt.fellows
2021-08-17 03:09
:raised_hands:

ram.tripathi
2021-08-17 06:33
has joined #pact-js

ricardo.neto
2021-08-17 09:22
has joined #pact-js

andrew.patterson
2021-08-17 14:55
has joined #pact-js

pshah
2021-08-17 15:31
has joined #pact-js

beem132
2021-08-17 17:36
Hello, I'm having issues getting my stateHandlers to run in my provider tests. I'm on V2 of pact-js, I'm attempting to verify a MessageProviderPact, and it gives me a warning saying that it is skipping setup due to no providerStatesUrl being specified. Doing some digging I saw someone else had this issue and the suggestion was that they do something like new Verifier().verifyProvider(opts) to avoid that message, but that particular verifier complains about a missing Url parameter in the options object.

tjones
2021-08-17 23:17
could you share your test code?

dylanchase26
2021-08-18 04:11
has joined #pact-js

satish.chandra
2021-08-18 05:54
has joined #pact-js

flynnhandley
2021-08-18 22:30
has joined #pact-js

beem132
2021-08-19 13:40
hey, thanks for the response, I have no idea what I did but it stopped displaying the warning, I don't think I actually changed any settings, but is it possible the spec value on the messagePact options could have had an impact on the warning?

tjones
2021-08-19 13:48
It's possible, but I think it has to be set to 3 for message pact to work at all (I'm not sure why the option is there)

beem132
2021-08-19 13:50
ah interesting, I think I may have had it set to two and then deleted the property altogether, so that could be it, thanks!

tjones
2021-08-19 13:56
We'll clean that up in the next version, since we have to touch all of those interfaces

tjones
2021-08-19 13:58
At the moment, I believe `new Pact()` must take spec level of 2, and MessagePact must be 3. In the future (if we keep that option), we'll make it warn if you try to set it to things that it can't do

tjones
2021-08-19 13:58
Sorry about that :confused:

beem132
2021-08-19 13:59
No worries, seems like there's quite a bit of good development going on. Spec 2 and Spec 3 are mostly unrelated to the difference between pact 2 and pact 3 right?

paulorochag
2021-08-19 15:01
How can I use the matcher to validate the `new Date()` from the example below? It's a scenario that I haven't found an example. Tried with `[iso8601DateTime(new Date())]` with no success (generated [Object object] )

thomaswtsang
2021-08-19 16:53
has joined #pact-js

brentbarker9
2021-08-19 17:40
karma-pact 3.0.0 and pact-node 10.13.3 appears to be working!

brentbarker9
2021-08-19 17:41
Thanks for your help!

paulorochag
2021-08-19 18:21
@tjones can you help me?

paulorochag
2021-08-19 18:53
I need to validate that the key is of type dateTime, not the value.

chris005
2021-08-19 19:07
has joined #pact-js

abatan.k
2021-08-19 20:40
Hello all :slightly_smiling_face: How do you tests headers ?? For example, i need to match that my header Content-type contains "application/json", but sometimes, the runtime add an extra "charset=UTF-8", do you have best practice for testing headers ??

matt.fellows
2021-08-19 22:30
We don't have key matchers that can check against a regex I don't believe, but we do have a key type matcher

matt.fellows
2021-08-19 22:30
It's available in the v3 beta

thomaswtsang
2021-08-19 22:38
i _think_ you could use `like()` for header matching

matt.fellows
2021-08-19 22:49
I'd use a regex an have an optional group for the charset


abatan.k
2021-08-19 23:25
thx for your answer :slightly_smiling_face:

matt.fellows
2021-08-19 23:27
np!

abatan.k
2021-08-19 23:28
Hey again :slightly_smiling_face: I have some problem with using Pact and my Dependency Injection. Do you also have some best practice for using Pact and DI ? For some context, i using in-memory implementation for my test on the provider side. But i don't think that when i call my API endpoint, the same container is used on both the test context with pact, and the request context. I tried to explain the best i can :sweat_smile: Hope you will understand what i am saying :slightly_smiling_face:

matt.fellows
2021-08-19 23:31
you can?t use an in-memory API, it needs to be available over an actual HTTP port. maybe if you could explain the use case / tech stack a bit more and we can see if we can help?

matt.fellows
2021-08-19 23:32
But basically, before a provider test runs, the provider _must_ have started up and available via HTTP

abatan.k
2021-08-19 23:34
No my API is running, i start my API manually (im using azure function), then im running my tests `yarn jest --testTimeout 30000` . When i say that im using InMemory implementation, im talking about my adapaters (Im using Port & Adapter Architecture / Hexagonal Architecture / Onion / ...)

abatan.k
2021-08-19 23:36
The problem is that when im populating my inmemory repositories on my provider test, my API doesn't seems to use the same instance of my repositories, so i cannot validate my tests

tjones
2021-08-19 23:37
Hmm. This sounds like a test setup problem rather than a pact problem

tjones
2021-08-19 23:37
(also I like your design choices, this is what I do too :+1:)

abatan.k
2021-08-19 23:38
yeah im a lot in craftmanship :slightly_smiling_face: im using CQRS with hexagonal architecture and some DDD concept, like Bounded Context, etc :wink:

abatan.k
2021-08-19 23:38
and im french so, sorry for my english :rolling_on_the_floor_laughing:

tjones
2021-08-19 23:38
It's not problem, your question is clear

abatan.k
2021-08-19 23:39
To clarify, im noy saying that there is any problem with Pact, i know that my problem comes from my DI lib / implementaion. And since your using Pact in production, i guess you guys, also use some DI implementation in your code base

tjones
2021-08-19 23:41
Yes. In JS, I usually roll my own DI with default params

tjones
2021-08-19 23:43
for example, in a repository I'm working on at the moment, config is loaded asynchronously. So, the file that creates the API reads like: ```export const apiClientFactory = ( tenant: string, configPromise: Promise<ApiConfig> = CONFIG,```

tjones
2021-08-19 23:43
oh, sorry, you're looking at the provider

tjones
2021-08-19 23:44
I use a similar pattern for the provider, but I don't have an example easily to hand

tjones
2021-08-19 23:44
The symptom you have sounds like you might be injecting into a different instance of the app than you're testing?

abatan.k
2021-08-19 23:44
ok i guess i just should use a simple object for my DI container

abatan.k
2021-08-19 23:45
and not rely on third party lib for handling DI

tjones
2021-08-19 23:45
You don't have to - I just find it easy to do it that way

tjones
2021-08-19 23:46
hold on, got a meeting, I'll be back in a bit to elaborate

abatan.k
2021-08-19 23:47
Yeah, but i think im using a lib for DI, because im used to do this in other langage, (im coming from PHP). But it seems that in JS, we don't really need to use 3rd-Party lib, for such simple pattern.

matt.fellows
2021-08-19 23:47
I?ve never really seen a good need for DI frameworks in JS.

matt.fellows
2021-08-19 23:48
It feels like at the point you do that, you may as well just use Java/.NET :stuck_out_tongue:

tjones
2021-08-19 23:48
> I?ve never really seen a good need for DI in JS. Really? I do it in every project

matt.fellows
2021-08-19 23:48
(that?s my opinion, I know DI framewoks exist)

matt.fellows
2021-08-19 23:48
I just updated my answer, I meant DI *frameworks*

abatan.k
2021-08-19 23:50
@matt.fellows honestly im starting thinking the same as you, it is not a langage like PHP / C# / JAVA, and it also seems that the `import / export` capability of JS is enough for DI.

abatan.k
2021-08-19 23:52
So do you have best practice for handling your DI _*without*_ using DI framework ?? I thought about a simple object, where i instantiating in memory adapter and real adapter depending some NODE env variable

abatan.k
2021-08-20 00:24
Ok after some thoughts, i found the problem. In order to run my (azure) functions, i need to compile my typescript, so, my functions use the `dist` folder which is generated by `tsc` . And my tests are using ts-jest in order to run.

srimuralixi
2021-08-20 02:18
has joined #pact-js

tjones
2021-08-20 04:55
Ah yeah. That can be a problem.

tjones
2021-08-20 04:55
I'll update with some thoughts on DI in JS later.

manika.goel
2021-08-20 05:38
has joined #pact-js

manika.goel
2021-08-20 06:18
When I do npm run publish, I am getting error as "No value provided for required options '--broker-base-url'" I tried clearing the cache and installing npm, tried upgrading npm version to 7.21.0. I am still getting this issue. Can someone please help me out here, I am kind of stuck because of this.

matt.fellows
2021-08-20 06:18
have you provided the broker details?

matt.fellows
2021-08-20 06:19
looks pretty clear to me, you?re not passing the broker details

manika.goel
2021-08-20 06:19
yes set PACT_BROKER_BASE_URL=https://centricconsulting.pactflow.io

manika.goel
2021-08-20 06:19
and its token as well

matt.fellows
2021-08-20 06:19
did you set it in that shell?

manika.goel
2021-08-20 06:21
I created this in PACT account and from there I copied my API token

manika.goel
2021-08-20 06:21
Do I need to set it somewhere as well?

matt.fellows
2021-08-20 06:22
it looks like that?s a powershell terminal

matt.fellows
2021-08-20 06:22
```$env:PACT_BROKERBASE_URL=...```

matt.fellows
2021-08-20 06:23
I could be wrong, but it looks like the environment variable is not properly propagating to the shall

matt.fellows
2021-08-20 06:23
you can pass it directly to the publish command also

manika.goel
2021-08-20 06:24
ok let me try this

manika.goel
2021-08-20 06:26
"scripts": {     "test:consumer": "mocha --exit --timeout 30000 consumer.pact.spec.js",     "test:provider": "mocha --exit --timeout 30000 provider.pact.spec.js",     "publish": "npx pact-broker publish ./pacts --consumer-app-version 1.0.0-someconsumersha --tag master"   }, Here you are asking me to mention the env variables? Any example how to do that?

matt.fellows
2021-08-20 06:27
can you please demonstrate that the environment variables are indeed active in your terminal?

matt.fellows
2021-08-20 06:27
if it?s the batch shell, just run `set` and check that the environment variables are set

matt.fellows
2021-08-20 06:28
if powershell: ```gci env:* | sort-object name```

akanksha.sharma
2021-08-20 06:31
has joined #pact-js

manika.goel
2021-08-20 06:36
I am getting this on running this command

matt.fellows
2021-08-20 06:36
I don?t see any PACT_ variables there

matt.fellows
2021-08-20 06:36
you need to set them using Powershell

manika.goel
2021-08-20 06:37
can you please provide an example how to do that?


manika.goel
2021-08-20 06:40
PS C:\ContractTesting_POC> set env:PACT_BROKERBASE_URL=https://centricconsulting.pactflow.io PS C:\ContractTesting_POC> set env:PACT_BROKER_TOKEN=Kel0T09C4jmBPo1QevJaNA tried this, still not seeing PACT_ variables

matt.fellows
2021-08-20 06:41
You don?t use set, you need the $ also

matt.fellows
2021-08-20 06:41
```$env:PACT_BROKER_BASE_URL="https://centricconsulting.pactflow.io"```

matt.fellows
2021-08-20 06:41
```#env:PACT_BROKER_TOKEN=Kel0T09C4jmBPo1QevJaNA```

matt.fellows
2021-08-20 06:42
*now, because this is in public, please go and reset your credentials in Pactflow before your account is taken over* :wink:

manika.goel
2021-08-20 06:46
Got this PACT_ variable but still getting same issue on executing npm run publish: "No value provided for required options '--broker-base-url'"

matt.fellows
2021-08-20 06:46
check the spelling

matt.fellows
2021-08-20 06:46
```PACT_BROKER_BASE_URL``` not ```PACT_BROKERBASE_URL```

manika.goel
2021-08-20 07:10
Thanks Matt. It worked

manika.goel
2021-08-20 07:33
PS C:\ContractTesting_POC> $env:PACT_BROKER_BASE_URL="https://centricconsulting.pactflow.io/" PS C:\ContractTesting_POC> #env:PACT_BROKER_TOKEN=<token> PS C:\ContractTesting_POC> npm run publish > pactflow-getting-started-js@0.1.0 publish > npx pact-broker publish ./pacts --consumer-app-version 1.0.0-someconsumersha *Publishing poc-consumer/poc-provider pact to pact broker at https://centricconsulting.pactflow.io/* *Failed to publish poc-consumer/poc-provider pact due to error: PactBroker::Client::Error - Authentication failed: Unauthorized. Please see https://docs.pactflow.io/docs/login-help for more information.* One or more pacts failed to be published I am getting Authentication failed error although I am able to login the url mentioned.

manika.goel
2021-08-20 07:34
I have tried clearing cache, updating pact version, taken read/write API token

matt.fellows
2021-08-20 07:35
your token command looks wrong

matt.fellows
2021-08-20 07:35
it?s prefixed with a `#`

matt.fellows
2021-08-20 07:35
It worked before, so always suspect it?s your local environment setup

manika.goel
2021-08-20 07:40
```#env:PACT_BROKER_TOKEN=Kel0T09C4jmBPo1QevJaNA``` I provided like you mentioned before

matt.fellows
2021-08-20 07:41
no, it should be `$env:` but you used `#env:`

matt.fellows
2021-08-20 07:41
if you can?t remember, google ?how to set env var in powershell?

manika.goel
2021-08-20 07:42
got it. Thanks

manika.goel
2021-08-20 07:42
it worked

manika.goel
2021-08-20 07:42
:slightly_smiling_face:

tjones
2021-08-20 08:47
what do you mean by pact 2 and pact 3?

tjones
2021-08-20 08:47
`spec` is the "pact specification version"

abatan.k
2021-08-20 10:15
I decided to go with a local web server for my contract testing instead of launching azure function. Since what i do is testing a function :sweat_smile:

matt.fellows
2021-08-20 10:40
sorry, got sidetracked - but that?s _exactly_ what you should do!

akanksha.sharma
2021-08-20 10:48
Need one information related to pact provider side, if I need to connect to my real time provider, what and where we should provide the changes?

tjones
2021-08-20 11:38
What changes?


akanksha.sharma
2021-08-20 11:40
Sure


akanksha.sharma
2021-08-20 12:29
should I change in the below code to access our own project api's (swagger links). ```server.listen(8081, () => {  importData()  console.log("Animal Profile Service listening on http://localhost:8081") })```

akanksha.sharma
2021-08-20 12:32
Also, I am not able to access this url from my local machine then how I am getting a valid response ```http://localhost:8081``` Just need clarification


matt.fellows
2021-08-20 12:42
Looks like we need to add to those docs sorry!

paulorochag
2021-08-20 12:42
Thank you

jonah
2021-08-20 14:42
has joined #pact-js

tlzhou
2021-08-20 15:02
has joined #pact-js

rsaccoll
2021-08-20 17:51
has joined #pact-js

abatan.k
2021-08-20 18:33
yeah it's way more simple :slightly_smiling_face:, anyway thx for the discussion, it helps me a lot :wink:

abatan.k
2021-08-20 18:35
@akanksha.sharma Can you launch a local web server ? (eg. `http.createServer`)

abatan.k
2021-08-20 18:36
I asked the same question as you yesterday, since im using Azure function, and the best approach it's to launch your local server for verifying contract on provider side

abatan.k
2021-08-20 18:39
This is what i do for example, hope it's help :wink:

matt.fellows
2021-08-21 10:29
Not sure I understand your question Akshanka

matt.fellows
2021-08-21 10:29
You need to have the code available for the provider code base locally, start the service locally and test it locally. That?s how 99% of pact provider verifications should happen

matt.fellows
2021-08-21 10:30
> should I change in the below code to access our own project api?s (swagger links). swagger links? The example you provided starts a locally express JS server and then below in the test it tests against that service. What do yo umean by swagger links?

ramya.sri
2021-08-23 03:52
has joined #pact-js

akanksha.sharma
2021-08-23 06:20
from swagger links I mean to say the url of swagger documents where all our API's are listed for project

akanksha.sharma
2021-08-23 06:22
Okay I am going to setup local system so that I can start service locally with help of developer, till now I am only able to access dev and QA env of my project

akanksha.sharma
2021-08-23 06:35
The question I previously want to ask is : I setup the code base locally in VS code for katacoda (https://katacoda.com/pact/scenarios/pactflow-getting-started-js) to get an idea how I can do it for my real time project. Now, in katacoda in provider code, the base url is mentioned as ```providerBaseUrl: "http://localhost:8081"``` and this localhost:8081 is not setup locally on my system but I am still able to verify the pact. So, how the code is connected to the server from my local as I am not able to access localhost:8081 and getting a valid response. I hope you understand it now

matt.fellows
2021-08-23 07:14
Are you asking how katacoda is working when it points to localhost:8081? It works because it?s running on remove Katacoda infrastructure, not your machine

matt.fellows
2021-08-23 07:14
The test is running on remote servers, and it?s starting up an app on those same servers, hence it?s ?local? (localhost) to to where the test is running

matt.fellows
2021-08-23 07:15
> Okay I am going to setup local system so that I can start service locally with help of developer, till now I am only able to access dev and QA env of my project I?m not trying to discourage you, but Pact testing is very much a tool that requires strong technical knowledge, the ability to write and maintain unit tests and good comprehension of the unit you are testing.

matt.fellows
2021-08-23 07:15
Doing Pact ?from the outside? as a black-box style test is not really possible

matt.fellows
2021-08-23 07:16
If I understand correctly, you have a Pactflow account, so you could look at using the Pactflow https://docs.pactflow.io/docs/workshops/bi-directional feature if the above requirements aren?t met

joseramonrivera21
2021-08-23 08:49
has joined #pact-js

denny.duttig
2021-08-23 10:10
has joined #pact-js

akansha.saraswat3
2021-08-23 10:50
has joined #pact-js

dimundo
2021-08-23 18:23
hi! i?m, getting > Could not parse the following content to a Pact due to Pact::UnrecognizePactFormatError and > pact@9.16.0: no handler found for message common.signal still json is valid and looks okish ( for the 1st error ) and description presents ( for the 2nd ) any ideas ?

tjones
2021-08-23 20:51
Is this a pact generated with pact spec version 3?


dimundo
2021-08-23 21:01
issue is, that i wanted to split 1 provider into 2, for 2 consumers

dimundo
2021-08-23 21:01
and looks like it was bad idea

dimundo
2021-08-23 21:03
so separated message triggered `no handler found for message`

sushant.soni
2021-08-23 21:10
has joined #pact-js

dimundo
2021-08-23 21:13
but there is sideeffect of that - build not failed :scream_cat: will investigate tomorrow

tjones
2021-08-23 22:46
pact-js doesn't support spec version 3 yet

tjones
2021-08-23 22:47
we're working on that release

tjones
2021-08-23 22:47
if you like, you can try the beta version


dimundo
2021-08-24 05:40
> pact-js doesn?t support spec version 3 yet weird, pactbroker says, that generated jsons are v3

ajaiswal595
2021-08-24 11:00
has joined #pact-js

pd287515778
2021-08-24 12:48
has joined #pact-js

hwebster
2021-08-25 05:30
has joined #pact-js

hoangvo
2021-08-25 05:43
has joined #pact-js

jobjingjo
2021-08-25 06:20
has joined #pact-js

vbhardwaj.eminent
2021-08-25 07:01
hi, Can I pass tags like this from jenkins so that it can be attached to the pact on pact broker ```Global.script.sh(script: "cd ./client && CI=true tags=${getBranchName()} npm run test:pact -- ${versionId}")``` I could see that in jenkins steps that tags are sent fine from jenkins but not published on the pact in pact broker

tjones
2021-08-25 07:01
I'm not sure I understand what you're trying to do

tjones
2021-08-25 07:02
this looks like it's setting an environment variable called `tags`? Pact doesn't read this variable. Does your script read it?

tjones
2021-08-25 07:02
Also, the verifier supports this specific feature out of the box:

vbhardwaj.eminent
2021-08-25 07:02
in pact js workshop tags are hardcoded in publish.pact.js, but I want to attach my branch name as tag to the contract

tjones
2021-08-25 07:03
Right, we should update that.

tjones
2021-08-25 07:03
It's better practice just to call the publish binary:

vbhardwaj.eminent
2021-08-25 07:03
could you give an example

vbhardwaj.eminent
2021-08-25 07:03
how to do it

tjones
2021-08-25 07:04
``` "pact:publish": "pact-broker publish pacts --consumer-app-version=\"$(npx @pact-foundation/absolute-version)\" --tag-with-git-branch --broker-base-url=https://pact-broker.example.com"```

tjones
2021-08-25 07:05
this is a (slightly redacted) example from one of my projects

tjones
2021-08-25 07:05
Note that this assumes that your pacts are in a directory called `pacts`

tjones
2021-08-25 07:06
I'd like to go through all the examples and remove `publish.js`

tjones
2021-08-25 07:06
it's not necessary and I think it causes more confusion than it helps

vbhardwaj.eminent
2021-08-25 07:08
why

tjones
2021-08-25 07:08
because you can get the publish functionality directly from your npm script

vbhardwaj.eminent
2021-08-25 07:11
can i do `"posttest:pact": "node publish.pact.js --tag-with-git-branch"`

matt.fellows
2021-08-25 07:29
does the file `publish.pact.js` accept that argument? If you?ve copied from one of the Pact JS examples, I doubt it

matt.fellows
2021-08-25 07:30
`publish.pact.js` is a user defined piece of JS, that essentially delegates back to the command Tim is referring to. So you can do whatever you want in that, and you could make your example work

vbhardwaj.eminent
2021-08-25 07:30
I got it

matt.fellows
2021-08-25 07:30
But FWIW I would just use the CLI directly. Less code, something you can repeat across languages for consistency etc.

vbhardwaj.eminent
2021-08-25 07:30
thanks Matt and Tim!

matt.fellows
2021-08-25 07:31
:thumbsup:

matt.fellows
2021-08-25 07:31
np

sagarsitap596
2021-08-25 14:10
has joined #pact-js

kyle.fischer
2021-08-25 16:31
has joined #pact-js

datasmithadvtech
2021-08-25 19:43
has joined #pact-js

todor.m.kolev
2021-08-25 19:59
has joined #pact-js

sushmitha.amin
2021-08-26 04:31
has joined #pact-js

tausif2909
2021-08-26 06:00
Hello, At consumer side my path contains the uuid : `"path": "/api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c"` , How do I replace the uuid in providerVerification code, Can someone share the example?

matt.fellows
2021-08-26 06:56
you would usually have a provider state that says `given a secret with uuid 4gf8c91a-64e1-47c2-a293-72252b5c1e4c exists` and a state handler that can create the secret

matt.fellows
2021-08-26 06:56
i.e. provider states


tausif2909
2021-08-26 07:18
Thanks @matt.fellows

akansha.saraswat3
2021-08-26 11:11
Hey team, I am getting the following error after running the pact.spec file ```thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 10 | 11 | describe('Retrieving Project Details', () => { > 12 | beforeAll(() => mockProvider.setup()); | ^ 13 | beforeEach(() => { 14 | jest.setTimeout(90000); 15 | });```

matt.fellows
2021-08-26 11:13
Try adding a global timeout as a flag in jest. Also, what do the debug logs say? Have a look at the section on troubleshooting

shwetastar98
2021-08-26 12:35
has joined #pact-js

contact
2021-08-26 12:44
has joined #pact-js

tjones
2021-08-26 13:17
BeforeAll is executed before beforeEach, so your timeout isn?t being set

tjones
2021-08-26 13:17
You can use jest-pact to set all the right defaults for pact, and to reduce the boilerplate

malena.cadima
2021-08-26 16:07
has joined #pact-js

louis.ss
2021-08-27 01:42
has joined #pact-js

akansha.saraswat3
2021-08-27 05:08
@malena.cadima These are the logs--- couldn't get much out of it. Can you pls check? ```0 info it worked if it ends with ok 1 verbose cli [ 1 verbose cli '/usr/local/bin/node', 1 verbose cli '/usr/local/bin/npm', 1 verbose cli 'run', 1 verbose cli 'coverage', 1 verbose cli '--', 1 verbose cli '-u', 1 verbose cli 'src/__tests__/components/project-search/projectsearch.pact.spec.js' 1 verbose cli ] 2 info using npm@6.14.4 3 info using node@v14.2.0 4 verbose run-script [ 'precoverage', 'coverage', 'postcoverage' ] 5 info lifecycle grand-ui-core@1.0.0~precoverage: grand-ui-core@1.0.0 6 info lifecycle grand-ui-core@1.0.0~coverage: grand-ui-core@1.0.0 7 verbose lifecycle grand-ui-core@1.0.0~coverage: unsafe-perm in lifecycle true 8 verbose lifecycle grand-ui-core@1.0.0~coverage: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/a0s0dw5/Documents/GitHub/grand-ui-core/node_modules/.bin:/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/a0s0dw5/Documents/GitHub/grand-ui-core/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/munki:/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin 9 verbose lifecycle grand-ui-core@1.0.0~coverage: CWD: /Users/a0s0dw5/Documents/GitHub/grand-ui-core 10 silly lifecycle grand-ui-core@1.0.0~coverage: Args: [ 10 silly lifecycle '-c', 10 silly lifecycle 'CI=true react-scripts --max_old_space_size=4096 test --ci --coverage --testResultsProcessor=./node_modules/jest-sonar-reporter --env=jest-environment-jsdom-sixteen "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js"' 10 silly lifecycle ] 11 silly lifecycle grand-ui-core@1.0.0~coverage: Returned: code: 1 signal: null 12 info lifecycle grand-ui-core@1.0.0~coverage: Failed to exec coverage script 13 verbose stack Error: grand-ui-core@1.0.0 coverage: `CI=true react-scripts --max_old_space_size=4096 test --ci --coverage --testResultsProcessor=./node_modules/jest-sonar-reporter --env=jest-environment-jsdom-sixteen "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js"` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:315:20) 13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:315:20) 13 verbose stack at maybeClose (internal/child_process.js:1051:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) 14 verbose pkgid grand-ui-core@1.0.0 15 verbose cwd /Users/a0s0dw5/Documents/GitHub/grand-ui-core 16 verbose Darwin 19.6.0 17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "coverage" "--" "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js" 18 verbose node v14.2.0 19 verbose npm v6.14.4 20 error code ELIFECYCLE 21 error errno 1 22 error grand-ui-core@1.0.0 coverage: `CI=true react-scripts --max_old_space_size=4096 test --ci --coverage --testResultsProcessor=./node_modules/jest-sonar-reporter --env=jest-environment-jsdom-sixteen "-u" "src/__tests__/components/project-search/projectsearch.pact.spec.js"` 22 error Exit status 1 23 error Failed at the grand-ui-core@1.0.0 coverage script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]```

tjones
2021-08-27 05:08
This is not the pact log

tjones
2021-08-27 05:09
The pact log will be in the `log` directory by default, or `pact/log` if you're using jest-pact. Or wherever you've configured it if you have changed it

tjones
2021-08-27 05:10
Did you try moving the setting of the timeout to your `beforeAll`?

tjones
2021-08-27 05:11
Although, that error log looks like you're having a problem with the coverage script, which will be unrelated to pact.

akansha.saraswat3
2021-08-27 05:20
yes i did .... i used beforeAlll earlier, error was still the same - timeout. I'll check for pact log and post here

akansha.saraswat3
2021-08-27 06:38
Where do we set this global variable? and what is global variable name and format to set?

akansha.saraswat3
2021-08-27 06:51
I am unable to move further from this .... every time I run test case... this error comes in ``` thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 20 | 21 | }); > 22 | beforeAll(() => mockProvider.setup()); | ^ 23 | test('ID 112342-001', async () => { 24 | const expectedProduct = { 25 | "status": "success",``` Code Snippet ```describe('Retrieving Project Details', () => { beforeEach(() => { jest.setTimeout(jestConfig.defaultTimeoutInterval || 15000); }); beforeAll(() => mockProvider.setup()); test('ID 112342-001', async () => { const expectedProduct = { "status": "success", "message": null,```


matt.fellows
2021-08-27 06:53
(from our workshop)

matt.fellows
2021-08-27 06:54
what is the value of `jestConfig.defaultTimeoutInterval` ?

matt.fellows
2021-08-27 06:54
presumably, 5000ms

akansha.saraswat3
2021-08-27 06:54
yes default value

matt.fellows
2021-08-27 06:54
What are you expecting `jest.setTimeout(jestConfig.defaultTimeoutInterval || 15000);` to do?

matt.fellows
2021-08-27 06:56
This is a question about *Jest*, your test runner. I?ve given an example, but I?d be googling Jest docs for more on htat

akansha.saraswat3
2021-08-27 06:58
it's just a different way to write timeout ... just to see if this will work .. earlier i just used the time unit

matt.fellows
2021-08-27 06:59
well, that statement says set the timeout value to `15000` _only if_ there is no default timeout. Which I think is why your timeout isn?t overriding the default timeout - there is a default, and it?s `5000`!

akansha.saraswat3
2021-08-27 07:00
yeah i don't see t anywhere in the code and how to override it. No matter what i do ... the default timeout is not getting replaced


akansha.saraswat3
2021-08-27 07:34
This didn't solve the problem, same 5000ms jest timeout issue. Could you pls check how to replace this default timeout for jest? Any example frameworks if you have

matt.fellows
2021-08-27 07:35
rather than us continually try ways to tweak your code that we can?t see, perhaps you could create a reproducable example we can help with? The timeout is a jest property, and this is a Pact forum

tjones
2021-08-27 07:37
You can also use `jest-pact`, which sets the timeout for you.


sergio.amorim
2021-08-27 14:40
has joined #pact-js

slin
2021-08-29 23:51
has joined #pact-js

shane.robinson
2021-08-30 00:30
has joined #pact-js

br.maher
2021-08-30 04:35
has joined #pact-js

akanksha.sharma
2021-08-30 11:04
Quick question - Does pact also verify the value of data present in response body OR it only verify the datatype of the fields present in response body. For eg : "body": {           "accountId": 9348878860,           "agencyCode": "5678777",           "accountStatus": "Open"} I want to validate agencyCode as negative scenario, value "5678777" should not match with provider value. So creating a mock API with "agencyCode": "5678777", but my provider has "agencyCode": "4218". When I am running my test, I am expecting it to get failed but its still passing.

matt.fellows
2021-08-30 11:13
yes, it will match exact values if you tell it to

matt.fellows
2021-08-30 11:13
if you?re using a matcher e.g. `Matchers.like` then it just looks at the type

akanksha.sharma
2021-08-30 11:19
What is the matcher function to match the exact values?

matt.fellows
2021-08-30 11:25
you don?t use a matcher

akanksha.sharma
2021-08-30 11:31
Then ?

matt.fellows
2021-08-30 11:33
you just don?t use a matcher, and it will use the value you provided

matt.fellows
2021-08-30 11:33
maybe share what you?re doing so we can advise?

akanksha.sharma
2021-08-30 11:38
consumer.pact.spec.js

akanksha.sharma
2021-08-30 11:38
please check below code

akanksha.sharma
2021-08-30 11:41
```const { Pact } = require ('@pact-foundation/pact'); const { ProductApiClient } = require ('./api'); const { Product } = require ('./product'); const { Matchers } = require("@pact-foundation/pact") const { like, regex } = Matchers const chai = require("chai") const expect = chai.expect // (2) Configure our Pact library const mockProvider = new Pact({   consumer: 'account-consumer_v5',   provider: 'account-provider_v5',   cors: true  }); describe('Account API test', () => {   // (3) Setup Pact lifecycle hooks   before(() => mockProvider.setup());   afterEach(() => mockProvider.verify());   after(() => mockProvider.finalize());   it('get account by ID', async () => {     // (4) Arrange     const expectedProduct = { accountId: 9348878860, agencyCode: "4218", accountStatus: "Open" }     await mockProvider.addInteraction({       state: 'an account with ID 9348878860 exists',       uponReceiving: 'a request to get an account',       withRequest: {         method: 'GET',         path: '/v1/accounts/9348878860'       },       willRespondWith: {         status: 200,         headers: {           'Content-Type': regex({generate: 'application/json; charset=utf-8', matcher: '^application\/json'}),         },         body: like(expectedProduct),       },     });     // (5) Act     const api = new ProductApiClient(mockProvider.mockService.baseUrl);     console.log("Base url : " + mockProvider.mockService.baseUrl)     const product = await api.getAccount(9348878860);     // (6) Assert that we got the expected response     expect(product).to.deep.equal(new Product(9348878860, "4218", "Open"));   }); });```

matt.fellows
2021-08-30 11:41
`like(expectedProduct)` So this says ?match every single property in the object based on its type, and not the value?

matt.fellows
2021-08-30 11:42
rather than wrapping the whole object in a `like` just wrap the properties you want to match by type

kwongyun
2021-08-30 15:57
has joined #pact-js

0x06065a
2021-08-31 00:02
has joined #pact-js

matt.thomas
2021-08-31 05:29
has joined #pact-js

abhi.nandan964
2021-08-31 10:19
has joined #pact-js

tausif2909
2021-08-31 11:53
Hi, To write `matcher` for an `id` in `path` I have found : `path: term({ generate: "/animals/1", matcher: "/animals/[0-9]+" })` , Same way how can we write the regex matcher for `uuid` ?

tjones
2021-08-31 11:55
Are you asking for a regex for a standard uuid like `123e4567-e89b-12d3-a456-426614174000`?

tjones
2021-08-31 11:56
try: ```[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}```

tausif2909
2021-08-31 12:16
Thanks @tjones

tausif2909
2021-08-31 12:30
Sorry but that didn't work

tausif2909
2021-08-31 12:30
Is this the right way to write in `path`

tausif2909
2021-08-31 12:31
`path: term({ generate: '/api/accounts/4gf8c91a-64e1-47c2-a293-72252b5c1e4c', matcher: '/api/accounts/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}' })`

abubics
2021-08-31 12:47
what about it isn't working?

abubics
2021-08-31 12:48
in Kotlin, I've got ```matchPath( "/admin/amendments/${RegexUUID}", "/admin/amendments/${ConstUUID}" )``` where ```private const val Hex = "[0-9a-fA-F]" private const val RegexUUID = "${Hex}{8}-${Hex}{4}-${Hex}{4}-${Hex}{4}-${Hex}{12}"```

abubics
2021-08-31 12:49
so I guess you could do a similar thing in JS.

abubics
2021-08-31 12:49
Do you get an error, or something?

tausif2909
2021-08-31 12:50
its not generating the pact, no error in logs, It works fine when I replace the regex to `[0-9]+`

tausif2909
2021-08-31 13:34
It works with simple regex like `[0-9a-f]` but if I add something in `{}` like `[0-9a-f]{12}` It doesn't generate the pact file

abubics
2021-08-31 13:47
I don't know if you need to escape the `-`s . . . which logs have you looked in? Usually, if the pactfile doesn't get generated, there'll be logs saying what went wrong (e.g. in `./logs/`)

abubics
2021-08-31 13:50
there also should be a `uuid` matcher, you could check how it works, and replicate that in your URL

shivi.btech08
2021-08-31 21:03
has joined #pact-js

tausif2909
2021-09-01 04:59
tried `uuid` matcher too.. that didn't work :disappointed:

abubics
2021-09-01 06:22
it's a bit hard to help if all the information given is "it didn't work" :pray:

tausif2909
2021-09-01 06:50
When I use normal regex like : `[0-9a-zA-Z]+` it generates logs in log file like below :

tausif2909
2021-09-01 06:50
```I, [2021-09-01T11:35:09.929594 #17936] INFO -- : Registered expected interaction GET /api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c D, [2021-09-01T11:35:09.929594 #17936] DEBUG -- : { "description": "Get secrets by UUID", "request": { "method": "GET", "path": { "json_class": "Pact::Term", "data": { "generate": "/api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "matcher": { "json_class": "Regexp", "o": 0, "s": "/api/secrets/[0-9a-zA-Z]+" } } }, "query": { } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "uuid": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "revision": { "json_class": "Pact::SomethingLike", "contents": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c" }, "data": { "key": "AKIAJXZAXSMEXIGSGPNA", "secret": "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", "flexVideoProxyPact": "true" }, "lastUpdate": { "json_class": "Pact::SomethingLike", "contents": 1584542499435 } } }, "metadata": null } I, [2021-09-01T11:35:09.944560 #17936] INFO -- : Received request GET /api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c D, [2021-09-01T11:35:09.944876 #17936] DEBUG -- : { "path": "/api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "query": "", "method": "get", "headers": { "Accept": "application/json", "User-Agent": "Needle/2.9.0 (Node.js v14.17.1; win32 x64)", "Host": "localhost:18186", "Connection": "close", "Version": "HTTP/1.1" } } I, [2021-09-01T11:35:09.945057 #17936] INFO -- : Found matching response for GET /api/secrets/4gf8c91a-64e1-47c2-a293-72252b5c1e4c D, [2021-09-01T11:35:09.945057 #17936] DEBUG -- : { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "uuid": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c", "revision": { "json_class": "Pact::SomethingLike", "contents": "4gf8c91a-64e1-47c2-a293-72252b5c1e4c" }, "data": { "key": "AKIAJXZAXSMEXIGSGPNA", "secret": "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", "flexVideoProxyPact": "true" }, "lastUpdate": { "json_class": "Pact::SomethingLike", "contents": 1584542499435 } } } I, [2021-09-01T11:35:09.959953 #17936] INFO -- : Writing pact for flex-secrets-service to D:/git-directory/flex-videoproxy-service/pact/flex-videoproxy-service-flex-secrets-service.json```

tausif2909
2021-09-01 06:51
but when I use regex for uuid, the log file remain empty

tausif2909
2021-09-01 06:51
Thats why I dont have any more information to share

kpuengpanich
2021-09-01 07:14
has joined #pact-js

mhmtyuceoz
2021-09-01 07:35
has joined #pact-js

tausif2909
2021-09-01 09:35
nevermind, I have switched to pactV3, and got the expected output, thanks for your help @abubics

abubics
2021-09-01 09:44
oh cool, I'm glad you got something working!

tjones
2021-09-01 11:04
I suspect that there was something else in the test that was causing the failure, like a promise not being returned to the testing framework

tjones
2021-09-01 11:05
But if it?s working now with v3, that?s good

tausif2909
2021-09-01 11:28
Yeah it worked with V3, But I have changed the approach, instead of using `term`, I have used `MatchersV3.fromProviderState`

tausif2909
2021-09-01 13:24
Hi, After upgrading to `V3` , Publish to Pact Broker is broken, Getting error : `Error: Cannot find module '@pact-foundation/pact-node'` Previously I was on version `9.16.0`, What changes are required, Can someone share the example

tjones
2021-09-01 13:28
Where are you getting this error?

tjones
2021-09-01 13:31
It?s much easier to help you if you can share your test code- I think your other example could have been solved that way

tjones
2021-09-01 13:31
If you are including pact-node in your test, then you?ll need to use pact-core instead in the beta branch

tjones
2021-09-01 13:32
But, you shouldn?t need to include either- you can publish straight from the pact-broker command

tjones
2021-09-01 13:32
I?m on mobile right now but I can link you to the documentation tomorrow

tjones
2021-09-01 13:33
To make it easiest for us to help you, have a look at howtoask

2021-09-01 13:33
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help

tausif2909
2021-09-01 13:38
I have replaced `@pact-foundation/pact-node` with `@pact-foundation/pact-core` looks like it worked

tjones
2021-09-01 14:06
Make sure you pin the version of both pact-core and pactjs-beta. The interface is not stable and will change.

volkan.tufekci
2021-09-02 08:47
has joined #pact-js

yassine
2021-09-02 10:59
has joined #pact-js

connor.beck
2021-09-02 13:39
has joined #pact-js

maurits.out
2021-09-02 15:12
has joined #pact-js

kumasaka.tk
2021-09-02 21:24
has joined #pact-js

valeriia.danylenko
2021-09-03 18:26
has joined #pact-js

irmt06
2021-09-04 22:51
has joined #pact-js

aram
2021-09-05 06:50
Hi folks, need some assistance :slightly_smiling_face: At the moment, due to difficulties, i?m running contract test as Integration. So we?re writing a DELETE test, and for that i need to first create (on provider side) the object, which is given a unique ID. How can i add that ID to the url on the _provider_ side?

tjones
2021-09-05 06:52
In the current release of pact-js, you can't. You have to mock the thing that creates a unique ID

tjones
2021-09-05 06:52
however, in the upcoming release, you will be able to use provider state variables

tjones
2021-09-05 06:52
you can check this out with the beta branch (see under V3 pacts in the readme)

tjones
2021-09-05 06:53
however, note that the interface for that branch is in flux and will change

aram
2021-09-05 06:55
Sounds great, thanks @tjones? i?ll follow the release :slightly_smiling_face:

tjones
2021-09-05 06:55
Oh, actually, you may have another option. There's the ability to modify the request before it is sent to the provider. I'm not sure if you can modify the URL though. See: https://github.com/pact-foundation/pact-js#modify-requests-prior-to-verification-request-filters

aram
2021-09-05 06:57
i think this if just for the headers. I want to change the request URL for a specific pact test..

tjones
2021-09-05 07:05
Yeah. You might be able to subvert that mechanism, though. The way it is implemented is that the request goes through a proxy, and this is a filter in the proxy. You have access to the full request object. However, the proxy doesn't respect all changes.

tjones
2021-09-05 07:05
Which pact framework is the consumer test in?

aram
2021-09-05 07:08
js as well

tjones
2021-09-05 07:10
Cool. This isn't well documented, but the request filter is express app-level middleware. A quick read of their docs suggests that you can change the path:


aram
2021-09-05 07:11
hmm?. i?ll take a look. Thanks again

tjones
2021-09-05 07:11
In summary, you have three options: ? use provider state to mock the unique identifier so the client can know it ? use pact-js 10.x beta (but the interface will change) ? use a request filter, but it's a bit of a hack

tjones
2021-09-05 07:11
The highest priority is releasing the next version of pact-js with all this support.

tjones
2021-09-05 07:11
(for us)

aram
2021-09-05 07:12
any ETA on that?

tjones
2021-09-05 07:12
If you go the beta, make sure you pin the version

tjones
2021-09-05 07:12
Unfortunately not really. Both Matt and I are working on it in our spare time.

tjones
2021-09-05 07:12
Verifier support will be soon though - that work is mostly done.

aram
2021-09-05 07:13
cool! cheers

tjones
2021-09-05 07:13
Let me know if any further clarification will help

tausif2909
2021-09-06 05:30
What is the most stable version of `pactV3` and `pact-core` , My PR reviewer is not happy If I use `beta` version while adding depedencies

tjones
2021-09-06 05:33
They're all considered unstable.

tjones
2021-09-06 05:33
Pragmatically you could pin one that works for you, and leave it at that.

divyalakshmi.gk
2021-09-07 01:46
has joined #pact-js

constantin.jaeck
2021-09-07 02:24
has joined #pact-js

narendra_uppara
2021-09-07 07:17
has joined #pact-js

nikuplanchiwar
2021-09-07 08:03
has joined #pact-js

sdomeracki
2021-09-07 10:22
has joined #pact-js

jgfarias42
2021-09-07 11:53
has joined #pact-js

gibraltor999
2021-09-07 12:03
has joined #pact-js

jgfarias42
2021-09-07 12:23
[JEST PACT] Hi folks, I am having some trouble starting up the Mock Server using Jest Pact [1]. I set up an interactions similar to how it is explained on the repository, simply declaring it with _pactWith_ and adding an interaction to the injected _provider_ variable. (First image) When I run the test, before any call is made to the server, I get this error during the attempt to call _spawn_ on the server (this command is not executable on my terminal - should it? I didn't find on _brew_). I am also sharing my _jest.pack.js_ and the _package.json_. I have a toy/POC project on the same machine and with the same setup, and it works with this approach. I am on a Mac Intel 11.5. Any thoughts? 1 - https://github.com/pact-foundation/jest-pact

tjones
2021-09-07 13:57
Can you tell us: ? What version of `pact-js` and `pact-node` you are using please? You can find out with: ```npm ls @pact-foundation/pact npm ls @pact-foundation/pact-node``` ? What OS and architecture you are running on

tjones
2021-09-07 13:58
This error is saying that the binary isn't present, which means that your npm install might have failed. To test this, can you try deleting your `node_modules` directory and running `npm install` again please?

tjones
2021-09-07 13:59
Yes, the pact mock service should be runnable on the command line, but not at the path in that error message

tjones
2021-09-07 14:01
it is in `<your-project-home>/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63/pact/bin/pact-mock-service`

tjones
2021-09-07 14:03
note that the binaries are downloaded during install, so if you're doing `--ignore-scripts` when you install, then pact won't work

tjones
2021-09-07 14:04
I'd like to clean up the error reporting in this case, I think we can do a lot better.

tjones
2021-09-07 14:05
> I have a toy/POC project on the same machine and with the same setup, and it works with this approach. This is good news! Is it using the same versions of pact and pact-node?

tjones
2021-09-07 14:06
There definitely is either a bug or an opportunity for improvement here somewhere, and I'd really like to get a fix out if we can.

tjones
2021-09-07 14:07
If you are still experiencing this issue after removing node modules and doing npm install again, it would be awesome if you could put it up somewhere I can download it and take a look

gibraltor999
2021-09-07 14:43
There is an issue which I faced recently that if the project path has a folder with space then the tests wont run and they just give a error that '*eg: ERROR (23471 on C02FTDNXMD6M): pact-node@10.13.3: Pact Binary Error: node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63/pact/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory'.*

gibraltor999
2021-09-07 14:44
Can this be addressed with better error handling so that it doesnt become a nightmare to understand the issue.

gibraltor999
2021-09-07 14:45
2. Same goes with the provider name being case sensitive. AT the consumer side I provided the provider name as : ABc and at the provider side it was ABC, and again error was not user friendly to investigate



tjones
2021-09-07 15:19
Oh, this one is new. Hmm.

tjones
2021-09-07 15:19
It would be great if the broker warned if you were asking for a consumer that's similarly named to another

tjones
2021-09-07 15:20
(especially if it just differed in case)

tjones
2021-09-07 15:21
Thanks for the reports, though! Even though we already had these two, I'd prefer we hear about an issue twice than not at all.

tjones
2021-09-07 15:22
I'm not sure we can do much at the framework level, though - since we ask the broker for the pacts with a specific string.


tjones
2021-09-07 15:27
I hope you don't mind that I credited you. Feel free to vote for it over there.

norway.martin
2021-09-07 18:38
has joined #pact-js

matt.fellows
2021-09-07 22:16
The broker does warn you if you create similarly named contracts


tjones
2021-09-08 01:35
Ah! Maybe this is an edge case? @gibraltor999 would you be able to share the exact names you used? What version of the broker were you using?

valeriia.danylenko
2021-09-08 07:39
hello everyone) I'm relatively new to development so I apologize in advance if my question will sound silly or somethings. I am recently working on implementing contract testing on provider side (which is a NestJS microservice). Presumably my microservice structure looks this way (see the picture): There are different modules that represent different features of a microservice. All of these modules are imported to AppModule. Additionally there's a common folder that hosts CoreModule. This module, in turn, imports DatabaseModule. Database module imports MongoModule (where DB connection is established) and uses MongoService as provider. CoreModule is used in all feature modules of a microservice. While trying to write a pact test I came arcoss an issue. Generally, during unit tests ordinary database connection is replaced with mock connection provided by mongo-memory-server. This is simply achieved by creating a testing module and using provide/useFactory block for a provider that needs to be mocked. I studied nestjs-provider-pact example, and it seems that we create a test module based on the whole application, additionally we also include PactModule (which is not a testing module but a real-time one). This PactModule import a module, a provider of which I would later use to set state of a provider. So my questing is: I want to seed my mocked database with some data in stateHandler block. In order to do it I need to inject mocked db-connection to PactModule, and make sure that the same mocked-connection is used during testing module initialization. Is there a way to do it?

matt.fellows
2021-09-08 08:03
I think that might be NestJS specific question, which I can?t answer. But perhaps Omer can (he created a NestJS library. See https://github.com/omermorad/nestjs-pact) But as a general rule, in the state handlers you need access to the mocking context, and you would usually do it there. @omer.moradd @omer.morad (sorry for the double, not sure which of the handles is real Omer!)

omer.moradd
2021-09-08 08:12
Hey! @valeriia.danylenko I read your question, I will PM you and we?ll try to solve it together @matt.fellows@matt.fellows@matt.fellows after we?ll figure out the solution I will post it here so everyone can enjoy it Also, do you think maybe it?s worth creating an issue in GitHub?

adamdullenty
2021-09-08 08:23
has joined #pact-js

gibraltor999
2021-09-08 08:36
@tjones: Pact Broker version used: Pact Broker Version: 2.83.0

gibraltor999
2021-09-08 08:37
Just a simple string : *Provider* (I used this a the consumer side) and I used *provider* at the provider side

matt.fellows
2021-09-08 10:19
Oh wow, thanks for the quick response Omer!

matt.fellows
2021-09-08 10:20
Only if you think it?s an issue with the framework or an obvious inclusion for documentation or something

marcin.baranowski953
2021-09-08 10:59
Hello, From time to time, when I run contract tests on consumer side (js), I get this error msg: ```Error: Pact startup failed; tried calling service 10 times with no result.``` I've found out that this happens only when I have running docker-compose up on my machine... but not always. It depends on services I have started using docker-compose. So I've began to check which service is causing trouble. I've done binary elimination (of 8 services). It turned out that none of the services alone is causing trouble: I can run only first half and pact server is running fine and also when running the second half pact server is still ok. Only mixes of them makes pact server unable to run. Checking all of these combinations would take a lot of time (256 possibilities with only this one docker-compose file, I have more of them :wink: ), so I prefer to find source of the problem. Anyone has had such issue? Do You have any suggestions? Unfortunately I cannot send here original docker-compose.

tjones
2021-09-08 11:00
Hmmm... I can't think of anything that would cause this

tjones
2021-09-08 11:00
are you setting a specific port when you're starting pact?

tjones
2021-09-08 11:01
What version(s) of pact are you using?

marcin.baranowski953
2021-09-08 11:02
yes, I set specific port (already tried few others to make sure it doesn't clash with any other)

tjones
2021-09-08 11:02
What happens if you don't supply a port?

marcin.baranowski953
2021-09-08 11:03
The latest versions: ``` '@pact-foundation/pact': 9.16.0 '@pact-foundation/pact-node': 10.13.5```

tjones
2021-09-08 11:05
One thing that might be happening is that the timeout might need to be longer. In pact-node, I think the test timeout isn't respected by the thing that waits for the service

marcin.baranowski953
2021-09-08 11:05
The same error, when I don't supply port

tjones
2021-09-08 11:06
we fixed this in pact-core, hold on a moment and I'll backport it

tjones
2021-09-08 12:01
Apologies, that took longer than I expected, because of some reasons. If you bump your pact version, you should get: ``` '@pact-foundation/pact': 9.16.1 '@pact-foundation/pact-node': 10.13.7```

tjones
2021-09-08 12:01
This adds a `timeout` option to `new Pact()`, that you can configure to ask it to wait longer. This is probably appropriate in docker, where everything takes much longer.

tjones
2021-09-08 12:01
the default is `30000` milliseconds

tjones
2021-09-08 12:06
@jgfarias42: Try `"@pact-foundation/pact": "^9.16.1"` - this will bump pact-node to 10.13.7, which contains a fix for at least one issue that caused this.

tjones
2021-09-08 12:06
@marcin.baranowski953: Let me know if that fixes it. I'm off to bed here, but if you have any further problems, I can take a look tomorrow.

marcin.baranowski953
2021-09-08 12:08
Okey, I will check it later and let You know :wink:

tjones
2021-09-08 12:12
:taco: for @omer.moradd for a super quick response!

martin.a.harkins
2021-09-08 12:15
has joined #pact-js

martin.a.harkins
2021-09-08 12:40
Howdy ! I'm trying to set up the verification tests for a provider (ie. `MyProviderService`) that provides both a REST API (using `Verifier`) and Kafka Messages (using `MessageProviderPact`). I'm having some trouble with that... Is that at all possible while keeping a common provider name ? ? I've already grouped all the REST consumers into a Verifier, and all the Event consumers into a MessageProviderPact ? Individually, each contract passes (ie. by having separate Verifiers for each Provider <-> Consumer REST communications, and specifying a specific pactUrl to that consumer) > As a side note, we actually have multiple consumers for the REST APIs and multiple consumers for the Event messaging...

martin.a.harkins
2021-09-08 12:41
Please let me know if you require more information. My guess that this might not be possible and that I should declare multiple provider names...

martin.a.harkins
2021-09-08 12:43
That's with Pact 2

tjones
2021-09-08 13:02
Unfortunately, both pact spec version 2 and (I think) 3 require different consumer names for the different types of pact

tjones
2021-09-08 13:03
Usually I?d do something like ?FooConsumer http? and ?FooConsumer kafka?

tjones
2021-09-08 13:03
Ah, sorry- the question is about providers. I believe the same is true for provider names

martin.a.harkins
2021-09-08 13:15
okay thanks. Found a fun thing playing around with consumerVersionSelectors: Given consumers: ? MyWebApp ? MyKafkaConsumer ```consumerVersionSelectors: [{ tag: 'develop', consumer: 'MyKafkaConsumer', }],``` Does only test that consumer, but tests of course ALL versions. ```consumerVersionSelectors: [{ tag: 'develop', latest: true, consumer: 'MyKafkaConsumer', }],``` Tests only the latest version, but tests ALL the consumers. NOOO so CLOSE !

omer.moradd
2021-09-08 13:26
Yayyy

omer.moradd
2021-09-08 13:26
Thanks :))

martin.a.harkins
2021-09-08 13:35
Ah I had the prop consumerVersionTag specified. Specifying the consumerVersionSelectors + lastest:true + consumer: 'XXX' now works !

jgfarias42
2021-09-08 14:00
Hi Timothy, sorry the delay. Yes, the issue is exactly the absence of the mock server binaries. On the POC project, I can see them (first image), but on my "real" project, they are not being downloaded (second image). Unfortunately, I cannot share the code, because it's proprietary. The POC is using Pact 9.12/Pact-Node 10.13.5 (third image). It works fine. I've upgrade the real project to Pact 9.16/Pact-Node 10.13.7 (fourth image), but it doesn't work. I've copied manually these binaries to the real project and everything works fine :rolling_on_the_floor_laughing: Note: I have to use Yarn because the project uses Yarn's workspaces, NPM doesn't support it.

valeriia.danylenko
2021-09-08 14:01
@omer.moradd Thank you so much for such thorough assistance. @matt.fellows at the end of the day it was Nestjs specific issue (and my lack of understanding nestjs testing flow). And the provided example and Pact itself work perfectly well.

marcin.baranowski953
2021-09-08 14:19
When I provided `timeout: 31000` or higher value I get: ```Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.```

marcin.baranowski953
2021-09-08 14:25
I guess one think may be not clear: I don't need to run contract tests along with running docker-compose. Me and my teammates use docker-compose on daily basis and running contract tests on local machines would be just inconvinient. Right now (until we find cause) it requires stopping docker-compose and rerun it after running contract tests.

matt.fellows
2021-09-08 14:49
Another :taco: for @omer.moradd

matt.fellows
2021-09-08 14:49
Thank you!

omer.moradd
2021-09-08 14:50
You welcome :hearts:

tjones
2021-09-08 23:44
Ah, is this yarn2? Yarn made a bunch of breaking changes to the way the npm ecosystem works (like ignoring the scripts in some cases)

tjones
2021-09-08 23:46
I wonder if this is a problem that happens because of yarn workspaces...

tjones
2021-09-08 23:47
yarn also ignores any error output from packages during install, which makes it hard to debug what's going on (maybe you can configure yarn not to do that, I don't know)

tjones
2021-09-08 23:50
> Error: Timeout of 30000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. This is from your testing framework, not pact.

tjones
2021-09-08 23:51
You'll have to increase both timeouts

rocco.smit
2021-09-09 06:20
has joined #pact-js

jgfarias42
2021-09-09 08:40
Still Yarn 1: Version 1.22.11 I will check the script ignoring - I am new to JS/NPM/Yarn, so it's basically try and error on my side :smile:

andrei_mironau
2021-09-09 10:00
has joined #pact-js

febin.sathar
2021-09-09 10:16
has joined #pact-js

jcaromiq
2021-09-09 11:47
has joined #pact-js

marcin.baranowski953
2021-09-09 12:22
Thanks @tjones I've increased mocha timeout and now it works like a charm :slightly_smiling_face:

tjones
2021-09-09 13:06
Awesome! We have a wrapper for jest that sets up sensible defaults for timeouts etc. Once the pact-js v10 is out, I?m planning to take a look at a similar interface for mocha. Should be a fairly straightforward port I reckon.

jgfarias42
2021-09-09 14:21
Anyway to runt he script manually? If so, I think I can make a workaround. (I will still check if this issues happens on my Jenkins setup)

mirko.zipris
2021-09-09 20:08
has joined #pact-js

tjones
2021-09-10 01:26
No, but you can download the binaries separately

tjones
2021-09-10 01:28
I think 9.16.1 will solve this problem

tjones
2021-09-10 01:30
To summarise: 1. I think you might be hit by a bug that is fixed in 9.16.1. The bug caused pact to not find the binaries (even though they were there) in some cases 2. If the problem is that yarn is not downloading the binaries, then you can download them manually yourself and put them in `<your-project-home>/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63` (but the location changes on different platforms, so you may have frustrations in CI). If that's what's happening, it's a yarn bug - it's supposed to run a `postinstall` script

tjones
2021-09-10 01:33
I looked it up - yarn 1 should still respect the scripts. So, unless you're running `yarn install --ignore-scripts`, I think you're hitting the bug fixed in 9.16.1.

mui_ume
2021-09-10 03:02
i have a body payload that want to match single value instead of range like 2-5 so can I use regular expression using the like from pact to match? ```size: like(/[0-9]+\.[0-9]?/),```

mui_ume
2021-09-10 03:42
it does not work so I use a value here is my github repo https://github.com/LayMui/pactjs-demo/blob/master/__tests__/address.spec.js line 22 unit: 0.1. basically the dev team has change from range 2-5 to a single value. so I like to use pactjs to catch such changes.

dotelnp
2021-09-10 06:48
has joined #pact-js

jgfarias42
2021-09-10 08:01
I guess it's not the same bug, since I am using version 9.16.1 already. I will let you know how it goes on CI.

tjones
2021-09-10 08:12
What do you mean by it does not work?

tjones
2021-09-10 08:12
You can't use `like` in that way


tjones
2021-09-10 08:14
you want to use: ```size: Matchers.term({ generate: '1.2', matcher: '[0-9]+\.[0-9]?' })```

tjones
2021-09-10 08:14
Although, I 'm not sure what you want to achieve with that regular expression

tjones
2021-09-10 08:14
I think it says at least one digit, then a period, and then optionally a digit?

tjones
2021-09-10 08:15
So, ```1123.5 // matches 1. // matches 1.0 // matches 1.124 // does not match```

mui_ume
2021-09-10 08:15
yes. it should not be a range such as 2-5

tjones
2021-09-10 08:15
If you want to match a number ,just use `Matchers.decimal()`

mui_ume
2021-09-10 08:15
2-5, 1-3, does not match becos it?s a range

tjones
2021-09-10 08:16
Pact doesn't support ranges for numbers

tjones
2021-09-10 08:16
Although we probably should

tjones
2021-09-10 08:16
if you say `Matchers.like("1-3")` you are saying "match a string, for example `"1-3"`"

tjones
2021-09-10 08:17
`like` is a convenience matcher that matches on type only.

tjones
2021-09-10 08:38
Ah, apologies! I must have misread

tjones
2021-09-10 08:40
can you tell me what ```ls node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.63``` prints?

tjones
2021-09-10 08:40
and if nothing, what do you get with: ```ls node_modules/@pact-foundation/pact-node/standalone```

tjones
2021-09-10 08:42
what happens if (in your project directory), you type: ``` npx pact-broker version``` and ```npx pact-mock-service``` (you'll need to control-c to get out of that last one, if it is successful)

mui_ume
2021-09-10 08:52
Matchers.decimal() does not work, I got this error TypeError: Cannot read property ?decimal? of undefined

tjones
2021-09-10 08:53
You have to import the matchers. Please see the example in the documentation I linked.

tjones
2021-09-10 08:54
^ Once the native libraries have finished cooking for that release, we'll have promises working properly for V3 state handlers. :raised_hands: :raised_hands: :raised_hands:

mui_ume
2021-09-10 08:54
can I use ```size: like(1.0)```

tjones
2021-09-10 08:54
If you are only wanting to match any number, then yes.

tjones
2021-09-10 08:55
I'm pretty excited about that release.

mui_ume
2021-09-10 08:55
does this match the below? ```1123.5 // matches 1. // matches 1.0 // matches 1.124 // matches```

mui_ume
2021-09-10 08:56
size: 1.0 will only match 1.0 whereeas size: like(1.0) will match any number as well as decimal number, right?


mui_ume
2021-09-10 08:56
got it thanks

matt.fellows
2021-09-10 08:59
Also note, because JS, 1.0 gets converted to 1 and becomes an integer match.

matt.fellows
2021-09-10 08:59
You need to use something like 1.1 in your example otherwise when the provide side runs it will fail

matt.fellows
2021-09-10 09:01
Many a :taco: for you @tjones! I've not kept up with your PRs recently as they're coming in so thick and fast. Looking forward to reviewing my emails when I'm back next week :rolling_on_the_floor_laughing:

tjones
2021-09-10 09:06
Oh, also, this release quietly introduces support for node 16 for the beta branch

sameer.patil
2021-09-10 18:42
has joined #pact-js

b.1.alpha
2021-09-10 19:17
has joined #pact-js

vicenzo
2021-09-10 22:50
Hello!! I think i need some help, trying to get a poc done and my pact file is not being written even though the console logs say they are. (I am on my phone rn, so i can't get to the code snippet). Got my provider.finalize() on the after block, and provider.verify() on afterTest()

matt.fellows
2021-09-11 02:38
When you're back at your desk it's be great to see code and/or logs. If logs say it's written it should be, perhaps it's not where you'd expect?

matt.fellows
2021-09-11 02:38
Also just check that you're correctly handling the functions, both of which are promises

naushad_amin
2021-09-11 23:15
has joined #pact-js

mui_ume
2021-09-13 07:47
how about if the value can be null or undefined? can I use like([1.1, null, undefined])

tjones
2021-09-13 07:53
No. Remember that `like` *only* matches on the type of the example you give it. So if you do this: `like([1.1, null, undefined])`, you are saying "match an array with three items, the first one is a number, the second is null, and the third is undefined. Also, you are setting up a JSON expectation here, and `undefined` doesn't exist in JSON. So, it's more like saying `[number, null, null]`. Lastly, pact works on specific examples, not a schema for appropriate responses. So, if you want to test that the server might produce `null` in some cases, you'll want a separate test for it

jgfarias42
2021-09-13 12:31
The content of pact-node/standalone is only a _pact_ folder. Here is the content of this folder:

jgfarias42
2021-09-13 12:32
The standalone folder has some checksums and installation scripts: (In the real project, we have the same, except the darwin-1.88.63/pact folder.

jgfarias42
2021-09-13 12:40
NPX for the _toy project_ (that is working):

jgfarias42
2021-09-13 12:43
And we get empty results on the _real project, b_ecause the darwin-1.88.63 folder is not there

jose_rodriguez
2021-09-13 13:16
has joined #pact-js

kyle_evans
2021-09-13 13:16
has joined #pact-js

thanuxxxx
2021-09-13 15:31
Am I using `eachKeyLike` correct way? I am getting mismatch error for the following scenario. Can anyone help me out? Here is an example how to use `eachKeyLike` from `pact-js` https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/e2e/test/consumer.spec.js This is a modal response ```const SampleResponse = { categories: { additionalProp1: { id: 'string', items: ['string'], name: 'string', sortOrder: 0, }, additionalProp2: { id: 'string', items: ['string'], name: 'string', sortOrder: 0, }, // Nth additional Prop additionalPropN: { id: 'string', items: ['string'], name: 'string', sortOrder: 0, }, }, };``` So I created a matcher something like this ```const expectation = { categories: eachKeyLike('1SMKX6JGWKY3J', { id: regex(/^[A-Z0-9]+$/,'1SMKX6JGWKY3J'), name: string('Dessert'), sortOrder: integer(3), items: atLeastOneLike(string('F79QJX241ZAHP')), }) }``` Here is the actual response from provider ```const actualResponse = { categories: { '4KS8YA1PY4YPC': { id: '4KS8YA1PY4YPC', name: 'Plain ol\' Crepe', sortOrder: 1, items: ['19AGCTC43X5YC'], }, 'D70N53J6R34K9': { id: '41SJNCEK3FXTJ', name: 'Flavored Crepes', sortOrder: 0, items: ['D70N53J6R34K9'], }, }, }``` This is the mismatch body log ```/* 1.1) body: $.categories Expected 1SMKX6JGWKY3J={"id":"1SMKX6JGWKY3J","items":["F79QJX241ZAHP"],"name":"Dessert","sortOrder":3} but was missing { + "4KS8YA1PY4YPC": { + "id": "4KS8YA1PY4YPC", - "1SMKX6JGWKY3J": { - "id": "1SMKX6JGWKY3J", + "name": "Plain ol' Crepe", - "name": "Dessert", + "sortOrder": 1, - "sortOrder": 3 "items": [ + "19AGCTC43X5YC" + ] - "F79QJX241ZAHP" - ], + }, + "D70N53J6R34K9": { + "id": "D70N53J6R34K9", + "name": "Flavored Crepes", + "sortOrder": 0, + "items": [ + "19AGCTC43X5YC" + ] } */``` It works fine when I feed the actual key into the matcher something like this ```const expectation = { categories: eachKeyLike('4KS8YA1PY4YPC', { id: regex(/^[A-Z0-9]+$/,'4KS8YA1PY4YPC'), name: string('Dessert'), sortOrder: integer(3), items: atLeastOneLike(string('F79QJX241ZAHP')), }) }``` I suspect I am using `eachKeyLike` method in a wrong way? Any ideas?

rahul.louis
2021-09-13 15:55
has joined #pact-js

a.koka
2021-09-13 17:01
has joined #pact-js

efloresambrosio
2021-09-13 20:09
has joined #pact-js

matt.fellows
2021-09-13 22:43
hmmm it looks correct to me

matt.fellows
2021-09-13 22:43
what does your provider verifier look like?

thanuxxxx
2021-09-13 22:48
What do you mean by that? I have this for provider side ``` @TestTemplate @ExtendWith(PactVerificationSpringProvider.class) void pactVerificationTestTemplate(PactVerificationContext context) { context.verifyInteraction(); }```

matt.fellows
2021-09-13 22:51
which version of Pact JVM are you using?

matt.fellows
2021-09-13 22:51
can you please also share the relevant pact file (or interactions within the pact file?)

thanuxxxx
2021-09-13 22:52
Version `4.1.16`

thanuxxxx
2021-09-13 22:58
```{ body: { categories: { '1SMKX6JGWKY3J': { id: '1SMKX6JGWKY3J', items: ['F79QJX241ZAHP'], name: 'Dessert', sortOrder: 3, }, }, }, matchingRules: { body: { '$.categories': { combine: 'AND', matchers: [ { match: 'values', }, ], }, '$.categories.*.id': { combine: 'AND', matchers: [ { match: 'regex', regex: '^[A-Z0-9]+$', }, ], }, '$.categories.*.items': { combine: 'AND', matchers: [ { match: 'type', min: 1, }, ], }, '$.categories..items[]': { combine: 'AND', matchers: [ { match: 'type', }, ], }, '$.categories.*.name': { combine: 'AND', matchers: [ { match: 'type', }, ], }, '$.categories.*.sortOrder': { combine: 'AND', matchers: [ { match: 'integer', }, ], }, }, }, };```

tjones
2021-09-13 23:36
Yes, this supports the theory that it wasn't downloaded correctly when install was run

tjones
2021-09-13 23:36
did you try removing `node_modules` and running install again, and what logs were printed when you did that?

matt.fellows
2021-09-14 00:23
it looks correct to me

matt.fellows
2021-09-14 00:23
@uglyog any ideas?

uglyog
2021-09-14 00:26
The values matcher is not being applied properly. I think it is an issue with Pact-JVM.

uglyog
2021-09-14 00:27
Can you raise an issue with Pact-JVM?

matt.fellows
2021-09-14 00:41
Thanks for checking Ron

thanuxxxx
2021-09-14 00:44
Okay done

matt.fellows
2021-09-14 00:48
Might be worth tinkering with the JVM version to see if a previous one works

thanuxxxx
2021-09-14 00:50
Sure will give a try. Thank you guys

mui_ume
2021-09-14 01:24
ok so if the value is null, it will still match like(1.1)?

matt.fellows
2021-09-14 01:50
no, `null` is not a number


mui_ume
2021-09-14 02:27
ok so I can just leave that data field to accept anything then? becos I still want to have pact test for shift left strategy for the microservices API

matt.fellows
2021-09-14 02:34
If your consumer test doesn?t use that field, it?s irrelevant what you put in that field. You *should not* include it if you don?t need it in your test

matt.fellows
2021-09-14 02:34
if you need it to be `null` , you should write a test that expects that. If you need it to be a float, you should write a separate test for that scenario

olle_hallin
2021-09-14 05:50
has joined #pact-js

divyalakshmi.gk
2021-09-14 06:00
Hello everyone, I am facing an issue with verification Pact broker status . Its showing Unverified. The test cases are passing in consumer and provider end. need your help to have a look on that, if anything I  am missing in the code or publishing part. The Provider is written in NodeJS, Typescript and pact test cases using jest- jasmine. In the attachment below: The first one client-testing - provider-testing, I have created for a pact test for another API. It is showing Unverified. The pact tests are passing locally. The second one otp-client- digix , was already published. Here I am adding pact testing to one more API and trying to publish it separately and its failing Can you please guide me to debug this issue. am sharing the screenshot of the PACT Flow

tjones
2021-09-14 06:15
Are you publishing your verification status from the verifier?

tjones
2021-09-14 06:15
What version of pact-js are you using?

tjones
2021-09-14 06:15
Can you share your configuration for the `Verifier` call?


matt.fellows
2021-09-14 07:04
You would usually only publish verification results from your CI servers

matt.fellows
2021-09-14 07:05
you can either explicitly set it to publish (as per the above docs)

matt.fellows
2021-09-14 07:05
or set this env var `PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true`

matt.fellows
2021-09-14 07:05
For clarity, we _don?t_ recommend doing this from your dev machine, because you may do that whilst still developing the feature, and invalidate any `can-i-deploy` results

matt.fellows
2021-09-14 07:05
I?d highly recommend doing this workshop: https://docs.pactflow.io/docs/workshops/ci-cd/

a.babenko
2021-09-14 14:00
has joined #pact-js

vasavi.balanagu
2021-09-14 16:49
has joined #pact-js

samuel.sjoberg
2021-09-14 21:49
has joined #pact-js

domingo
2021-09-14 23:51
has joined #pact-js

pradeepkumarstudent20
2021-09-15 03:32
has joined #pact-js

jgfarias42
2021-09-15 11:35
Hi Timothy. I am not so expert on node, but it seems my project has different modules (two package.json). Someone had already defined the pact-js and jest-pact dependencies on another package.json and when I did the "master" yarn install, it mess up. I removed the duplication and it seems to be ok now. Thank you for all the investigation and guidance.

sushant.soni
2021-09-15 12:18
Hello everyone, I am trying to support multiple provider states in an interaction on the provider side. But I couldn?t find any example for the same. Can someone please point me to a resource I can refer to?

matt.fellows
2021-09-15 12:19
are you using the new v3 package, or the current stable?

matt.fellows
2021-09-15 12:20
on the provider side, supporting multiple states is simple - you create state handlers for each state you need to support, and pact will call 0 or more of them

sushant.soni
2021-09-15 12:23
v3

sushant.soni
2021-09-15 12:25
Is my understanding incorrect when I say that the consumer wants 2 states which are interdependent. For example 1. User is logged in 2. User has a product in the wishlist 2nd is possible only after 1.

matt.fellows
2021-09-15 12:30
those states look like good states to me

matt.fellows
2021-09-15 12:31
I may be incorrect about this, but there is no ordering as far as I?m aware of

matt.fellows
2021-09-15 12:35
You could also create a state ?User is logged in and has a product in the wishlist?

matt.fellows
2021-09-15 12:35
If you want to be able to re-use states on the provider, then one must be unaware of the other

matt.fellows
2021-09-15 12:36
If they are coupled, then I?d just create a single state for that scenario

sushant.soni
2021-09-15 12:36
Perfect, that clears a lot.

sushant.soni
2021-09-15 12:36
This might be a #general question, but what do you recommend while setting up provider states, return a mock response data or from a real service?

matt.fellows
2021-09-15 12:45
mock data


tjones
2021-09-15 13:53
It depends what you mean by "real service". I usually mock at the boundary to any repository layers internally in the provider

tjones
2021-09-15 13:54
This means that the provider's business logic is executed during the test. It's best practice not to try to exercise the business logic with the pact test, but I think it's good if the tests have some coverage of the business logic (if that makes sense)

tjones
2021-09-15 13:57
You're welcome! Glad it's sorted!

bryan
2021-09-15 15:16
has joined #pact-js

bryan
2021-09-15 15:20
I?m contracting for a company that has a strict policy about which software can run on our computers. We can get the standalone binaries approved and put into the company?s ?software center? so it?s already installed on our systems, but I?ve looked through the docs and some of the source code and can?t seem to find a way to point pact to these approved binaries. Am I missing something?

paulorochag
2021-09-15 15:44
Guys, my contract test is breaking and I believe it is because of the query params, can you provide me with support? I'm not really sure what's going on, but it's returning exactly what he expected.

paulorochag
2021-09-15 18:29
Again with other route :confused:

dboxler
2021-09-15 18:35
has joined #pact-js

paulorochag
2021-09-15 19:00
I believe I discovered the problem. In the consumer, I'm implementing: ```query: { autoDispatch: 'false', },``` But in the _pact.log_ the interaction is getting like ``` "query": { "autoDispatch": [ "false" ] },```

paulorochag
2021-09-15 19:01
@tjones, @matt.fellows

paulorochag
2021-09-15 21:06
in fact what I showed in the screenshot above is not a error, I saw that it is right. I've analyzed it again and it looks like the test request ('http://cipagarmeApi.post') is running before the interaction is registered ('addInteraction'). I will try to understand why in some tests, intermittently, the request is made before the interaction. If you have some light while I investigate it would be a great help.

tjones
2021-09-15 21:55
Thanks- the problem is that you have to wait for the provider to add the interaction before you can start your test. You can do this by returning the result from addInteraction in your before call

matt.fellows
2021-09-15 22:43
You can do it


matt.fellows
2021-09-15 22:43
Apologies, those docs were removed in the latest version because we?re going to bundle it into the package

matt.fellows
2021-09-15 22:44
but that should temporarily get you going, whilst we get that into all of the Pact JS releases

tjones
2021-09-15 22:48
Or using async/await as you do in your test

keerthisiv
2021-09-16 03:59
has joined #pact-js

adelina.simion
2021-09-16 08:41
has joined #pact-js

sushant.soni
2021-09-16 08:52
my provider calls another microservice to fetch some data. So should we always use the actual data from this microservice or should we stub it?

tjones
2021-09-16 08:58
I usually stub within your provider

tjones
2021-09-16 08:58
eg, your provider's code looks something like this: ```controller -> service -> otherMicroserviceClient``` then it makes a network call to the other microservice

tjones
2021-09-16 08:59
instead of mocking the network call, I would mock the client interface internally in your provider

tjones
2021-09-16 09:00
that way you can express your mock as: ```getUser("STEVE") will return someMockUser``` instead of all the gory details of however that request works

akke.luukkonen
2021-09-16 10:29
has joined #pact-js

alejandro.pena
2021-09-16 13:37
has joined #pact-js

bryan
2021-09-16 14:03
How do I tell pact to use a binary installed on my system instead of the downloaded one?


bbleach
2021-09-17 07:30
has joined #pact-js

sushant.soni
2021-09-17 13:35
Hi Whenever my provider encounters multiple provider states in the pact, it is not able to set those up. This is what I get from the DEBUG logs ```pact-node@10.13.7: DEBUG: Setting up provider state '' for consumer 'xyz' using provider state set up URL http://localhost:56438/_pactSetup``` and ```pact@9.16.1: No state handler found for "null", ignoring```

sushant.soni
2021-09-17 13:39
CC: @tjones

matt.fellows
2021-09-17 13:42
You need to use the v3 beta, please see the readme. The current stable package is not v3 compatible (which is the spec where multiple states were supported)

sushant.soni
2021-09-17 13:57
Thanks :slightly_smiling_face: trying that now

sushant.soni
2021-09-17 15:08
Thanks Matt, works like a charm!

paulorochag
2021-09-17 15:19
Timothy, that async/await suggestion was what we implemented and it worked.

tjones
2021-09-17 15:54
Glad to hear you got it working! Let us know if you have further questions

divyalakshmi.gk
2021-09-20 04:33
@tjones Verifier config details is as below: const opts = { logLevel: 'info', providerBaseUrl: 'http://localhost:8080', provider: 'provider-testing', providerVersion: '1.0.0', pactBrokerUrl, pactBrokerToken, stateHandlers: { 'Returns the Id details of 5cbd5f90':IdDetails, }, if (http://process.env.CI || process.env.PACT_PUBLISH_RESULTS) { Object.assign(opts, { publishVerificationResult: true, }); } return new Verifier(opts).verifyProvider().finally(() => { api.stop(); });

matt.fellows
2021-09-20 04:51
What does the terminal output look like when you run it?

divyalakshmi.gk
2021-09-20 05:04
Provider output:

divyalakshmi.gk
2021-09-20 05:04
consumer output:

divyalakshmi.gk
2021-09-20 05:14
Publishing results:

divyalakshmi.gk
2021-09-20 05:16
pact broker after publishing:

matt.fellows
2021-09-20 06:10
I don?t understand

matt.fellows
2021-09-20 06:10
it seems like your provider test is publishing a Pact, that?s confusing

matt.fellows
2021-09-20 06:10
the provider verifies a pact that a _consumer_ publishes

matt.fellows
2021-09-20 06:11
That terminal output is definitely not the output i?d expect to see if running the verifier code you shared above

rushideshpandes
2021-09-20 13:11
has joined #pact-js

gemhar
2021-09-20 14:33
has joined #pact-js

bryan
2021-09-20 14:37
@matt.fellows this tells me where to put the zip/tarball so the install script can unzip it itself? in this case, I have to have Software Center install the pact binaries so it sets the special security flag so it has permission to run? the zip/tarball is already unzipped/untarred and I need to tell pact where to run the executable from

vicenzo
2021-09-20 21:25
finally remembered tocome back

vicenzo
2021-09-20 21:26
```2021-09-20T21:19:41.585Z INFO @wdio/local-runner: Shutting down spawned worker [2021-09-20 21:19:41.589 +0000] INFO (24191 on Vicenzos-MBP): pact@9.16.1: Pact File Written [2021-09-20 21:19:41.589 +0000] INFO (24191 on Vicenzos-MBP): pact-node@10.13.7: Removing Pact process with PID: 24205 [2021-09-20 21:19:41.591 +0000] DEBUG (24191 on Vicenzos-MBP): pact-node@10.13.7: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2021-09-20 21:19:41.593 +0000] INFO (24191 on Vicenzos-MBP): pact-node@10.13.7: Deleting Pact Server with options: {"consumer":"WebApp","cors":true,"dir":"/Users/vicenzo/Code/app/tests/pacts","host":"127.0.0.1","log":"/Users/vicenzo/Code/app/logs/pact.log","pactFileWriteMode":"overwrite","port":58919,"provider":"Backend","spec":2,"ssl":false,"timeout":30000} 2021-09-20T21:19:41.839Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully 2021-09-20T21:19:41.840Z INFO @wdio/local-runner: shutting down```

vicenzo
2021-09-20 21:27
```export const pactServer = new Pact({ consumer: "WebApp", provider: "Backend", log: path.resolve(process.cwd(), "logs", "pact.log"), dir: path.resolve(process.cwd(), "tests", "pacts"), logLevel: "debug", cors: true }); export const publisher = new Publisher({ publishVerificationResult: true, pactBroker: 'http://localhost:9292', consumerVersion: version, pactFilesOrDirs: [path.resolve(process.cwd(), "tests", "pacts")], }); const server = exec('gulp start-pact-dev'); exports.config = merge(wdioConf.config, { baseUrl: 'http://localhost:8083', specs: [ './tests/webdriverio/specs/**/*.pact.js' ], exclude: [ './tests/webdriverio/specs/**/*.e2e.js' ], onPrepare: async function (config, capabilities) { server.stdout.pipe(process.stdout); pactServer.setup().then(() => pactServer.addInteraction(LoginInteraction)); }, afterTest: function () { pactServer.verify(); }, after: function () { pactServer.finalize(); }, onComplete: function () { server.on('exit', function() { process.exit(); }); pactServer.finalize(); } });```

jsegall
2021-09-20 21:37
has joined #pact-js

vicenzo
2021-09-20 22:26
sorry to ping you @matt.fellows

matt.fellows
2021-09-21 11:28
Verify and finalize are both promises, that may be the cause as they don't appear to be handled

dalkire
2021-09-21 13:30
has joined #pact-js

mathias.duesterhoeft
2021-09-21 14:51
Hi there :wave: in version `10.0.0-beta.44` I could still pass in `pactBrokerUrl` as `undefined` and pass in `pactUrls` to use local contract files instead of a remote broker. in `10.0.0-beta.48` the tests fail with `Failed to load pact - Could not load pacts from the pact broker 'undefined' - UrlError("relative URL without a base")` If I do not pass in `pactBrokerUrl` at all (instead of `undefined`) I even get a crash of the native binary. ```[2021-09-21T14:46:41Z ERROR pact_ffi::verifier::verifier] error verifying Pact: "error: The following required arguments were not provided:\n --broker-url <broker-url>...\n --dir <dir>...\n --url <url>...\n\nUSAGE:\n pact_verifier_cli --broker-url <broker-url>... --consumer-version-selectors <consumer-version-selectors>... --dir <dir>... --file <file>... --hostname <hostname> --loglevel <loglevel> --password <password> --port <port> --provider-name <provider-name> --provider-version <provider-version> --request-timeout <request-timeout> --scheme <scheme> --state-change-url <state-change-url> --url <url>... --user <user>\n\nFor more information try --help" Error { message: "error: The following required arguments were not provided:\n --broker-url <broker-url>...\n --dir <dir>...\n --url <url>...\n\nUSAGE:\n pact_verifier_cli --broker-url <broker-url>... --consumer-version-selectors <consumer-version-selectors>... --dir <dir>... --file <file>... --hostname <hostname> --loglevel <loglevel> --password <password> --port <port> --provider-name <provider-name> --provider-version <provider-version> --request-timeout <request-timeout> --scheme <scheme> --state-change-url <state-change-url> --url <url>... --user <user>\n\nFor more information try --help", kind: MissingRequiredArgument, info: None } [2021-09-21 14:46:41.651 +0000] INFO (82237 on HAMACL00334): pact@10.0.0-beta.48: Verifying provider [2021-09-21 14:46:41.657 +0000] INFO (82237 on HAMACL00334): pact@10.0.0-beta.48: debug request/response logging enabled [2021-09-21 14:46:41.661 +0000] INFO (82237 on HAMACL00334): pact-core@13.1.6: Verifying Pacts. [2021-09-21 14:46:41.662 +0000] INFO (82237 on HAMACL00334): pact-core@13.1.6: Verifying Pact Files [2021-09-21 14:46:41.725 +0000] DEBUG (82237 on HAMACL00334): pact-core@13.1.6: sending arguments to FFI: [2021-09-21 14:46:41.726 +0000] DEBUG (82237 on HAMACL00334): pact-core@13.1.6: --request-timeout 30000 --loglevel debug --state-change-url http://localhost:57400/_pactSetup --provider-name vehicle-mission-sync --port 57400 --hostname localhost --consumer-version-selectors {"latest":true,"consumer":"some"} --user undefined --password undefined --provider-version 1 --file /path/to/contract.json [2021-09-21 14:46:41.750 +0000] DEBUG (82237 on HAMACL00334): pact-core@13.1.6: response from verifier: null, 4 [2021-09-21 14:46:41.750 +0000] ERROR (82237 on HAMACL00334): pact-core@13.1.6: !!!!!!!!! PACT CRASHED !!!!!!!!! The underlying pact core was invoked incorrectly. This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it. There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output. SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world. We're sorry about this!``` Is this a bug? Or am I missing something.

vicenzo
2021-09-21 16:04
with async/await?

hakan.celebi
2021-09-21 19:43
has joined #pact-js

matt.fellows
2021-09-22 00:54
Yes, that?s one way and assuming that code supports it. Looking at it, it looks to be in a callback, so you would need to consult the docs of the tool you?re usinsg to ensure you handle it correctly

matt.fellows
2021-09-22 00:54
Sometimes you can simply return the promise

matt.fellows
2021-09-22 00:57
It?s a bug somewhere :stuck_out_tongue:

matt.fellows
2021-09-22 00:57
The issue is (tested by running the Verifier CLI, which is essentially what Pact JS calls) the consumer version selectors are there - they require a broker configuration

matt.fellows
2021-09-22 00:58
The error message for the verification options aren?t ideal, and something we will definitely need to fix (and are, slowly)

univ.anirudh
2021-09-22 05:56
Is it idiomatic to use 'hard-coded' ID values and exact strings for defining provider states in both the consumer and provider test code? For example, if I'm testing with a required provider state - `there exists a resource with id <x>` , the exact same thing will need to be written on the provider verification test, including the same value for `<x>` (unless I have a wrong understanding of the docs). Would I need to make sure that the values here are exactly the same across both the participants? Or is there some leniency w.r.t letter casing etc?

mathias.duesterhoeft
2021-09-22 06:27
Oh - thanks a lot - I will give this a try.

abubics
2021-09-22 06:49
there are a few approaches, that's definitely one of them.

abubics
2021-09-22 06:51
Whatever approach you choose, somewhere along the line you have to coordinate on state - whether you use ? explicit values in state names, or ? implicit value only hinted at by state names, or ? in later versions of the state(s) spec, actual meta(data).

abubics
2021-09-22 06:52
you can also eschew all variant values, flexibly matching them away, and only assert on specific invariant values (e.g. IDs passed in match IDs coming back out)

univ.anirudh
2021-09-22 06:53
Do later versions of the spec allow us to pass values from the consumer for state that the provider can pick up? So the consumer could pass in, say, the resource ID while defining the state, and the provider would not need to be aware of that and could take it as a dynamic input while the verification process is going on?

abubics
2021-09-22 06:55
yeahh, something like that . . . I haven't used it yet, but I've read people talking about it in Slack

abubics
2021-09-22 06:55
I think it's in v3 or v4

univ.anirudh
2021-09-22 06:56
Ahh. That's a bit away, at least for JS. Just trying to set up a process that would be the easiest to maintain for our team. Thanks, this helped!

matt.fellows
2021-09-22 07:04
`valueFromProviderState` is the method that I think it?s called in the latest JS code (beta) and in some languages (e.g. JVM, Go)

matt.fellows
2021-09-22 07:05
It really solves the problem where you can?t control identifiers on the provider side and provider states. Hopefully in most cases, you have granular control over your provider code duration verification, and can use mocking and other common testing tools to set up data or system states as needed.

tjones
2021-09-22 07:10
Why are you passing in options but setting them to `undefined`? What are you expecting to happen?

tjones
2021-09-22 07:10
In that example, it looks like pactBrokerUser and pactBrokerPassword are probably set, but undefined.

tjones
2021-09-22 07:11
Can you share the config that you're using?

tjones
2021-09-22 07:12
I suppose that we can make pact-js handle this case, but I think the bug is in the config if you're setting options explicitly to undefined, as this is not valid (if the documentation suggests it is, then we should update it)

tjones
2021-09-22 07:13
It's a trivial change to make it ignore settings explicitly set to undefined, but I think it's probably better to throw an error, as I think it's more likely an error than intentional

mathias.duesterhoeft
2021-09-22 07:14
We run our verification tests in CI against a real broker. But on a local developer machine we do not want this - instead we use local version of the contract. So I have some common code that e.g. sets the `pactBrokerUrl` from an env variable - or `undefined` if the env variable is not there. But I can easily change this - but also - Also without this the tests failed - complaining that the `pactBrokerUrl` was not set.

mathias.duesterhoeft
2021-09-22 07:15
The hint from @matt.fellows helped though - I only set `consumerVersionSelectors` when connecting with a broker

mathias.duesterhoeft
2021-09-22 07:16
So thanks a lot for your support!

mathias.duesterhoeft
2021-09-22 07:17
Moving from version `https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.454` to `https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.458` my tests start failing because now also the metadata in the contract is verified. Can I switch this off somehow.

matt.fellows
2021-09-22 07:18
no you can?t

tjones
2021-09-22 07:18
You're welcome! I'd like to improve this case, especially if it used to (silently) work before. What do you think? Do you think we should accept `pactBrokerUrl: undefined` and potentially mask config errors, or do you think we should throw an error suggesting to not set it at all?

matt.fellows
2021-09-22 07:18
If the metadata is important, you should validate it. If not, you should remove it from the pact test

mathias.duesterhoeft
2021-09-22 07:19
I can only say that it is convenient - and TypeScript did not complain - so your types seem to allow to pass undefined. In that case I think the code should not make a difference between `undefined` and not passed.

matt.fellows
2021-09-22 07:20
It doesn?t help that the verifier feedback is really unreadable/incomprehensible

matt.fellows
2021-09-22 07:21
The error is kind of hidden in there, but it?s certainly not user friendly

mathias.duesterhoeft
2021-09-22 07:21
> If not, you should remove it from the pact test Do you mean "remove it from the contract"? My test is not providing metadata - but they are defined in the contract.

matt.fellows
2021-09-22 07:21
It would be better if Pact JS Core receieved structured validation errors, and then we could present it better

matt.fellows
2021-09-22 07:21
alternatively, we restrict the inputs - but the downside of that is we need to maintain what?s possible

tjones
2021-09-22 07:21
Interesting. I thought typescript only allowed `undefined` if it was explicitly set in the types, not just optional, but you're right.

tjones
2021-09-22 07:22
In that case it should behave appropriately. I'll update the code

matt.fellows
2021-09-22 07:22
One option Tim is to split the configuration - not just a single `Verifier` but to have a `PactBrokerVerifierConfiguration` and a `LocalPactVerifierConfiguration` etc. type thing with the appropriate options. That would give better type hints then

mathias.duesterhoeft
2021-09-22 07:23
I also scratched my head about that one - `pactBrokerUrl?: string` allows to pass `undefined`

matt.fellows
2021-09-22 07:23
the verifier could accept any of them, or we provide different verification methods

tjones
2021-09-22 07:23
So, we stopped verifying the combinations of options before sending them to the binary because the binary couldn't update what was valid without also requiring a change to pact-js (and all other frameworks). But, maybe what we should do is detect that it failed in this way (which we already do), and THEN run type verification.

matt.fellows
2021-09-22 07:23
the `?` means `undefined | string`

tjones
2021-09-22 07:24
This would mean that we'd go "it failed due to the wrong arguments - do we know why?"

tjones
2021-09-22 07:24
Yes, I think that type split is a good idea - although it only helps typescript users, so I think we should do it in code too.

tjones
2021-09-22 07:24
Also it means that for typescript users we have really unhelpful error messages

tjones
2021-09-22 07:25
it'll be like `pactBrokerUrl is not valid on the type <large confusing description of types>`

matt.fellows
2021-09-22 07:26
I always find having multiple types on a function arguments hard to read, so perhaps a separate function is actually better - each function accepts only a specific type


tjones
2021-09-22 07:27
That feels unhelpful, and will make migration harder

matt.fellows
2021-09-22 07:27
well, yes more specifically, remove it from the _consumer_ pact test

matt.fellows
2021-09-22 07:27
which, yes, will remove it from the contract

mathias.duesterhoeft
2021-09-22 07:27
Ah - I see - thanks.

tjones
2021-09-22 07:28
In the short term (next 20 minutes + 30 minutes release time) I will make it accept but warn if you say `pactBrokerUrl: undefined`

tjones
2021-09-22 07:30
Something like `The verifier option 'pactBrokerUrl' was explicitly set to undefined and will be ignored. This may be an error in your config. Remove the option entirely to get rid of this warning`

tjones
2021-09-22 07:36
Also, if we separate the types, we might prevent valid combinations. For example, you should be able to provide pacturls and a broker

matt.fellows
2021-09-22 07:36
Apologies, it really should have forced validation from the start, but we didn?t yet have the facility

matt.fellows
2021-09-22 07:37
that?s true. I was going to make the same case but got distracted by anohter thread :stuck_out_tongue:

tjones
2021-09-22 07:37
I think it'll get complex quickly. Even just with local vs remote, you could have the type be: ```PactBrokerVerifierConfiguration | LocalPactVerifierConfiguration | (PactBrokerVerifierConfiguration & LocalPactVerifierConfiguration)```

matt.fellows
2021-09-22 07:38
deferring validation to the core makes the most sense, and getting it to be helpful - this way all of the languages benefit and we do it once



mathias.duesterhoeft
2021-09-22 07:39
It makes sense I think.

mathias.duesterhoeft
2021-09-22 07:39
I was just searching for a quick fix. But properly validating the metadata is possible and increases the value of the test :+1:

matt.fellows
2021-09-22 07:59
I wanted to say ?we could look at an option to disable that? but I think it?s best we don?t. Once there is an assertion made on the consumer side, you would expect it to be verified!

tjones
2021-09-22 08:00
@mathias.duesterhoeft: v10.0.0-beta.51 is now cooking, let us know if you have any issues (it should be fully released in about 30-40 minutes)

matt.fellows
2021-09-22 08:04
Also, just reflecting on how much I :hearts: this:

mathias.duesterhoeft
2021-09-22 08:19
Btw - are `matchingRules` supported for `metaData` ? I have this but still the value itself is matched... ```"matchingRules": { "body": { //... }, "metaData": { "$.traceId: { "combine": "AND", "matchers": [{ "match": "type" }] }, } }, "metaData": { "traceId": "d3_7404" },```

matt.fellows
2021-09-22 08:21
good question. I actually didn?t think they were matchable, but it?s interesting that it let?s you do it

mathias.duesterhoeft
2021-09-22 08:25
My problem is that the matchers are not taken into account. For example the traceId in the metadata is different every time the consumer publishes the contract. So matching by value is just not feasible.

matt.fellows
2021-09-22 08:37
Could you please raise a request? It seems like something we should support

mathias.duesterhoeft
2021-09-22 08:38
Sure - would that be `pact-js` or `pact-js-core` ?

tjones
2021-09-22 09:11
Release is complete!

tjones
2021-09-22 09:25
Yeah, it has really helped with bug reports. I'm looking forward to overhauling all the logs so they're much nicer in general

matt.fellows
2021-09-22 11:24
Pact JS is fine, we?ll raise from there to wherever it needs to go

matt.fellows
2021-09-22 11:24
(probably needs to be exposed in the rust core)


matt.fellows
2021-09-22 11:46
Just saw it in #pact-js-development - thanks! :pray:

bryan
2021-09-22 14:03
@matt.fellows any advice here?

nrobison
2021-09-22 15:39
has joined #pact-js

sushant.soni
2021-09-22 15:51
Hello I am getting such error with the verification ``` $.data.products.0.meta.xyz.2 -> Expected 'DEQ17BY455455' to match '(.*?)'``` What am I missing?

sushant.soni
2021-09-22 16:05
For more info: The pact was generated from Pact-JVM a v3, and verified using pact-js@beta

calise
2021-09-22 17:06
has joined #pact-js

calise
2021-09-22 17:11
I'm getting the ENOENT error out of the box with the example project

calise
2021-09-22 17:15
Hi - I just tried to run the example project for node + jest consumer and I'm getting an ENOENT error from the pact-node-service. I'm not able to find anything on stackoverflow. I did a brief search here and found a suggestion to remove and reinstall node modules with latest node but that didn't work. Any suggestions?

calise
2021-09-22 17:26
I see that it's trying to spawn using darwin-1.88.63

calise
2021-09-22 17:27
And that binary does not exist in my node_modules folder

nrobison
2021-09-22 17:38
Hey folks. I have a question regarding number handling. We have a Java API that we're writing pacts against. One field returns either a number (e.g. 5000) or the string "Infinity". I tried to write a custom term for the field, but it's throwing type error. Any thoughts on this? Totally possible I'm doing it incorrectly. Here's my custom term: ```exhaustion: term({ matcher: "Infinity|^[+-]?([1-9]\\d*|0)(\\.\\d+)?", generate: 500000000 })```

matt.fellows
2021-09-22 20:35
Can you please share you npm install logs?

matt.fellows
2021-09-22 20:36
Are you on. Corporate machine? It's possible that artifact is being blocked

matt.fellows
2021-09-22 20:36
You can't write a regex for a number or a string

matt.fellows
2021-09-22 20:37
You need two tests - one for when it's a number and another for when it's Infinity

leonardo.viana
2021-09-22 20:38
Hi all. Any updates on approximately when pact-js v3 will be out of beta and released for generally availability?

sushant.soni
2021-09-22 20:45
@matt.fellows This works fine when the pact is v2. Do you know how can we work around this problem? or maybe even the root cause?

vicenzo
2021-09-22 21:36
:ok_hand:

matt.fellows
2021-09-22 22:04
Oh, sorry Bryan I missed this update

matt.fellows
2021-09-22 22:11
Could you please raise a request on the pact-js-core repo? We?ll look to bundle it into the actual package, so you don?t have to move it

matt.fellows
2021-09-22 22:12
currently, you can?t move the file elsewhere. That could also be done, but it would be better to not have to download it at all

matt.fellows
2021-09-22 22:55
Soon!

matt.fellows
2021-09-22 22:55
See https://github.com/pact-foundation/pact-js/projects/3, a lot of the bigger bits are done

matt.fellows
2021-09-22 22:59
The board is up to date, or very close to. You can see the remaining items before a release in the TODO column

matt.fellows
2021-09-22 22:59
Kudos to @tjones who?s been making some great progress

uglyog
2021-09-22 23:18
That is a strange regex. It will match everything, including nothing, and then capture the result

uglyog
2021-09-22 23:21
pact-js@beta is using a different regex implementation than pact-js v2. You might want to change your regex to be something like `[A-Z0-9]+`

sushant.soni
2021-09-23 07:43
Thanks, I?ll check this out.

nareshnavinash
2021-09-23 09:28
has joined #pact-js

radu.simu
2021-09-23 09:38
has joined #pact-js

aterrong
2021-09-23 09:42
has joined #pact-js

nisharaveendran30
2021-09-23 10:34
has joined #pact-js

sujithsukumaranm
2021-09-23 10:36
has joined #pact-js

sureshbabudevaki
2021-09-23 12:01
has joined #pact-js

greg.hinsley
2021-09-23 12:29
has joined #pact-js

bryan
2021-09-23 13:51
I?m not sure I?m making myself clear: in order to use pact in this company?s enterprise environment, the executables MUST be installed by Software Center? pact cannot install them

matt.fellows
2021-09-23 21:34
Sure, please raise a request then and we can look at it

matt.fellows
2021-09-23 21:35
I'd suggest looking at our beta, it doesn't use an executable and removes this need. We're closing in on releasing a major release of it

bryan
2021-09-23 21:48
what does it do in lieu of an executable?

bryan
2021-09-23 22:08
@matt.fellows

matt.fellows
2021-09-23 22:13
It uses a C library

bryan
2021-09-23 22:14
interesting? I?ll have to try it out on Monday and see if it works in this customer?s environment

thanuxxxx
2021-09-24 03:29
@matt.fellows So it seems like after `JVM version: 4.2.8,` the issue doesn't appear

matt.fellows
2021-09-24 03:34
thanks for following up

nyman.robin
2021-09-24 07:07
has joined #pact-js

francislainy.campos
2021-09-24 10:18
Hi, good morning. So I?m trying to run my pact tests but am getting this error. Thank you.

francislainy.campos
2021-09-24 10:20
```{ "name": "gatling_tool", "version": "0.1.0", "private": false, "dependencies": { "@ant-design/icons": "latest", "@material-ui/core": "^4.11.0", "@material-ui/icons": "^4.9.1", "@material-ui/lab": "^4.0.0-alpha.56", "@pact-foundation/pact-node": "^10.11.0", "@testing-library/user-event": "^7.2.1", "antd": "4.8.0", "axios": "^0.20.0", "bootstrap": "^4.5.2", "cors": "^2.8.5", "express": "^4.17.1", "hookrouter": "^1.2.3", "jquery": "^3.5.1", "moment": "^2.29.1", "popper.js": "^1.16.1", "react": "^16.13.1", "react-bootstrap": "^1.3.0", "react-csv": "^2.0.3", "react-dom": "^16.13.1", "react-dragger": "^1.3.0", "react-scripts": "3.4.3", "react-table": "^7.1.0", "startbootstrap-simple-sidebar": "^5.1.2" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "./node_modules/.bin/mocha 'src/pact_old/**/*.pact.js'", "eject": "react-scripts eject", "test:consumer": "mocha --exit --timeout 30000 src/draft/consumer.pact.spec.js", "test:provider": "mocha --exit --timeout 30000 provider.pact.spec.js", "publish": "npx pact-broker publish ./pacts --consumer-app-version 1.0.0-someconsumersha --tag master", "can-deploy:consumer": "npx pact-broker can-i-deploy --pacticipant gatling-consumer --version 1.0.0-someconsumersha --to prod", "can-deploy:provider": "npx pact-broker can-i-deploy --pacticipant gatling-provider --version 1.0.0-someprovidersha --to prod", "deploy:consumer": "npx pact-broker create-version-tag --pacticipant gatling-consumer --version 1.0.0-someconsumersha --tag prod", "deploy:provider": "npx pact-broker create-version-tag --pacticipant gatling-provider --version 1.0.0-someprovidersha --tag prod" }, "eslintConfig": { "extends": "react-app" }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] }, "devDependencies": { "@pact-foundation/pact": "^10.0.0-beta.21", "@testing-library/jest-dom": "^4.2.4", "@testing-library/react": "^9.5.0", "chai": "^4.2.0", "jest-pact": "^0.8.1", "mocha": "^8.1.3", "prop-types": "^15.7.2", "react-router-dom": "^5.2.0" } }```

ricardo.paquito
2021-09-24 10:36
has joined #pact-js

abramenkov.valentin
2021-09-24 12:42
has joined #pact-js

leo.tang
2021-09-24 17:56
has joined #pact-js

tjones
2021-09-24 22:15
Which version of the beta are you using? This "^10.0.0-beta.21" will select one of them - and it might be one of the broken ones.

tjones
2021-09-24 22:16
The latests is 10.0.0-beta.51, try that

tjones
2021-09-25 00:35
If you don?t need the spec version 3 features, then the main release (9.x.x) is the stable one

jyotiguptaofficial
2021-09-25 13:00
has joined #pact-js

jyotiguptaofficial
2021-09-25 13:04
Hi Folks, I am trying to run the pact test at react consumer side : https://github.com/thombergs/code-examples/tree/master/pact/pact-react-consumer [Repo Link] While running the pact at client side with command : yarn test:pact:graphql . I am getting following error. Can someone help for the same.

francislainy.campos
2021-09-25 14:33
Thank you. Yes, version 9 fixes this error. I get now a timeout issue when trying to run the tests from jest though but will open this as a separate question. Cheers.

francislainy.campos
2021-09-25 14:44
Hi, I?m getting this issue where the pact server does not appear to be running when I try to build a docker image. It works fine outside docker when I try yarn test:pact from there. https://github.com/francislainy/docker-sample/blob/master/Dockerfile https://github.com/francislainy/docker-sample/blob/master/src/pact/consumer/showcase/school.pact.test.js Any ideas please? Thank you.

tjones
2021-09-25 14:45
With docker we see longer start up times. Try increasing your test timeout

tjones
2021-09-25 14:46
if you're using jest, jest-pact does this for you

tjones
2021-09-25 14:48
this error looks like it is in your code, not in pact.

tjones
2021-09-25 14:48
can you share your code?

tjones
2021-09-25 14:48
Also, make sure you are awaiting or returning all promises appropriately


francislainy.campos
2021-09-25 14:50
Thank you Timothy. I?ve just tried now with 500000 as a timeout but got the same issue.

francislainy.campos
2021-09-25 14:50
I can try with jest-pact if you think this may be helpful to fix the problem.

tjones
2021-09-25 14:51
jest-pact automates the boiler plate. It might be helpful, but if you prefer to write it yourself, can you let us know: ? What version of pact-core / pact-js you are using ? What your test code is

francislainy.campos
2021-09-25 14:53
Sure, this is my code on github https://github.com/francislainy/docker-sample

francislainy.campos
2021-09-25 14:53
?@greet_bot/pact?: ?^9.16.1",

tjones
2021-09-25 14:57
The code looks right to me

tjones
2021-09-25 14:57
are you certain you are applying the new timeout correctly?

francislainy.campos
2021-09-25 14:57
```import { Matchers } from '@pact-foundation/pact'; import { getSchool } from '../../../apis/ids'; import providerBuilder, { PROVIDER } from '../../helpers/pactSetup'; const { somethingLike, uuid } = Matchers; const GET_EXPECTED_BODY = { name: somethingLike('InteractEd Test Eval School 1-91002661'), type: 'SCHOOL', sifRefId: uuid('54d2a3eb-0010-4988-9d41-ec68ea869399'), pid: somethingLike('91002661'), schoolId: uuid('54d2a3eb-0010-4988-9d41-ec68ea869399'), parentOrg: { orgId: uuid('fabe7fcc-6c79-4540-94ee-3f22072ddb7a'), name: somethingLike('InteractEd Test Eval District 1-91002660'), type: somethingLike('DISTRICT'), sifRefId: uuid('fabe7fcc-6c79-4540-94ee-3f22072ddb7a'), pid: somethingLike('91002660'), }, }; const provider = providerBuilder(PROVIDER); beforeAll(() => { return provider.setup().then((opts) => { process.env.API_PORT = opts.port; }); }); afterAll(() => provider.finalize()); afterEach(() => provider.verify()); describe('GET School', () => { beforeEach((done) => { const interaction = { state: 'i have a school', uponReceiving: 'a request for a school', withRequest: { method: 'GET', path: '/ids/v1/schools/0d2bf746-ae98-4bb4-a807-8c2db6d2852d', headers: { Accept: '*/*', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: GET_EXPECTED_BODY, }, }; provider.addInteraction(interaction).then(() => done()); }); test('generate contract', async () => { const response = await getSchool( { schoolId: '0d2bf746-ae98-4bb4-a807-8c2db6d2852d' }, 'mockToken', { baseUrl: `${provider.mockService.baseUrl}/ids/v1`, }, ); expect(response.status).toEqual(200); } ,500000 ); });```

tjones
2021-09-25 14:58
What error do you get?

francislainy.campos
2021-09-25 14:58
That?s what I have it

tjones
2021-09-25 14:58
The error you originally posted in your screenshot is from the timeout in the hook, not the test

francislainy.campos
2021-09-25 14:59
I still get the same error

tjones
2021-09-25 14:59
Yes. This suggests your timeout is not being applied correctly.

tjones
2021-09-25 14:59
Please set jests timeout higher

francislainy.campos
2021-09-25 15:00
Where should I apply it if not there where I put the 50000?

tjones
2021-09-25 15:00
You can use jest-pact to do this, or you can pass it on the command line with `--testTimeout=30000`

tjones
2021-09-25 15:01
In the code you shared, you are setting the timeout on the individual test

francislainy.campos
2021-09-25 15:01
On the docker run command?

tjones
2021-09-25 15:01
It is better to change jest's timeout for all tests + hooks


tjones
2021-09-25 15:01
on jest

tjones
2021-09-25 15:01
Please see the jest documentation for timeouts

francislainy.campos
2021-09-25 15:09
The timeout is gone but the mock service is still not running

tjones
2021-09-25 15:12
As per the error message, see the logs to see what is going wrong

tjones
2021-09-25 15:13
it looks like the mock server isn't starting, so you should see an error message telling you what is going wrong

tjones
2021-09-25 15:14
if you see the startup message, but it's failing still, check your promises.

tjones
2021-09-25 15:14
Also, are you running tests in some sort of browser environment?

tjones
2021-09-25 15:16
That is saying the binaries weren't found.

francislainy.campos
2021-09-25 15:16
The logs are inside the docker container so I?d need to figure out how to access that as I?m still learning docker.

tjones
2021-09-25 15:16
Try deleting node_modules

tjones
2021-09-25 15:17
This log is enough - the problem is that pact doesn't have the binaries it is supposed to

francislainy.campos
2021-09-25 15:17
Which binaries?

tjones
2021-09-25 15:18
this sometimes happens if you install behind a corporate firewall

tjones
2021-09-25 15:18
pact installs these on `npm install`

tjones
2021-09-25 15:18
have a look further up in your logs to see if there were errors during npm install

tjones
2021-09-25 15:19
If you are behind a corporate firewall, you can tell pact to use local binaries following the instructions here: https://www.npmjs.com/package/@pact-foundation/pact-node#user-content-pact-download-location

francislainy.campos
2021-09-25 15:20
I?m not on vpn no


tjones
2021-09-25 15:20
Sorry, link didn't go directly correctly

tjones
2021-09-25 15:21
Can you see if the path to `pact-mock-service` in your error message resolves correclty?

tjones
2021-09-25 15:22
I have to go to bed here, but I will check back in the morning

francislainy.campos
2021-09-25 15:23
No problem. Thank you for your help.

francislainy.campos
2021-09-25 15:23
We can continue this whenever you?re back and have some more time.

tjones
2021-09-25 15:24
In summary: ? check for errors during `npm install` ? ensure that it works after you remove node_modules + package-lock (if these are corrupt, sometimes npm doesn't run the install script during `npm install`) ? see if the path to `pact-mock-service` from that error message resolves correctly

francislainy.campos
2021-09-25 15:24
No errors on npm no

francislainy.campos
2021-09-25 15:24
I?ll check the path

tjones
2021-09-25 15:25
Are you running npm install outside the container?

francislainy.campos
2021-09-25 15:25
No, docker

tjones
2021-09-25 15:25
Pact detects the architecture and installs the appropriate binaries, so if you run it outside it might not work


francislainy.campos
2021-09-25 15:25
```docker build -t docker-sample .```

tjones
2021-09-25 15:26
If you can make a minimal reproducible example docker file + repo, I can take a look tomorrow


francislainy.campos
2021-09-25 15:27
I?ll push the jest timeout change

tjones
2021-09-25 15:27
Your example has a mix of yarn and npm which probably isn't helping

francislainy.campos
2021-09-25 15:28
The docker commands I?ve been running are commented out inside the dockerfile

francislainy.campos
2021-09-25 15:28
yarn is what is triggering the test

tjones
2021-09-25 15:29
Right, but npm install is run, not yarn install

tjones
2021-09-25 15:29
some versions of yarn put the packages in different places to npm

francislainy.campos
2021-09-25 15:30
I can try with yarn install instead of npm install

francislainy.campos
2021-09-25 15:30
Anyways, please don?t feel obliged to keep replying to me if you want to go to bed

tjones
2021-09-25 15:31
Good luck! I'll check back tomorrow

jyotiguptaofficial
2021-09-25 15:31
I am trying to run the pact at react consumer end [Graphql] for the public repository, sharing the repo link https://github.com/thombergs/code-examples/tree/master/pact/pact-react-consumer.

francislainy.campos
2021-09-25 15:31
Sure, thank you. I?ll type here what happened and we can catch up when you?re back.

jyotiguptaofficial
2021-09-25 15:39
Test File : hero.service.test.graphql.pact.js Command for execution : cross-env CI=true react-scripts test --runInBand --setupFiles ./pact/setup-graphql.js --setupTestFrameworkScriptFile ./pact/jest-wrapper.js --testMatch \?**/*.test.graphql.pact.js\?

jyotiguptaofficial
2021-09-25 15:39
Setup-graphql.js: ```const path = require('path'); const Pact = require('@pact-foundation/pact').Pact; global.port = 8080; global.provider = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'graphql-hero-consumer', provider: 'graphql-hero-provider', host: '127.0.0.1' });```

jyotiguptaofficial
2021-09-25 15:40
jest-wrapper.js: ```beforeAll((done) => { global.provider.setup().then(() => done()); }); afterAll((done) => { global.provider.finalize().then(() => done()); });```

jyotiguptaofficial
2021-09-25 15:41
Test File : hero.service.test.graphql.pact.js : ```import GraphQLHeroService from './hero.service.graphql'; import * as Pact from '@pact-foundation/pact'; import fetch from 'node-fetch'; describe('HeroService GraphQL API', () => { const heroService = new GraphQLHeroService('http://localhost', global.port, fetch); // a matcher for the content type "application/json" in UTF8 charset // that ignores the spaces between the ";2 and "charset" const contentTypeJsonMatcher = Pact.Matchers.term({ matcher: "application\\/json; *charset=utf-8", generate: "application/json; charset=utf-8" }); describe('getHero()', () => { beforeEach((done) => { global.provider.addInteraction(new Pact.GraphQLInteraction() .uponReceiving('a GetHero Query') .withRequest({ path: '/graphql', method: 'POST', }) .withOperation("GetHero") .withQuery(` query GetHero($heroId: Int!) { hero(id: $heroId) { name superpower __typename } }`) .withVariables({ heroId: 42 }) .willRespondWith({ status: 200, headers: { 'Content-Type': contentTypeJsonMatcher }, body: { data: { hero: { name: Pact.Matchers.somethingLike('Superman'), superpower: Pact.Matchers.somethingLike('Flying'), __typename: 'Hero' } } } })).then(() => done()); }); it('sends a request according to contract', (done) => { heroService.getHero(42) .then(hero => { expect(hero.name).toEqual('Superman'); }) .then(() => { global.provider.verify() .then(() => done(), error => { done.fail(error) }) }); }); }); });```

jyotiguptaofficial
2021-09-25 15:42
GraphQLHeroService : ```import {ApolloClient} from "apollo-client" import {InMemoryCache} from "apollo-cache-inmemory" import {HttpLink} from "apollo-link-http" import gql from "graphql-tag" import Hero from "../hero"; class GraphQLHeroService { constructor(baseUrl, port, fetch) { this.client = new ApolloClient({ link: new HttpLink({ uri: `${baseUrl}:${port}/graphql`, fetch: fetch }), cache: new InMemoryCache() }); } getHero(heroId) { if (heroId == null) { throw new Error("heroId must not be null!"); } return this.client.query({ query: gql` query GetHero($heroId: Int!) { hero(id: $heroId) { name superpower } } `, variables: { heroId: heroId } }).then((response) => { return new Promise((resolve, reject) => { try { const hero = new Hero(response.data.hero.name, response.data.hero.superpower, null, heroId); Hero.validateName(hero); Hero.validateSuperpower(hero); resolve(hero); } catch (error) { reject(error); } }) }); }; } export default GraphQLHeroService;```

jyotiguptaofficial
2021-09-25 16:03
Hey @tjones Can you pls help me on the same

francislainy.campos
2021-09-25 16:15
Hi, so it?s working now. Removed npm install and added yarn install to the scripts file and that fixed the issue.

francislainy.campos
2021-09-25 16:15
Thanks very much for your help.

mattandaey
2021-09-25 20:32
has joined #pact-js

matt.fellows
2021-09-25 21:54
Hi Jyoti, note that this is a global workspace and people are from all over the world. No need to @ somebody who's responded they'll be notified and will respond if they choose to. Tim was probably asleep at the time! :rolling_on_the_floor_laughing:

tjones
2021-09-26 02:44
Glad you got it working. npm and yarn sometimes look in different places for their packages, so it's best to stick to one or the other.

tjones
2021-09-26 02:48
There are a few issues here. Probably the real cause is being masked because of the way `done` is used - if you are using `done` with promises, you'll have to remember to catch and fail if there are errors. The last test block has a catch, but it's in the wrong place.

tjones
2021-09-26 02:48
To reduce the risk of having bugs in your tests, it's usually better practice to return promises instead of using `done`

tjones
2021-09-26 02:51
Also, when you have the test wrapper globally like that, you'll have the pact server started up for every test. This is probably not what you want - and means that the logs can be hard to interpret. For example, in your log, I can see the pact server appearing to start, but it might not be during the test that's failing. I suspect that further up in your log you have a failing pact server start, which might be the issue

tjones
2021-09-26 02:52
We introduced jest-pact to help reduce the boilerplate setup for jest, and to ensure that it's in the most helpful place. Not using jest-pact isn't the problem, but it would bring these refactorings for you for free.

tjones
2021-09-26 02:52
Try running with `logLevel: 'debug'`

tjones
2021-09-26 02:56
If you want a quick fix to ensure that you're only starting the pact server when you need to, try moving the `beforeAll` and `afterAll` out of the wrapper script and into the pact test file. You don't want it in the wrapper script because it will run on all tests.

jyotiguptaofficial
2021-09-26 08:41
Thanks for the help. Really appreciated. I have integrated with jest-pact, it helped to remove all setup/wrapper files required for test execution. Moreover consuming async/await for the async task execution now by removing the done callback.

jyotiguptaofficial
2021-09-26 08:45
Hey Folks, please help with this query. Thanks in advance. Is there any way for addInteraction of GraphQLInteractionObject in jest-pact. As I am forced to use only InteractionObject as parameter in provider.addInteraction function. Sharing code snippet for better clarity

jyotiguptaofficial
2021-09-26 08:45
```//Customer.pact.graphql.test.js import { pactWith } from 'jest-pact'; import path from 'path'; import { provideApolloClient, useQuery } from '@vue/apollo-composable'; import { getCustomerRequest, getCustomerResponse } from './customerInteraction'; import getCustomer from '../../../../src/graphql/queries/customers/getCustomer'; import apolloClient from '../../../../src/plugins/apollo'; const CONSUMER = 'Calypso Get Consumer'; const PROVIDER = 'GraphQL'; const PACTConfigOption = { cors: true, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'DEBUG', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: CONSUMER, provider: PROVIDER, host: 'localhost', }; pactWith(PACTConfigOption, (provider) => { describe('Get Customer GraphQL', () => { beforeEach(async () => { const interaction = { state: 'customer query', ...getCustomerRequest, willRespondWith: getCustomerResponse, }; await provider.addInteraction(interaction); }); it('generate contract for getCustomer', async () => { provideApolloClient(apolloClient); const { result, error } = await useQuery(getCustomer, { customerId: '2135e729-a289-49e5-9c22-b0ffba629e24' }); expect(result).toEqual(''); // expect(error).toEqual(''); }); }); });```

jyotiguptaofficial
2021-09-26 08:47
// CustomerInteraction.js File ```import { Matchers } from '@pact-foundation/pact'; const { somethingLike, uuid, } = Matchers; const contentTypeJsonMatcher = Matchers.term({ matcher: 'application/json; *charset=utf-8', generate: 'application/json; charset=utf-8', }); export const getCustomerRequest = { uponReceiving: 'a getCustomer Query', withRequest: { method: 'POST', path: '/graphql', body: { operationName: 'getCustomer', variables: { customerId: uuid('54d2a3eb-0010-4988-9d41-ec68ea869399'), }, query: 'query getCustomer($customerId: ID) {n customer(id: $customerId) {n namen idn __typenamen }n}n', }, }, }; export const getCustomerResponse = { status: 200, headers: { 'Content-Type': contentTypeJsonMatcher, }, body: { data: { customer: { name: somethingLike('customer name'), }, }, }, };```

tjones
2021-09-26 10:15
the provider in `jest-pact` is the same as the provider from pact-js - all jest-pact does is give you a wrapper for the boilerplate,


jyotiguptaofficial
2021-09-26 11:48
Yeah, I got it. Make sense. Thanks alot!!!

abubics
2021-09-27 00:53
:taco: for @tjones \o/

matt.fellows
2021-09-27 01:09
yes, absolutely more :taco: for @tjones

univ.anirudh
2021-09-27 06:09
Is there anything in particular I need to do for a request payload to be sent as JSON when verifying a contract on the provider's side? The body of the request seems to be getting sent as a key-value pair with key as the actual payload and value as an empty string

univ.anirudh
2021-09-27 06:09
The pact on the consumer side for reference - ``` { "description": "a get-room request", "providerState": "there exist some rooms", "request": { "method": "POST", "path": "/", "headers": { "Accept": "application/json" }, "body": { "content": { "api": "get-room", "request": { "roomHash": "foobar" } }, "meta": { } } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "success": false } } },```

univ.anirudh
2021-09-27 06:11
~When sending normal requests to the same endpoint, the payload gets converted to JSON by a middleware, but that seems to be failing for requests through the verification mock server~ Can be ignored. I was missing a `Content-Type` header in the pact json which was implicitly being sent as `application/json` . Didn't realize that it has to be explicitly set in the contract. My bad!

tjones
2021-09-27 07:41
Perhaps we should make the consumer pact warn if there is no content type :thinking_face:

saurelio58
2021-09-27 12:39
has joined #pact-js

francisco
2021-09-27 18:27
has joined #pact-js

jamesatroughton
2021-09-28 10:42
has joined #pact-js

leonardo.viana
2021-09-28 22:06
Hi all. So, I understand we can verify all pacts with a given tag by using something like: ```consumerVersionSelectors: [ { tag: "prod", all: true } ]``` Now, is it possible to verify the _latest_ version of the pacts from _all_ tags?

jake.thacker
2021-09-28 22:06
has joined #pact-js

craig.schwarzwald
2021-09-28 22:37
has joined #pact-js

tjones
2021-09-29 00:45
I think you can just do `[{ latest: true }]`

tjones
2021-09-29 00:46
tbh, I'm not 100% sure - pact-js just passes whatever selector you give it on to the broker, and it decides

owain.hunt
2021-09-29 12:58
has joined #pact-js

bryan
2021-09-29 14:06
@matt.fellows I haven?t been able to try the beta because their internal nexus npm repository has the beta quarantined :disappointed:

damtsisa
2021-09-30 06:58
has joined #pact-js

morsisdivine
2021-09-30 09:23
has joined #pact-js

patrice.jy.thomas
2021-09-30 15:05
has joined #pact-js

kschendster
2021-09-30 16:46
has joined #pact-js

adam.dubnytskyy
2021-09-30 17:49
has joined #pact-js

stefano.varesi
2021-09-30 17:51
has joined #pact-js

steven.yi
2021-09-30 20:17
has joined #pact-js

leonardo.viana
2021-09-30 21:49
It seems to me that using `[{ latest: true }]` would just verify the latest overall pact (regardless of tag), *not* the latest pacts for each and every tag. @matt.fellows, in minute 11:30 of video https://www.youtube.com/watch?v=6Qd-kq1AzZI (during the provider pipeline) you say that: > ?pact is going to the pact broker pull down all the contracts? How do I specify ?the latest pacts from all tags? via `consumerVersionSelectors`? Is there someone who would know the answer to that question?

matt.fellows
2021-09-30 21:55
I don't think there is a selector for "all tags". That could mean hundreds of pacts and will just grow unless you delete old ones. Can you explain why you want it?


leonardo.viana
2021-09-30 22:13
Yeah, I saw that link, but it seems incomplete, given that the `all` property is not even listed there. What happens when `consumerVersionSelectors` is not specified at all? Will it just select the latest overall pact? I didn?t see that in the documentation either?

calcorbin
2021-09-30 23:09
has joined #pact-js

tjones
2021-09-30 23:19
This is probably a #pact-broker question

matt.fellows
2021-09-30 23:22
probably, can you explain why you want that use case though Leonardo? I ask because it is the kind of thing that could accidentally lead to strange/bad behaviour

osikwemhev
2021-10-01 01:45
has joined #pact-js

kentaro
2021-10-01 10:05
has joined #pact-js

vitali.domashkevitsh
2021-10-01 10:08
has joined #pact-js

seb983
2021-10-01 11:30
has joined #pact-js

dimundo
2021-10-01 12:18
with 9.16.3 i?m getting ```.../.yarn/unplugged/@pact-foundation-pact-node-npm-10.13.8-8690d7b85e/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact-1.60.0/lib/pact/hal/entity.rb:102:in `assert_success!': Error retrieving https://pact.xxx.xxx/ status=404 default backend - 404 (Pact::Hal::ErrorResponseReturned)```

matt.fellows
2021-10-01 12:23
We do run some feature examples that publish/verify from a broker in the Pact JS repo. What action are you performing Dmitry? @bethskurrie any ideas as to what this could be?

dimundo
2021-10-01 12:25
provider fetching pacts from broker

matt.fellows
2021-10-01 12:33
Any chance you could please add the verbose flag? Might need to collectively fix it tomorrow with fresh eyes rather than rush another out

dimundo
2021-10-01 12:39
i?m kinda also on coffee , can you elaborate how to do it more verbose ? :smile:

dimundo
2021-10-01 12:39
some key somewhere ?

vannessa.andrade
2021-10-01 14:44
has joined #pact-js

calcorbin
2021-10-01 17:39
Let me know if you all have more issues you'd like me to work on for pact-js, I've had fun so far!

leonardo.viana
2021-10-01 20:14
Hi all. I?m using `consumerVersionSelectors` with pact-js v3 beta and the `tag` I specify seems to be getting ignored. For example, if I specify `consumerVersionSelectors: [ { tag: 'dev_lviana_pact', latest: true } ]`, it simply verifies the latest version, ignoring tags, as can be seen from the output (notice how the tag is *not* mentioned in the output): ```The pact at https://menloinfra.pactflow.io/pacts/provider/pnr-policy/consumer/menlo-frontend-policy/pact-version/c3e484fb28acdba797b9674f88f9c9fc3dbfed24 is being verified because the pact content belongs to the consumer version matching the following criterion: * latest version of menlo-frontend-policy that has a pact with pnr-policy (2.81.0-3-12-gd6d0eb7e2)``` As a matter of fact, the issue I?m seeing seems to be exactly like the one described below: https://github.com/pact-foundation/pact-js/issues/713 Now, that issue was supposedly fixed on version `10.0.0-beta.44`: https://github.com/pact-foundation/pact-js/commit/f8e511fbc0a006bde4599308d377844830a31bcd The thing is, version `10.0.0-beta.44` is exactly the version I?m using, and yet I?m still seeing this issue. Am I missing something, or is it possible that the `tag` property is still being ignored in recent versions of pact-js v3 beta?

matt.fellows
2021-10-01 22:39
Just confirming you did figure this one out and it's sorted now? K8s change?

matt.fellows
2021-10-01 23:21
Can you please respond to that ticket with a debug level log so we can take a look at what?s happening?

leonardo.viana
2021-10-02 00:11
@matt.fellows, I just did that. You can clearly see that `consumerVersionSelectors` is an empty array with `10.0.0-beta.44`, even though I passed in `consumerVersionSelectors: [ { tag: 'dev_lviana_pact', latest: true } ]`.

leonardo.viana
2021-10-02 00:17
Here it is for your reference:

matt.fellows
2021-10-02 00:50
Thanks. I would just update to the latest and see if it was fixed in between. There were a few build issues whilst we tried to add support for node 16. We're up to 51 now

matt.fellows
2021-10-02 00:51
FYI we've made really good progress in the v3 branch in the past few weeks, I'd say we're a week or two away from revisiting the API in the v3 branch and getting close to the next major release. Thanks for your patience! :pray:

mickfagan
2021-10-02 10:36
has joined #pact-js

maxim.matviyuk
2021-10-03 16:48
has joined #pact-js

jonathan.a.stern
2021-10-03 20:38
has joined #pact-js

dimundo
2021-10-04 06:15
yes, everything is fine now :slightly_smiling_face:

matt.fellows
2021-10-04 06:16
phew!

matt.fellows
2021-10-04 06:16
this kind, or the better kind? :stuck_out_tongue:

dimundo
2021-10-04 06:16
yes :troll:

matt.fellows
2021-10-04 06:16
:laughing:

chris.ramsden
2021-10-04 16:40
has joined #pact-js

leonardo.viana
2021-10-04 20:20
I noticed that `consumerVersionTags` seems to work on `beta.44`. Also, `consumerVersionSelectors` does indeed seem to work on `beta.51`, so it looks like we are good.

matt.fellows
2021-10-04 21:17
great, thank you for confirming!

tausif2909
2021-10-05 04:32
Hello, my pact publishing suddenly started failing in the jenkins pipeline with error : `[2021-10-01T10:11:49.048Z] INFO: pact-node@6.21.3/23527 on ip-10-62-220-138: Checking if it it possible to deploy` `[2021-10-01T10:11:49.051Z] INFO: pact-node@6.21.3/23527 on ip-10-62-220-138: Asking broker at https://pact.xyz.net/ if it is possible to deploy` `[2021-10-01T10:11:49.061Z] INFO: pact-node@6.21.3/23527 on ip-10-62-220-138: Created './standalone/linux-x64-1.63.0/bin/pact-broker can-i-deploy --pacticipant 'flex-taxonomy-service' --version '1.0.0' --pacticipant 'flex-search-app' --version '1.0.0' --broker-base-url 'https://pact.xyz.net/'' process with PID: 23539` `[2021-10-01T10:12:00.213Z] WARN: pact-node@6.21.3/23527 on ip-10-62-220-138: Pact exited with code 1.` `[2021-10-01T10:12:00.214Z] ERROR: pact-node@6.21.3/23527 on ip-10-62-220-138:` `can-i-deploy did not return success message:` `Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=error: certificate verify failed /var/lib/jenkins/workspace/ps_FMP_UI_flex-search-app_master/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/matrix.rb:13:in `get', attempt 1 of 3` what could be the issue? my pact portal is working fine, I am able to publish it from my local

tjones
2021-10-05 04:33
Can you try updating to the latest version of pact?

tjones
2021-10-05 04:34
There is an issue with some expired SSL certs

matt.fellows
2021-10-05 04:34
Yep, probably Let's encrypt issue

tausif2909
2021-10-05 04:34
~Below are the logs~

tausif2909
2021-10-05 04:39
right now its `"@pact-foundation/pact-node": "^6.21.3"` , should I upgrade it to `9.x.x`?

tausif2909
2021-10-05 04:40
latest is `Release v9.16.3`

tausif2909
2021-10-05 04:42
another one is `"pact": "^4.3.2"` , Sorry but I am not sure which one to upgrade

brian.fung
2021-10-05 04:57
has joined #pact-js

matt.fellows
2021-10-05 04:59
they are both? old

matt.fellows
2021-10-05 04:59
at a minimum, you need to have `pact-node` updated to the very latest

matt.fellows
2021-10-05 04:59
which is `v10.13.8`

matt.fellows
2021-10-05 05:00
`pact` is currently `v9.16.3` as you have observed

matt.fellows
2021-10-05 05:00
I would recommend updating Pact. If you have `pact-node` as an explicit dependency, you could probably remove it (`pact` brings it in anyway)

matt.fellows
2021-10-05 05:00
if there are upgrade teething issues, I would then see if you can update `pact-node` independently of `pact`

tausif2909
2021-10-05 05:02
perfect, thanks @matt.fellows @tjones

tjones
2021-10-05 05:03
pact-node isn't intended to be depended on directly, although there were a lot of old examples that did depend on it

tjones
2021-10-05 05:03
if you're using it, you probably have custom scripts that use it that could be replaced with CLI commands

tjones
2021-10-05 05:04
Please let us know if you have any issues with the upgrade

elekberhacizade
2021-10-05 05:27
has joined #pact-js

ankit.wadhwana
2021-10-05 12:23
has joined #pact-js

zhaopeng
2021-10-05 12:24
has joined #pact-js

bjorn.johansson
2021-10-05 13:16
has joined #pact-js

pcting
2021-10-05 18:57
has joined #pact-js

aulia.ahn
2021-10-06 00:01
has joined #pact-js

muralis
2021-10-06 01:21
has joined #pact-js

tausif2909
2021-10-06 06:57
I have upgraded pact to `9.16.3` , but now my code returns error while generating pact like : `TypeError: provider.addInteraction is not a function`

tausif2909
2021-10-06 06:58
Have we stopped supporting `provider.setup` & `provider.addInteraction` in latest version

lakapoor777
2021-10-06 08:47
has joined #pact-js

tausif2909
2021-10-06 08:57
sorry , Please ignore.. replied in the wrong thread

tausif2909
2021-10-06 08:58
I have upgraded pact to `9.16.3` , but now my code returns error while generating pact like : `TypeError: provider.addInteraction is not a function`

tausif2909
2021-10-06 08:58
Have we stopped supporting `provider.setup()` & `provider.addInteraction()` in latest version

matt.fellows
2021-10-06 09:47
No, they are still there

matt.fellows
2021-10-06 09:47
Please share your logs and/or code

garry.jeromson973
2021-10-06 09:52
has joined #pact-js

tausif2909
2021-10-06 10:10
sorry it was my bad in the declaring variable.. sorted out the issue. thanks

tausif2909
2021-10-06 10:25
After upgrading to the latest still getting SSL certificate error

tausif2909
2021-10-06 10:29
```tausif@tausif:~/git-directories/my-search-app/Service/publishPact$ node publishToPactBroker.js [2021-10-06 10:22:09.623 +0000] INFO (30582 on tausif): pact-node@10.13.8: Publishing Pacts to Broker [2021-10-06 10:22:09.626 +0000] INFO (30582 on tausif): pact-node@10.13.8: Publishing pacts to broker at: https://pact.xyz.net/ [2021-10-06 10:22:11.065 +0000] WARN (30582 on tausif): pact-node@10.13.8: Pact exited with code 1. [2021-10-06 10:22:11.065 +0000] ERROR (30582 on tausif): pact-node@10.13.8: Could not publish pact: /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `connect' : SSL_connect returned=1 errno=0 state=error: certificate verify failed ( OpenSSL::SSL::SSLError ) from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `block in connect' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/timeout.rb:74:in `timeout' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `connect' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:863:in `do_start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:852:in `start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:79:in `block in perform_request' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:93:in `until_truthy_or_max_times' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:64:in `perform_request' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/http_client.rb:25:in `get' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/link.rb:41:in `get' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal/link.rb:45:in `get!' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/hal_client_methods.rb:20:in `index_resource' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/publish_pacts.rb:31:in `call' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/publish_pacts.rb:14:in `call' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/cli/broker.rb:157:in `publish_pacts' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/cli/broker.rb:42:in `publish' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/thor-1.1.0/lib/thor/base.rb:485:in `start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.54.0/lib/pact_broker/client/cli/custom_thor.rb:15:in `start' from /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/app/pact-broker.rb:34:in `<main>' Something went wrong while pushing pact for collections Error: /home/tausif/git-directories/my-search-app/Service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.75/pact/lib/ruby/lib/ruby/2.2.0/net/http.rb:923:in `connect' : SSL_connect returned=1 errno=0 state=error: certificate verify failed ( OpenSSL::SSL::SSLError )``` Logs

matt.fellows
2021-10-06 11:47
Please see the pinned issue on pact JS for solution

matt.fellows
2021-10-06 11:47
There is still work to fully resolve

tausif2909
2021-10-06 12:18
:+1:

matt.fellows
2021-10-06 12:23
:wave: hi folks, the organiser of https://testjssummit.com/ reached out about doing a talk on Pact. I don?t have the capacity to put together a new talk right now and wouldn?t want to repeat my usual _yet another time._ If anybody is keen, i?d be happy to do an intro - let me know! If it helps, here are some ideas: 1. Talk about your journey. People love a good story to connect with 2. Talk about how you used Pact in some obscure technology, or something not often presented (messaging, graphql, AWS/cloud etc.) 3. Show how to refactor an existing application to be testable with Pact 4. Metrics, outcomes and killer headlines (ala https://building.nubank.com.br/why-we-killed-our-end-to-end-test-suite/) :laughing:

anagha.sulakhe
2021-10-06 16:27
has joined #pact-js

carolyn.biggar
2021-10-07 00:27
has joined #pact-js

tausif2909
2021-10-07 04:59
Sorry to ask you but do you have any ETA to fix this issue or any workaround to temporary fix to avoid SSL error? As our multiple builds are failing in the pipeline @matt.fellows @tjones


tjones
2021-10-07 05:00
> The short term resolution is to disable SSL verification with the env var PACT_DISABLE_SSL_VERIFICATION=true or setting one of standard openssl SSL_CERT_FILE or SSL_CERT_DIR env vars.


tausif2909
2021-10-07 05:04
Thanks @tjones

mesut.gunes
2021-10-07 09:03
has joined #pact-js

vandana.bhaskersen
2021-10-08 09:58
has joined #pact-js

ad.redouani
2021-10-09 15:11
has joined #pact-js

amulyadoss
2021-10-09 21:09
has joined #pact-js

amulyadoss
2021-10-09 21:53
I am working on a Pact test where the service under test has as a required field cookie in header, whose value is the xsrf token. This service is using axios post to make the request. The other required fields to be sent in the header are the content-type and x-xsrf-token. I created the header as follows: headers: { cookie:?XSRF-TOKEN=123?, Content-type:'application/json' X-xsrf-token:?123? } The problem that I am facing is that the pact test is failing with the following error: Could not find key ?cookie?(keys present are: Content-type,X-xsrf-token) at $.headers I am able to verify that the pact test is sending the cookie in the header and also that the service is receiving it. It is only when it makes the http://axios.post call that the cookie is being dropped. I have tried all the fixes suggested:withCredentials:true, expose headers etc but the error is always that the cookie key is not in the header. Can someone please help me with this as I am all out of ideas.

matt.fellows
2021-10-09 22:40
Is this a consumer test or a provider test?

amulyadoss
2021-10-09 22:42
This is a consumer test.

matt.fellows
2021-10-09 22:43
Can you please post the entire pact test?

amulyadoss
2021-10-09 22:49
Thank you! Will do

amulyadoss
2021-10-09 23:20
const NFWServiceTest: PactTestDefinition=[ function defineInteraction(){ return { uponReceiving:?a request to send postal mail?, withRequest:{ method:?POST?, path:?/orders?, body:mockRequestBody ///JSON object }, willRespondWith:{ status:200, headers:{?Content-Type?:?application/json?} body:mockResponse //json object } }; }, function(pactHost){ It(?Request returns 200?, async done =>{ const mockThis = { headers: { ?cookie?:?XSRF-TOKEN=123?, ?Content-Type?:'application/json?, ?X-xsrf-token?:?123? } //Following is for Falcor routes- //service uses falcor & axios //This is Falcor call const callRoute:CallRoute = NFWService.sendPostalMail; //This is the Falcor path set const pathSet:any=[?nfw?,?ALL?], // this resolves to ?http://127.0.0.0.1:1231/orders%E2%80%99 URLS.WEBSERVICE_URL=pactHost +?/orders?; const actualResponse:any=await callRoute.call.call(mockThis,[pathSet],[mockRequestBody]); const actualVal:any=actualResponse.value.value; expect(actualValue).toEqual(mockResponse); done(); }); } ]; //passing it to a wrapper that generates the pact file PactTest(NFWRoute.sendPostalMail,?provide-api-name?,NFWServiceTest);

amulyadoss
2021-10-09 23:20
The service is using Falcor and the actual http post call is made by axios

amulyadoss
2021-10-09 23:23
Also we are using an in-house wrapper PactTest to set up & tear down jest tests, as well as all the pact related set up like log level, pact host etc.

amulyadoss
2021-10-09 23:25
I have successfully been able to write consumer pact tests for services which are using Falcor and axios. However none of those services had a cookie in the header as a required field.

matt.fellows
2021-10-09 23:28
I'm confused about the use of mockThis, but could you please also set the logs to debug and share the pact log file created?

matt.fellows
2021-10-09 23:29
Also for future ref, please try and format your code with code gates

matt.fellows
2021-10-09 23:29
(I'm on mobile FYI so may miss something)

amulyadoss
2021-10-09 23:30
mockThis is just a const for the header. I could have just used const headers as well.

matt.fellows
2021-10-09 23:32
Oh, which version of pact are you using?

matt.fellows
2021-10-09 23:35
If you're using the beta please set to verbose and upload a test file of your terminal log output

amulyadoss
2021-10-10 00:16
In the log , I have console logged the headers being sent in the pact test and what the incoming header in the service is. Also have logged the request options that are used to make the axios post call.

matt.fellows
2021-10-10 00:45
Thanks, but I need the log file, it should be in the relative path like logs/pact.log by default

matt.fellows
2021-10-10 00:46
That will tell us what actual req/res was received by the mock service

matt.fellows
2021-10-10 00:46
Separate to the terminal output

amulyadoss
2021-10-10 01:17
Sadly I don?t have access to the log file, because I am unable to run the pact test locally. The pact test runs as a part of a bamboo build stage. Sorry, I know i am not providing any useful info. Any advise on what to look for to help debug the issue?

matt.fellows
2021-10-10 01:18
You should get the log file to be a build artifact then

matt.fellows
2021-10-10 01:19
As for your test, the obvious thing missing to me is that I can't see anywhere in your pact test where you tell pact it's expecting an xsrf header. I.e. there are no expectations set on the headers property if the pact Interaction. Are you putting the expectation on the body?

matt.fellows
2021-10-10 01:19
Specifically, the expectation should be on the request header

amulyadoss
2021-10-10 01:30
Thank you I did have the headers here in the given

amulyadoss
2021-10-10 01:32
withRequest:{ method:?POST?, path:?/orders?, headers:{'cookie':'xsrf-token=123','content-type':'application/json','x-xsrf-token':'123'} body:mockRequestBody ///JSON object },

amulyadoss
2021-10-10 01:33
but it didnt seem to make any difference. It looks like the post call was failing with a 500, bcos the cookie is missing.

matt.fellows
2021-10-10 01:48
Is this the same as the other test? It looks different

matt.fellows
2021-10-10 01:49
Why can't you run this locally?

matt.fellows
2021-10-10 01:49
Pact tests are unit tests

matt.fellows
2021-10-10 01:50
The pact log file will tell you exactly what you configured and exactly what you sent

matt.fellows
2021-10-10 01:51
Because you have a number of tools/layers that are in between it's very hard to help you without them

amulyadoss
2021-10-10 01:55
I will try to find it. The reason I am not able to run it locally, is I am running it on a windows machine and I get an error thrown by Ruby about the path being too large.

matt.fellows
2021-10-10 01:56
Ah!

matt.fellows
2021-10-10 01:57
Have you tried moving the project closer to e.g C: ?

matt.fellows
2021-10-10 01:57
The v3 beta might be worth looking into

farshad.falaki
2021-10-10 19:13
has joined #pact-js

jhopkinwilliams
2021-10-12 02:01
has joined #pact-js

josephhaig
2021-10-12 08:52
has joined #pact-js

margarita.lukjanska
2021-10-12 10:12
has joined #pact-js

oak155online
2021-10-12 14:17
has joined #pact-js

filipovic
2021-10-13 06:51
has joined #pact-js

stefan.smith
2021-10-13 09:37
has joined #pact-js

warren
2021-10-13 16:45
has joined #pact-js

michael.stein
2021-10-13 19:02
has joined #pact-js

hwillj
2021-10-14 14:52
has joined #pact-js

craig.schwarzwald
2021-10-14 17:57
I'm trying to run my consumer pact test locally on Windows and getting: ...pact-node/standalone/win32-1.88/pact/lib/ruby/lib/Ruby/gems/2.2.0/gems/builder1.9.9/lib/builder.rb:418:in []=': Invalid argument - ruby_setenv(GEM_PATH) This error only comes up on Windows and works fine on my Linux build pipeline. From Google searches it looks like something in my ENV is too large. I've tried wrapping the pact command in a bash script to eliminate my INCLUDE, CLASS PATH, and shortening my PATH to bare minimum, but still facing this error. Does anyone else have any other ideas?

matt.fellows
2021-10-14 22:15
do you happen to also have Ruby installed on your system?

matt.fellows
2021-10-14 22:15
I?ve seen cases where there are some extra environment variables that can interfere with things

matt.fellows
2021-10-14 22:15
but have not seen that specific error before

matt.fellows
2021-10-14 22:16
We?re edging closer to a release of our new beta interface: https://github.com/pact-foundation/pact-js/tree/master#pact-js-v3

matt.fellows
2021-10-14 22:16
We are blocked by an upstream problem at the moment, so it?s still a few months away, but that should resolve that specific issue

matt.fellows
2021-10-14 22:16
(doesn?t use Ruby anymore)

fengniy
2021-10-15 02:09
has joined #pact-js

craig.schwarzwald
2021-10-15 03:16
Yeah, I'm trying to keep an eye out for the Pact JS V3 release. I'm not sure I can get a beta inside my company.

craig.schwarzwald
2021-10-15 03:17
I shouldn't have Ruby installed anywhere.

matt.fellows
2021-10-15 05:04
I thought that might be the case

mark.dathorne
2021-10-15 09:51
has joined #pact-js

matt.fellows
2021-10-15 10:17
have you tried inspecting your env to see what?s in there? I?m assuming you won?t be able to share that, but I wonder what a trial/error might look like

matt.fellows
2021-10-15 10:17
I can?t even find that file on the internet :stuck_out_tongue:

matt.fellows
2021-10-15 10:17
will have to download the package itself

artur
2021-10-15 12:24
I'm trying to migrate from v3 beta 44 to 51 and the provider states are not fired `MismatchResult::Error("Invalid status code: 500", None)` any idea what the issue could be?

craig.schwarzwald
2021-10-15 13:32
There are a total of 61 variables in my ENV it looks like. The only 3 that are more than 20 or so characters are INCLUDE, CLASS PATH, and PATH, which I've wiped out or minimized in a bash script before the line that executes the pact test.

craig.schwarzwald
2021-10-15 13:40
Hmmm, just tried to export all other variables to "" as well, but still getting that same error.

haroldlearning93
2021-10-15 14:49
has joined #pact-js

vsrungar95
2021-10-15 22:14
has joined #pact-js

tjones
2021-10-16 00:17
It sounds like the provider state handler is returning a 500. Are you able to share your state handler code?

artur
2021-10-16 10:31
``` 'the user is recreated': (setup, parameters) => { const email = `${parameters.username}@example.com` if (setup) { fetch(providerBaseUrl + '/ocs/v2.php/cloud/users/' + parameters.username, { method: 'DELETE', headers: validAdminAuthHeaders })```

artur
2021-10-16 10:31
I think the issue is the paramaters given to the state handler

artur
2021-10-16 10:33
in beta36 I got

artur
2021-10-16 10:35
in beta51 the fist parameter `setup` contains the password and the username

artur
2021-10-16 10:37
I must have missed a breaking change in https://github.com/pact-foundation/pact-js/commit/456567c83a5f155381eebb7dd3f6b60d3bc0060b ``` BREAKING CHANGE: the signature of state handlers has been updated to accept either a single function with parameters, or an object that can specify optional teardown and setup functions that run on the different state phases.```

tjones
2021-10-16 10:52
Ah, yes. The signature has changed. Maybe we can make the (re) migration path easier

tjones
2021-10-16 10:53
We could use `function.length` and assume the old format

jsoto128
2021-10-16 20:45
has joined #pact-js

fiszczu
2021-10-17 17:04
has joined #pact-js

brocheleau
2021-10-18 03:23
has joined #pact-js

andrerc
2021-10-18 22:11
has joined #pact-js

leonardo.viana
2021-10-18 22:54
Hi team. We?ve just upgraded from pact-js v3 beta.51 to beta.52 and we?re noticing one extra log line that seems a little concerning. Up to beta.51, the output of our consumer tests would be something like: ```10:59:15 [2021-10-18 17:59:14.487 +0000] INFO (766 on 43282697741d): pact-core@13.1.7: Publishing Pacts to Broker 10:59:15 [2021-10-18 17:59:14.491 +0000] INFO (766 on 43282697741d): pact-core@13.1.7: Publishing pacts to broker at: https://menloinfra.pactflow.io 10:59:18 PASS libs/api-client/src/lib/api/pact.spec.ts (10.383 s) 10:59:18 [2021-10-18 17:59:17.792 +0000] INFO (766 on 43282697741d): pact-core@13.1.7: 10:59:18 Tagged version 2.82.0-16-ge11add554 of menlo-frontend as "dev_lviana_pact" 10:59:18 Publishing menlo-frontend/pnr-policy pact to pact broker at https://menloinfra.pactflow.io 10:59:18 [33mA pact for this consumer version is already published. Overwriting. (Note: Overwriting pacts is not recommended as it can lead to race conditions. Best practice is to provide a unique consumer version number for each publication. For more information, see https://docs.pact.io/versioning)[0m 10:59:18 The latest version of this pact can be accessed at the following URL: 10:59:18 https://menloinfra.pactflow.io/pacts/provider/pnr-policy/consumer/menlo-frontend/latest``` However, on beta.52 there?s one extra line saying `ERROR (805 on 3af6c54f8b79): pact-core@13.2.0: Could not publish pact:` ```15:25:33 [2021-10-18 22:25:32.467 +0000] INFO (805 on 3af6c54f8b79): pact-core@13.2.0: Publishing Pacts to Broker 15:25:33 [2021-10-18 22:25:32.471 +0000] INFO (805 on 3af6c54f8b79): pact-core@13.2.0: Publishing pacts to broker at: https://menloinfra.pactflow.io 15:25:35 PASS libs/api-client/src/lib/api/pact.spec.ts (10.087 s) 15:25:36 [2021-10-18 22:25:35.122 +0000] ERROR (805 on 3af6c54f8b79): pact-core@13.2.0: Could not publish pact: 15:25:36 Created menlo-frontend version 2.83.0-dev-40-g6353f14a8 with tags dev_lviana_pact 15:25:36 [33m Next steps: 15:25:36 Configure the version branch to be the value of your repository branch.[0m 15:25:36 [32mPact successfully published for menlo-frontend version 2.83.0-dev-40-g6353f14a8 and provider pnr-policy.[0m 15:25:36 View the published pact at https://menloinfra.pactflow.io/pacts/provider/pnr-policy/consumer/menlo-frontend/version/2.83.0-dev-40-g6353f14a8 15:25:36 Events detected: contract_published (pact content is the same as previous version with tag dev_lviana_pact and no new tags were applied) 15:25:36 No enabled webhooks found for the detected events``` Despite the `ERROR`, the pact seems to be getting published just fine (as can be verified by the subsequent line: `Pact successfully published`?), so it really seems like a bogus message. Is this a known issue?

tjones
2021-10-18 22:55
Yes, it is. I'll release a version with a fix later today

tjones
2021-10-18 22:55
thanks for the report

leonardo.viana
2021-10-18 23:06
Thanks for confirming, @tjones!

matt.fellows
2021-10-19 03:15
Thanks for fixing Tim. Are you using the JS API Leonardo to publish? If possible, i?d switch to the CLI if you could. We?re trying to move away from the JS SDK that wraps all of this so that the CLI can move at more pace. We currently do some hacky things, which is the root cause of this problem

tjones
2021-10-19 06:20
Also the CLI is way nicer - you don't need any custom scripts, it's installed automatically, and you can just call it straight from a script in `package.json`. See the examples in the pact-js repo

rodolfo.valenzuela
2021-10-19 07:43
has joined #pact-js

kamilyrb
2021-10-19 22:31
has joined #pact-js

sadikshahidain
2021-10-20 01:12
Does anyone recall why pact-js-core stopped checking checksums for the Ruby standalone binaries? I see that there https://github.com/pact-foundation/pact-js-core/blob/d264f0b800209a171b320039e7fa3c2dd621606e/standalone/install.ts#L390 around this, but it seems to have been removed at some point in the past 2 years (FWIW https://grep.app/search?q=.%2Atar.gz.%2Achecksum.%2A&regexp=true&filter[repo.pattern][0]=pact-foundation, it just seems like JS might've been the last/only to do so and so I'm trying to figure out if I really need to do so as a consumer of the PHP library for security's sake)

matt.fellows
2021-10-20 01:15
We didn?t see any value in the security of it given that we download it in the same step, so any compromise would mean that the malicious actor could also modify the checksum. Outside of security, we couldn?t see the value in keeping it. If the file was corrupted, the zip file wouldn?t unpack anyway Also we now pack the file directly into the bundle (rather than download at runtime), which is probably why we don?t have the checksums anymore

sadikshahidain
2021-10-20 01:17
Awesome, ty for that context. And yeah I think in that case I'll see about checking against a hard-coded hash in our code then, assuming our security team still considers this a significant risk (I've heard mixed takes so far...), and just make some notes around managing upgrades for it.

tjones
2021-10-20 05:49
Which version are you asking about? The current main release checks the checksums, the current beta does not (because the binaries are bundled with the package, so we'd be marking our own exam)

tjones
2021-10-20 05:50
Note that the code you linked to is not a dependency of pact-js's current release. This is what the current release uses: https://github.com/pact-foundation/pact-js-core/blob/pact-node/standalone/install.ts


artur
2021-10-20 11:43
trying to update from beta 36 to beta 53 I get `Request Failed - One or more of the state change handlers has failed during teardown phase` To find out which teardown phase failed I removed all teardowns in the state handlers, still II get that message. How can I find out where its coming from?

artur
2021-10-20 11:58
oh noooo it's the timeout. I'm hunting that :ghost: since days. It has nothing to do with the handler, its the timeout

tjones
2021-10-20 14:34
Ah! Which timeout?

joel.whalen588
2021-10-20 20:27
has joined #pact-js

sadikshahidain
2021-10-21 01:58
Mmm, I see. And yeah I didn't have a specific version in mind, was just trying to understand if it would make sense for me to start an issue on the Pact-PHP repo to do the same (and then also try to make a PR for it). I'm still in conversation with our security team about it, but it doesn't feel like downloading the checksum for comparison to the downloaded standalone binary will make much of a difference to them at this stage. (I'm still trying to get clarity on whether the binaries being bundled with the package will make a difference to them security-wise)

matt.fellows
2021-10-21 02:14
Is the context as a user of the package? Are you assessing the security of our packages or for some other reason?

sadikshahidain
2021-10-21 02:15
Correct, as a user assessing security. This all started from someone pointing out that downloading a binary looked vaguely similar to how the CodeCov breach from earlier this year happened (fwiw I still don't fully understand what happened for that)

matt.fellows
2021-10-21 02:29
All the better reason to have the artifacts bundled into the package. You still need to put other zero trust mechanisms in place (which I?m sure you do!), but that will certainly reduce the # of flags being raised

sadikshahidain
2021-10-21 02:33
Yeah for sure. And lol idk about the "I'm sure you do" part though. Maybe "I sure hope you do" is more appropriate :sweat_smile: I'll definitely bring this context back to the security team though and see if we can't bring Pact back into the fold with maybe just tracking these concerns for now.

matt.fellows
2021-10-21 03:35
Alternatively, take a look at the v3 beta - it won?t have this problem and doesn?t need to embed Ruby or other stuff like that

artur
2021-10-21 06:21
the one that you set in the `Verifier` options I think it supposed to be the timeout for the state-handler. But it feels like accumulated for all state handlers.

matt.fellows
2021-10-21 06:23
Ah, the timeout is applied to all of the HTTP interactions from the core (Rust) to the outside world. So it will apply to the state handlers and also to the verification requests

matt.fellows
2021-10-21 06:24
Verbose logs _should_ show this, but knowing you Artur you would have tried that, so that tells me we may have a visibility problem

artur
2021-10-21 06:26
I can double check if I haven't looked detailed enough in the logs.

artur
2021-10-21 06:28
Is the timeout reset after every interaction / state handler or for all together? I cannot prove it yet but it looks to be that my tests are fine if I only run some of them but fail in the sum

matt.fellows
2021-10-21 06:30
see if you can bump that timeout for now

matt.fellows
2021-10-21 06:30
I can see that the timeout is used in a few places. For the rust _core_, the timeout is per request

matt.fellows
2021-10-21 06:31
but it looks like we?ve retained the timeout also at a higher level (i.e. for all verifications)


matt.fellows
2021-10-21 06:32
It?s 30s by default, but i?ve you?ve overridden that to something smaller that could be the cause

tjones
2021-10-21 06:50
To be clear, pact-js has never downloaded the checksum separately (it was bundled with the package). From the next major version (currently in beta), it bundles the binaries instead of the checksums. If you trust packages from npm, this is the same risk.

tjones
2021-10-21 06:53
I don't think the risk profile is any larger. Having an attacker compromise the binary is similar to compromising a dependency (which has happened before in npm, although not to pact-js).

tjones
2021-10-21 06:53
There's a good writeup of the CodeCov issue here - https://blog.gitguardian.com/codecov-supply-chain-breach/

artur
2021-10-21 06:57
I have a pact file with 185 interactions when I set the timeout to `30000` I get aound 101 failures increasing the timeout to `60000` only 79 I'm pretty sure no interaction or state handler takes 60sec by itself but the timeout corresponds to the overall runtime of the test. setting it to `30000` makes the verifier finish and fail after around 37 sec setting it to `60000` make the same set of tests fail after around 67 sec that makes me think its an overall timeout, or if its not supposed to be its not reset somewhere

artur
2021-10-21 06:58
also it cannot be set to more than `65535` https://github.com/pact-foundation/pact-js/issues/761

matt.fellows
2021-10-21 07:02
ah, I just read that and can see the issue

matt.fellows
2021-10-21 07:03
@tjones we have two timeouts that are being used for different purposes. We use the `timeout` value both as an overall verification timeout, and also a per-request timeout.

tjones
2021-10-21 07:04
We do. But the refusal to set it as higher than 65535 is the real problem

matt.fellows
2021-10-21 07:05
indeed

artur
2021-10-21 07:05
in the debug output I cannot see anything that indicates the timeout issue

artur
2021-10-21 07:06
this is the last output, it shows the request and response and it looks as expected to me#

tjones
2021-10-21 07:06
Yeah, I agree. This really highlights the need to do a full review of the rust logging

matt.fellows
2021-10-21 07:06
trace might have it

tjones
2021-10-21 07:06
It's saying that it can't connect to the state endpoint (the proxy in pact-js)

tjones
2021-10-21 07:07
`localhost` is suspicious. I think we should use an IP.

artur
2021-10-21 07:08
that is the other funny thing, after the crash it seems to forgotten the `providerBaseUrl`

artur
2021-10-21 07:08
`Request Failed - Invalid response: error sending request for url (http://localhost:38463/ocs/v1.php/apps/files_sharing/api/v1/shares/-1): error trying to connect: tcp connect error: Connection refused (os error 111)`

artur
2021-10-21 07:09
but I have definetely set the providerBaseUrl to `http://localhost/owncloud-core`

tjones
2021-10-21 07:10
Ah, so, pact-js lies to Rust about the providerBaseUrl

tjones
2021-10-21 07:10
because all requests go through a proxy

tjones
2021-10-21 07:11
(which is what `/_pactSetup` is hosted on)

artur
2021-10-21 07:12
and the proxy refuses the connection because it ran into a timeout


tjones
2021-10-21 07:12
it shouldn't.

tjones
2021-10-21 07:13
The timeout is unrelated to the proxy.

tjones
2021-10-21 07:16
I suspect the rust core is misreporting the error

tjones
2021-10-21 07:17
but it's hard to say for sure. I reckon we'll know more once we can fix the timeout issue

artur
2021-10-21 07:17
OK, that error message set me on a wrong path for debugging.

tjones
2021-10-21 07:17
Can you see the state change endpoint in the debug log?


tjones
2021-10-21 07:19
this file contains the logs that we're expecting

artur
2021-10-21 07:21
yes in the debug logs I see stuff like ```[2021-10-21 07:03:26.172 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: incoming request: {"body":{"action":"setup","params":{"password":"test123","username":"test123"},"state":"the user is recreated"},"headers":{"content-type":"application/json","accept":"*/*","host":"localhost:38463","content-length":"103"},"method":"POST","path":"/_pactSetup"} [2021-10-21 07:03:26.173 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state '{"action":"setup","params":{"password":"test123","username":"test123"},"state":"the user is recreated"}' [2021-10-21 07:03:26.173 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state 'the user is recreated' [2021-10-21 07:03:27.015 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: outgoing response: {"body":"{\"description\":\"user created\"}","headers":{"x-powered-by":"Express","content-type":"application/json; charset=utf-8","content-length":"30","etag":"W/\"1e-14HI00Phtn5NGrwCVZx+5BZjkfQ\""},"status":200} [2021-10-21 07:03:27.017 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: incoming request: {"headers":{"authorization":"Basic YWRtaW46YWRtaW4=","accept":"*/*","host":"localhost:38463"},"method":"GET","path":"/ocs/v1.php/cloud/users"} [2021-10-21 07:03:27.017 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: Proxying /ocs/v1.php/cloud/users [2021-10-21 07:03:27.251 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: outgoing response: {"body":"<?xml version=\"1.0\"?>\n<ocs>\n <meta>\n <status>ok</status>\n <statuscode>100</statuscode>\n <message/>\n </meta>\n <data>\n <users/>\n </data>\n</ocs>\n","headers":{"x-powered-by":"Express","date":"Thu, 21 Oct 2021 07:03:27 GMT","server":"Apache/2.4.46 (Ubuntu)","set-cookie":["ocuv4s8d5xsv=pq9fivhtej6736u6fhm51ekkor; path=/owncloud-core; HttpOnly; SameSite=Strict","oc_sessionPassphrase=pTH22542LqN9UmfyQ9N%2FKlC%2BGDTfCsYIvdcRjvkJrff%2Bk6bL01HqwuiyrFD1N%2FK37MvpV0og5uvWoqsj6PP6IrmBglPVspMM25O6uc5iEwGXowF2HJBrj%2F08x9cMJzpP; path=/owncloud-core; HttpOnly; SameSite=Strict","ocuv4s8d5xsv=p5dlregcibbjfjf5sjp0tae7i2; path=/owncloud-core; HttpOnly; SameSite=Strict","cookie_test=test; expires=Thu, 21-Oct-2021 08:03:27 GMT; Max-Age=3600","oc_username=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core; HttpOnly","oc_token=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core; HttpOnly","oc_remember_login=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core; HttpOnly","oc_username=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core/; HttpOnly","oc_token=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core/; HttpOnly","oc_remember_login=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/owncloud-core/; HttpOnly","ocuv4s8d5xsv=vth47qc2ls0mm09a5n16gmalep; path=/owncloud-core; HttpOnly; SameSite=Strict","ocuv4s8d5xsv=9024b41hio8lds8h5crr79s30l; path=/owncloud-core; HttpOnly; SameSite=Strict"],"expires":"Thu, 19 Nov 1981 08:52:00 GMT","cache-control":"no-store, no-cache, must-revalidate","pragma":"no-cache","content-security-policy":"default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src *; img-src * data: blob:; font-src 'self' data:; media-src *; connect-src *","x-xss-protection":"0","x-content-type-options":"nosniff","x-frame-options":"SAMEORIGIN","x-robots-tag":"none","x-download-options":"noopen","x-permitted-cross-domain-policies":"none","vary":"Accept-Encoding","content-length":"146","connection":"close","content-type":"text/xml; charset=UTF-8"},"status":200} [2021-10-21 07:03:27.254 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: incoming request: {"body":{"action":"teardown","params":{"password":"test123","username":"test123"},"state":"the user is recreated"},"headers":{"content-type":"application/json","accept":"*/*","host":"localhost:38463","content-length":"106"},"method":"POST","path":"/_pactSetup"} [2021-10-21 07:03:27.254 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state '{"action":"teardown","params":{"password":"test123","username":"test123"},"state":"the user is recreated"}'```

artur
2021-10-21 07:21
and that all looks correct to me

tjones
2021-10-21 07:22
I agree. I suspect the Rust core is not reporting the correct error (although it does seem strange)

artur
2021-10-21 07:24
the `setting up state` log comes twice. First with the JSON then with the name

artur
2021-10-21 07:25
```[2021-10-21 07:03:23.165 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state '{"action":"setup","params":{"password":"test123","username":"test123"},"state":"the user is recreated"}' [2021-10-21 07:03:23.165 +0000] DEBUG (26566 on deepthought3): pact@10.0.0-beta.53: setting up state 'the user is recreated'```

tjones
2021-10-21 07:26
Yeah, looks like the logs there have a few issues. Firstly, it says `Setting up state` when it should say `Received state change request`, and should probably be a trace log. Secondly, we don't log at all if we ignore the state change request because we don't have a handler.

tjones
2021-10-21 07:26
Well, we do, but only if there's absolutely no handler

tjones
2021-10-21 07:27
I think line 45 and 51 need else -> debug("Not tearing down state ${state}") (etc)

vasil.vasilev
2021-10-21 08:41
has joined #pact-js

ben.crinion
2021-10-21 11:09
has joined #pact-js

ben.crinion
2021-10-21 11:14
Hi, we're getting an error when trying to verify pacts for messages and for a rest contract with the same participant name. We've come across a fairly old github issue (https://github.com/pact-foundation/pact-js-core/issues/179). Is it still the case that we need different participant names for our message and rest pacts?

vince.lee
2021-10-21 11:17
hi folks we are in the process of building out our contract test suite with pact, and have run into an issue when we come to test a new message. :thread:

vince.lee
2021-10-21 11:18
we have a single `MessageProviderPact` test as follows, which works fine: ```// my-message-a.test.ts describe('my message A', () => { const p = new MessageProviderPact({ messageProviders: { 'part-ex-cancellation-completed event': () => Promise.resolve({ foo: 'bar' }), }, stateHandlers: { 'part-ex is removed from a delivered order': async () => { // setup some state return Promise.resolve(); }, 'part-ex is removed from a collected order': async () => { // setup some other state return Promise.resolve(); }, }, verbose: true, provider: 'my-provider', providerVersion: versionFromGitTag(), consumerVersionTags: ['local-stage'], providerVersionTags: [process.env.BRANCH_NAME, process.env.STAGE], enablePending: false, pactBrokerUrl: 'https://me.pactflow.io', pactBrokerToken: process.env.PACT_BROKER_TOKEN, publishVerificationResult: true, }); it('matches the contract', async () => { return await p.verify(); }); });```

vince.lee
2021-10-21 11:19
when we come to create a new test, for a different message, we copy this file and add it as a new one. however, when we run the contract tests in jest, the first test fails

vince.lee
2021-10-21 11:19
i got around this by adding both sets of stateHandlers and messageProviders into the single test file, but imagine this will become unwieldy and slow

vince.lee
2021-10-21 11:20
what's the best way to have multiple test files?

vince.lee
2021-10-21 11:29
we are using http://pactflow.io as the broker

matt.fellows
2021-10-21 11:49
What do you mean ?when we come to create a new test?? The short answer is, I think, at the moment I think, you can?t.

matt.fellows
2021-10-21 11:49
you could create separate providers that only test specific consumers though

matt.fellows
2021-10-21 11:49
i.e. use `consumerVersionSelectors` and use the consumer to split the tests apart

achuljyan
2021-10-21 19:20
Hello, It looks like pact Verifier doesn't have a parameter to write logs to a file (like Pact's "log" parameter). At least according to this doc: https://github.com/pact-foundation/pact-js#verification-options Why not have such option for Verifier?

estephania.calvo
2021-10-21 19:27
has joined #pact-js

ahmetbcakici
2021-10-21 22:38
has joined #pact-js

sadikshahidain
2021-10-22 01:41
Yeah that's the sort of case I made to our security team earlier today, that if/once the binary is bundled it's just like any other dependency. (haven't heard back yet though) Also I know this is the wrong channel but should I write up an issue for PHP to bundle the binary? I'm not sure what's involved but I'd be willing to tackle it myself, unless you all already had plans to do so or it requires more context than I'd be able to gain

matt.fellows
2021-10-22 01:51
that?d be great, thanks!

vince.lee
2021-10-22 08:24
> What do you mean ?when we come to create a new test?? when we want to test a different message published by the provider eg we have a 'part-ex-cancellation-completed' event as above, but we also publish 'part-ex-cancellation-failed' is it that we should just have a single test file, into which we load lots of different messageProviders to satisfy all of consumers?

matt.fellows
2021-10-22 08:49
yeah that?s right. You can still split the handlers etc. into separate files, but it does require a single entrypoint to configure what is verified

abarcadabra
2021-10-22 12:30
has joined #pact-js

harwin1494
2021-10-22 19:04
has joined #pact-js

anindita.ghosh
2021-10-22 23:26
has joined #pact-js

tjones
2021-10-24 12:52
Looks like this is an oversight - it is supported, but the option doesn't seem to be documented.

tjones
2021-10-24 12:54
`logDir` will tell it where the log directory should be

tjones
2021-10-24 12:54
You can also use `out` to tell it to write the output to a file instead of standard out.

tjones
2021-10-24 12:54
However, both of these options will be removed in the next version - what is the use case for wanting the logs to go to a file?

sadikshahidain
2021-10-25 04:32
Wrote up this issue - https://github.com/pact-foundation/pact-php/issues/227 As a next step for me I'll try to figure out/understand how Pact-JS is doing the bundling of the binary in the beta channel today, so if y'all have any quick pointers for that just lmk

matt.fellows
2021-10-25 04:35
Thanks!

tjones
2021-10-25 06:21
@sadikshahidain: https://github.com/pact-foundation/pact-js-core/blob/master/script/download-libs.sh ^ This downloads all the libraries (the Ruby binaries and the Rust FFI libraries). The first script mentioned there reads the versions that we're expecting out of our source code, and then exports them as environment variables.

tjones
2021-10-25 06:22
If you just want the download of the ruby standalone, this script (and the dependencies it names at the top) are all you need: https://github.com/pact-foundation/pact-js-core/blob/master/script/lib/download-standalone.sh

rajnish.maurya
2021-10-25 06:47
has joined #pact-js

alanbos
2021-10-25 10:11
has joined #pact-js

achuljyan
2021-10-25 12:24
It looks like https://github.com/pact-foundation/pact-js-core/issues/100 has been resolved : https://github.com/ruby/ruby/pull/4505 Is it possible to rebuild Pact with the latest Ruby version to get rid of the long path issue?

matt.fellows
2021-10-25 12:56
It's not that easy I'm afraid. We use traveling ruby which is major versions behind

matt.fellows
2021-10-25 12:57
I'd jump on the v3 beta or wait for that

achuljyan
2021-10-25 13:35
ok thank you @matt.fellows for the quick response

kuzmanovid
2021-10-25 13:59
has joined #pact-js

achuljyan
2021-10-25 14:05
btw when are you planning to release v3?

j.malyjasiak
2021-10-25 14:24
has joined #pact-js

rtbhosale17
2021-10-25 14:25
has joined #pact-js

stefano.mantini
2021-10-25 14:31
has joined #pact-js

r.muthukumar136
2021-10-25 14:59
has joined #pact-js

dimundo
2021-10-25 19:45
hi! if `"match": "type"` is declared in interaction in which cases it doesnt work and expects exact match, not type? could this be due to this ? ``` "metadata": { "pactSpecification": { "version": "2.0.0" } }```

dimundo
2021-10-25 19:46
consumer is pact-js v2 provider is pats4s ( aka jvm/scala )

gravis54
2021-10-25 21:46
has joined #pact-js

misha.antipenko
2021-10-25 21:57
has joined #pact-js

matt.fellows
2021-10-26 01:53
Soon, that's the best answer

matt.fellows
2021-10-26 01:54
We're currently blocked on an upstream issue with node FFI bindings

matt.fellows
2021-10-26 01:54
Aside from some minor API changes it's good to use IMO

matt.fellows
2021-10-26 01:55
Mmm that matcher should work

matt.fellows
2021-10-26 01:55
Any chance you could please share the pact and/or errors you're seeing Dmitry?

tjones
2021-10-26 03:05
How are you generating the matchers in your interaction?

dimundo
2021-10-26 05:40
``` it("should POST to resolve signal ", async() => { const path = POST_SIGNAL_RESOLVE_URL await provider.addInteraction({ state: "2. i will resolve signal", uponReceiving: "a request to resolve signal", withRequest: { method: "POST", path, headers: { "Content-Type": "application/json" }, body: { ...tableIdBody, signalId: string("ddd") }, }, willRespondWith: { status: 200 }, }) const res = await makePostRequest(provider.mockService.baseUrl + path, { ...tableIdBody, signalId: "signalguid" }) expect(res.status).toBe(200) expect(res.ok).toBeTruthy() await provider.verify() })```

dimundo
2021-10-26 05:40
```signalId: string("ddd")``` and ```signalId: like("ddd")``` makes same json

dimundo
2021-10-26 05:41
``` "body": { "tableId": "table1", "signalId": "ddd" }, "matchingRules": { "$.body.signalId": { "match": "type" } } },```

j.malyjasiak
2021-10-26 06:01
@j.malyjasiak has left the channel

matt.fellows
2021-10-26 06:44
hmm that looks fairly innocuous

tjones
2021-10-26 06:58
That looks right. It should match any string as `signalId`

dimundo
2021-10-26 07:00
looks like my brain was a bit melted - this works properly for consumer and provider tests were failing, because `ddd` wasnt something provider expects

matt.fellows
2021-10-26 07:02
:laughing:

matt.fellows
2021-10-26 07:02
you have plenty of credits in the bank Dmitry!

adomanski
2021-10-26 10:43
has joined #pact-js

kriegster108
2021-10-26 14:58
has joined #pact-js

jhopkinwilliams
2021-10-27 00:59
is it easy to set up pact with aws lambdas written in typescript? Also how would i. go about that?


matt.fellows
2021-10-27 01:13
Yes you can do it for sure

jhopkinwilliams
2021-10-27 01:17
Thanks Matt! Ill take a look at that. Is that a tutorial in that doco too?

matt.fellows
2021-10-27 01:23
I wouldn't call it a tutorial on AWS but yes there are tutorials there

tjones
2021-10-27 04:01
The answer is "yes, it's easy" and "how you set it up depends on whether your lambda is the provider or consumer, and if it is the provider (or a message consumer), how you are invoking it"

adam.witko
2021-10-27 07:36
has joined #pact-js

adam.witko
2021-10-27 07:42
Hey all :wave: I am looking to get on board with the recent migration to ?branch? stuff over in Pact. We use `@pact-foundation/pact` in our consumer/providers, which itself uses `@pact-foundation/pact-node` (renamed to pact-js-core). I have found https://github.com/pact-foundation/pact-js/issues/757 that looks to have no in progress or merged PR, so I?m thinking of picking it up. This looks to be a two part change to both the repos for `@pact_foundation_greet/pact-js-core` to expose and handler the new properties, then `@pact-foundation/pact` to use the updated pact-js-core package. Is anyone currently working on this, or am I good to get some PRs open? Cheers!

matt.fellows
2021-10-27 08:19
That'd be great! Not in front of my computer but there is probably already issues raised to do it

alex.macpherson
2021-10-27 08:28
has joined #pact-js

matt.fellows
2021-10-27 11:19
ah, you linked to the issue :laughing:

matt.fellows
2021-10-27 11:20
Just needs the new type added to pact-js-core, and then a version bump of that dependency in pact-js and it?s good to go

matt.fellows
2021-10-27 11:22
If you wanted to pick this related change up that would also be welcome: https://github.com/pact-foundation/pact-js/issues/750

adam.witko
2021-10-27 16:15
I?ll take a lookie. Do you, or anyone here, know if I need to contribute from forking then raising a PR to the pact-foundation/pact-js-core repo? It?s documented like this in the pact-js repo but not pact-js-core repo

yurich00
2021-10-27 18:10
has joined #pact-js

lincolnf
2021-10-27 23:30
has joined #pact-js

tjones
2021-10-28 01:47
Yes, that's right

tjones
2021-10-28 01:47
to get it into the main pact-js, we'll need to backport it to the `pact-node` branch in the pact-js-core repo

lawrencemajmacdonald
2021-10-28 07:33
has joined #pact-js

zsolt.vilagos
2021-10-28 10:00
has joined #pact-js

zsolt.vilagos
2021-10-28 10:01
@zsolt.vilagos has left the channel

norway.martin
2021-10-28 15:59
@norway.martin has left the channel

ramesh.dhanasekaran
2021-10-29 02:20
has joined #pact-js

matt.fellows
2021-10-29 05:16
:raised_hands:

matt.fellows
2021-10-29 05:16
Reminder to myself to manually compile / upload Arm artifacts for M1 users

matt.fellows
2021-10-29 05:16
I think the previous release version artifacts should work because we haven't changed the rust code

matt.fellows
2021-10-29 05:16
But I'll verify

harwin1494
2021-10-29 08:22
Hey all, I am getting this error while running the pact test at the consumer side. Correct me if I am wrong, but as per my understanding we can write consumer tests giving no relevance to what an actual provider will respond like, so if I am providing any status code to be validated in my test script, should I be getting this error? (The line here is from the actual micro-service js file).

matt.fellows
2021-10-29 08:25
What's the actual problem, we can't tell from that code

matt.fellows
2021-10-29 08:27
Please share your test code

harwin1494
2021-10-29 08:31
```d```

harwin1494
2021-10-29 08:31
I am unable to get a the exact code here, some problem with my ide.

christopher.mcewen
2021-10-29 12:14
has joined #pact-js

catalin.comarnescu
2021-10-29 12:31
has joined #pact-js

sushant.soni
2021-10-29 12:32
@catalin.comarnescu

catalin.comarnescu
2021-10-29 12:34
hi @uglyog, can we find more details about this change somewhere?

catalin.comarnescu
2021-10-29 12:34
seems lack of capture groups prevents us from using e.g. OR between terms

catalin.comarnescu
2021-10-29 12:35
``` "mismatches": [{ "attribute": "body", "description": "Expected 'look_bordered' to match 'look|look_bordered|slider_cta'", "identifier": "$.data.content.items.0.type" }],```

catalin.comarnescu
2021-10-29 12:35
tried with and without the brackets

catalin.comarnescu
2021-10-29 12:35
again, this was working fine (with the capture group) with pact-js v2

mui_ume
2021-10-29 12:52
Hi Matt, I clone from this git repo https://github.com/pactflow/example-consumer when I run npm start, I got this error × TypeError: Cannot read properties of undefined (reading ?endsWith?)

mui_ume
2021-10-29 13:10
I need to add the .env file and define REACT_APP_API_BASE_URL=http://localhost:3000 but I got ```Error: Request failed with status code 404```

kiran.rudrangi
2021-10-29 16:48
has joined #pact-js

matt.fellows
2021-10-29 21:34
It's not designed to be run without the backend. See the usage in the readme

matt.fellows
2021-10-29 21:34
It is designed to run tests though

uglyog
2021-10-30 00:53
Is that with Pact-JS or Pact-JVM. I did a quick test with Pact-JVM, and that regex works as exepected

matt.fellows
2021-10-30 02:04
Can you please share the versions of software producing the pact file and verifying it?

mui_ume
2021-10-30 02:36
are u referring to this part of the README.md ```To be able to run some of the commands locally, you will need to export the following environment variables into your shell: PACT_BROKER_TOKEN: a valid API token for Pactflow PACT_BROKER_BASE_URL: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io PACT_PROVIDER=pactflow-example-provider-dredd: this changes the default provider to the Dredd based provider (https://github.com/pactflow/example-provider-dredd) PACT_PROVIDER=pactflow-example-provider-postman: ... Postman (https://github.com/pactflow/example-provider-postman) PACT_PROVIDER=pactflow-example-provider-restassured: ... Rest Assured (https://github.com/pactflow/example-provider-restassured)```

mui_ume
2021-10-30 02:36
I follow the above and I did the next section make test, it give me the error ```TypeError: Cannot read property 'endsWith' of undefined 10 | url = process.env.REACT_APP_API_BASE_URL; 11 | } > 12 | if (url.endsWith("/")) { | ^ 13 | url = url.substr(0, url.length - 1) 14 | } 15 | this.url = url```


mui_ume
2021-10-30 02:43
I was following this youtube workshop, which part of it show the backend setup?

mui_ume
2021-10-30 03:37
sorry matt, it?s at 0:34, I got it work now

matt.fellows
2021-10-30 05:27
You don't run the provider at all as part of testing

matt.fellows
2021-10-30 05:28
There is a corresponding provider project you can run to see the application working

matt.fellows
2021-10-30 05:28
But for the purposes of contract testing you don't need to start the app

mui_ume
2021-10-30 05:39
I run npm start at the example-consumer, it start localhost:3000 with this error on the page ```Error: Request failed with status code 404```

matt.fellows
2021-10-30 05:54
For posterity, I was referring to the usage instructions: https://github.com/pactflow/example-consumer#usage

mui_ume
2021-10-30 05:57
got it work ! thanks I run npm start at the git repo example-provider-dredd

jhopkinwilliams
2021-11-01 01:35
Hey Matt, I set up 2 very basic APIs with serverless on AWS lambda. Basically 1 just returns some City data and the other request calls this function to receive the data. Im a bit lost on the documentation for this: https://docs.pactflow.io/docs/examples/aws/sns/consumer/readme/ and I am not too sure on how to get this set up for my organisation. Im not really a developer you see.

matt.fellows
2021-11-01 01:48
The one caller the other just uses a standard pact test, nothing AWS specific there

matt.fellows
2021-11-01 01:48
Assuming you have it behind AWS API Gateway, The way to think about the HTTP AWS one is this

matt.fellows
2021-11-01 01:49
If you can start the API locally (e.g. serverless local) it just looks like any other provider pact test and there is nothing AWS specific about it

matt.fellows
2021-11-01 02:20
make sense?

jhopkinwilliams
2021-11-01 03:00
sorry Matt, i wasnt at my desk just then

jhopkinwilliams
2021-11-01 03:01
what I normally do is ```sls deploy``` I havent tried to start serverless locally before

jhopkinwilliams
2021-11-01 03:03
do you have a link to a bare bones consumer test i can put in my repo?

matt.fellows
2021-11-01 06:13
All of those examples are a good starting point


saurabh.goel
2021-11-01 12:58
hi everyone, I am successfully able to inject values from provider for APIs https://docs.pact.io/implementation_guides/jvm/consumer/junit/#having-values-injected-from-provider-state-callbacks-3611. Is there something similar for message pacts? like I have a field in "contents" of my messagepact, which i would like to dynamically substitute by my provider state variable.

matt.fellows
2021-11-01 13:28
The state handlers are the same as for HTTP so yes you should

tjones
2021-11-01 14:36
However, pact-js does not yet support them. You can use the beta, which will bring you these features, but it's not stable.

saurabh.goel
2021-11-01 14:36
ohh, ok thanks timothy

saurabh.goel
2021-11-01 14:36
and matt

ahmed_syed
2021-11-01 20:46
has joined #pact-js

matt.fellows
2021-11-01 23:34
ah I did misread that. I thought you were already using the beta. Thanks for clarifying Tim

somayajulaas
2021-11-02 00:38
has joined #pact-js

john
2021-11-02 03:32
has joined #pact-js

harwin1494
2021-11-02 08:19
Hi, I am trying to use matcher in PACT-js but getting this error, do I need to run npm install again?

harwin1494
2021-11-02 08:48
Update :- I added `import { Matchers } from '@pact-foundation/pact';` and the above error got resolved. But now getting reference error. Please help.

matt.fellows
2021-11-02 08:51
somethingLike isn't a function

matt.fellows
2021-11-02 08:51
That's why it's failing

matt.fellows
2021-11-02 08:51
`like` is probably what you want

harwin1494
2021-11-02 08:52
even that is throwing the same error

harwin1494
2021-11-02 08:55
@matt.fellows

tjones
2021-11-02 08:58
You probably want `Matchers.like` - have a look in the examples to see how it is done there

catalin.comarnescu
2021-11-02 08:59
Pact file is produced by Pact JVM 4.0.10, verified using pact-js 10.0.0-beta.52

harwin1494
2021-11-02 09:01
I am going through examples here https://docs.pact.io/implementation_guides/javascript/readme#match-common-formats, but couldnt find `Matchers.like`. Can you point me to the right one?

catalin.comarnescu
2021-11-02 09:04
``` "$.data.content.items[*].type": { "matchers": [{ "match": "regex", "regex": "(look|look_bordered|slider_cta)" }], "combine": "AND" },```

catalin.comarnescu
2021-11-02 09:04
this is the generated matcher

harwin1494
2021-11-02 09:06
it worked, thanks Tim. But while searching the channel for matchers example, simply using like/somethingLike also worked, is it related to some updates?

matt.fellows
2021-11-02 09:26
Some people alias code etc

matt.fellows
2021-11-02 09:26
The examples in the pact JS repo all are correct, so they should be a starting point rather than random people's code

rochitsen
2021-11-02 10:49
has joined #pact-js

catalin.comarnescu
2021-11-02 12:12
or the variant without the brackets

catalin.comarnescu
2021-11-02 12:12
``` "$.data.content.items[*].type": { "matchers": [{ "match": "regex", "regex": "look|look_bordered|slider_cta" }], "combine": "AND" },```

catalin.comarnescu
2021-11-02 12:13
but of course this one wouldn?t work as it?s not a valid regex

matt.fellows
2021-11-02 12:31
It looks like a valid regex to me. What's not valid about it?

finta.pl
2021-11-02 14:43
has joined #pact-js

catalin.comarnescu
2021-11-02 16:07
hm actually you?re right. but again, both fail the same way, with or without the brackets

catalin.comarnescu
2021-11-02 16:08
```"mismatches": [{ "attribute": "body", "description": "Expected 'look_bordered' to match '(look|look_bordered|slider_cta)'", "identifier": "$.data.content.items.0.type" }],```

alessandro.borraccino
2021-11-02 17:04
has joined #pact-js

myao
2021-11-02 22:23
has joined #pact-js

matti.anusha
2021-11-03 02:58
has joined #pact-js

ozgurerisir
2021-11-03 10:29
has joined #pact-js

christian.kampka
2021-11-03 13:23
Is there a way to have a pact include cors requests in the API contracts? I know that I can set `cors: true` on the consumer side, wich tells the mock server to "tollerate" a pre-flight request, but it does not seem to be recorded as part of the contract.

matt.fellows
2021-11-03 20:32
If it needs to be in the contract you should put it in the contract

matt.fellows
2021-11-03 20:33
There's no one set of CORS headers, you should specify the ones you need

john
2021-11-04 04:07
any idea how to resolve this: PactBroker::Client::Hal::ErrorResponseReturned - Error making request to https://dfsfds.pactflow.io status=401 Unauthorized. Please see https://docs.pactflow.io/docs/login-help for more information.

john
2021-11-04 04:07
I went through the documentation but everything seemed ot be ok

matt.fellows
2021-11-04 04:08
Can you please share your config that's failing?

john
2021-11-04 04:09
Sorry Matt what do you mean config?

matt.fellows
2021-11-04 04:09
401 means what you think it means. Are you using the correct bearer token?

john
2021-11-04 04:10
i go to the pactflow website

john
2021-11-04 04:10
and click the cog setting and get the read/write tokens

john
2021-11-04 04:11
i then dump them in a .env file

matt.fellows
2021-11-04 04:11
Thata the one!

john
2021-11-04 04:11
you want me to share the tokens with you?

matt.fellows
2021-11-04 04:11
Nah that's fine

john
2021-11-04 04:12
so all i do is click "Copy env vars" and paste it into my .env file

matt.fellows
2021-11-04 04:12
Are you sure it's the correct env car?

john
2021-11-04 04:12
the test:consiumer works

matt.fellows
2021-11-04 04:12
var*

john
2021-11-04 04:12
just not the publishing

matt.fellows
2021-11-04 04:13
Consumer doesn't need the token to run tests

matt.fellows
2021-11-04 04:13
What env var is it?

john
2021-11-04 04:14
i only have 2 env set the base url and the token

john
2021-11-04 04:15
PACT_BROKER_BASE_URL and PACT_BROKER_TOKEN

matt.fellows
2021-11-04 04:15
How does npx know about your .env file?

john
2021-11-04 04:16
good point

john
2021-11-04 04:17
where would i put that

john
2021-11-04 04:17
i put require('dotenv').config()

john
2021-11-04 04:17
in my consumerpact test

matt.fellows
2021-11-04 04:20
You put it in the environment directly or wrap it in a shell script.

matt.fellows
2021-11-04 04:21
It's usually only used in CI (publishing that is)

john
2021-11-04 04:51
ok no worries I will try that

uladzislau_danilchyk
2021-11-04 10:04
Hi all! Please, help me with checking specified array item. The problem is that array items can vary. And I need to check all of possible items structure in array. How to do that?

matt.fellows
2021-11-04 10:14
The new beta has an `arrayContaining` matcher that can do this: https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0#using-the-v3-matching-rules

john
2021-11-04 23:47
thanks that worked!

john
2021-11-05 02:40
just a quick question. I really enjoyed the Katacode tutorial for a basic pact consumer / providers scenario. Do you have something similar for something that uses aws lambdas and uses SQS? I know there is a work shop on that which uses SNS, im going to work through shortly. Another question what is the use of "can i deploy" if you have pact tests and you run them and they fail - you should not deploy then right?

tjones
2021-11-05 02:41
What Katacode tutorial?


tjones
2021-11-05 02:41
Oh right. That's a pactflow tutorial, and no, we don't have anything like that

john
2021-11-05 02:42
appologies dev isnt my strong point

tjones
2021-11-05 02:42
So, can-i-deploy is used to check version compatibility

john
2021-11-05 02:42
but my collegue was say the lambda uses an event bridge

tjones
2021-11-05 02:42
The pact tests are only one half of the equation

tjones
2021-11-05 02:43
Your pact tests say "I am confirming I can send these requests and understand these responses", and they generate a pact file

tjones
2021-11-05 02:43
that pact file can then be shared with the broker so that it can be verified by the provider

john
2021-11-05 02:43
my collegue send that the lamdas they hit arent like endpoints

tjones
2021-11-05 02:43
pact verification says "I am confirming I can understand these requests and generate these responses"

tjones
2021-11-05 02:44
can-i-deploy is used to see if the verification has run successfully with the versions in whatever environment you are deploying to.

tjones
2021-11-05 02:45
"ok, my pact tests pass, and I generated the contract (pact file). Now, is that contract implemented by my provider in the environment I want to deploy to?"

john
2021-11-05 02:45
when you say version. what do you mean? Do you mean version of the libaries your using?

tjones
2021-11-05 02:45
^ That's the question that can-i-deploy asks

tjones
2021-11-05 02:45
no, I mean version of the software that you're testing

john
2021-11-05 02:45
ah ok i see

john
2021-11-05 02:46
if i want to get up and running with the lambdas the best place for that would be that sns workshop?

tjones
2021-11-05 02:47
we don't have an sns workshop, as far as I am aware

tjones
2021-11-05 02:47
we have examples, though


john
2021-11-05 02:49
so that example should work with lambdas on aws right?

tjones
2021-11-05 02:50
Yes. (from memory I think that might even be what's tested there).

tjones
2021-11-05 02:50
However, there's a subtlety in that message pacts only check the content - they don't send and receive the messages like the http pacts do

tjones
2021-11-05 02:51
We're working on pact plugins that will enable the testing of actually sending and receiving messages

tjones
2021-11-05 02:51
Testing the content is still valuable, since that's the part that usually drifts

john
2021-11-05 02:52
is that pactflow?

john
2021-11-05 02:52
is pactflow and pact the same thing? Sorry if i seem confused

tjones
2021-11-05 02:54
No. Pactflow is a hosted broker (with extra features that work well for enterprise users, such as federated login and support for things like running verification backwards from OpenAPI specs)

tjones
2021-11-05 02:54
Pact is the open source project

tjones
2021-11-05 02:54
Pactflow happens to be run by many of the pact core maintainers, but the open source project has been around longer.

john
2021-11-05 02:54
how do you share the pacts with open source project?

tjones
2021-11-05 02:54
With the broker

john
2021-11-05 02:55
all the examples ive done so far was with that pactflow

tjones
2021-11-05 02:55
There's a docker image. If you don't want to set up your own broker, then Pactflow is a very easy option.

tjones
2021-11-05 02:55
That's because you're doing pactflow examples, it sounds like.

tjones
2021-11-05 02:55
The technology is the same.

tjones
2021-11-05 02:55
(except pactflow has more enterprise features)

tjones
2021-11-05 02:56
I'm not familiar with the pactflow examples because I don't maintain them

john
2021-11-05 02:56
all i need to do is to have a basic template for my development teams to be able to start using contract testing throughout the organisation. They mainly use aws lambdas

tjones
2021-11-05 02:56
Right. I would start with the example I sent you

john
2021-11-05 02:57
ok great, does that example use the broker?

tjones
2021-11-05 02:57
yes, all the examples do


john
2021-11-05 02:57
so just clone that and run it right?

tjones
2021-11-05 02:57
(in pact JS, our test broker is very kindly provided by pactflow)


tjones
2021-11-05 02:58
but, any code that speaks to the pactflow broker will also speak to the OSS broker

john
2021-11-05 02:58
ok i see great. thanks so much Timothy, im probably the least qualified person to be setting this up as i dont know anything about contract testing lol

john
2021-11-05 02:58
OSS is the open source broker right?


tjones
2021-11-05 02:59
yes, sorry. OSS as in "Open Source Software"

john
2021-11-05 02:59
ok ill clone that and let you know how i. get on thanks for your help


john
2021-11-05 03:35
hey Timothy

john
2021-11-05 03:36
I just cloned the repo and got the consumer running but im getting an issue with th e publishing. I didnt see in the example readme if i need any specific export env . I have some set up already for pactflow though

john
2021-11-05 03:38
i see that the package.json has this: ```--broker-base-url=https://test.pact.dius.com.au"```

john
2021-11-05 03:45
ok I got it working with using pactflow. @tjones if i want to use this without pactflow what credentials would i have to use etc?

tjones
2021-11-05 03:46
You would have to set up your own broker in your own infrastructure, and use the credentials you set up

tjones
2021-11-05 03:47
In my view it is much easier to use pactflow, which I can safely say because I don?t work for them

john
2021-11-05 03:48
ok i think for my need just have a working demo is valuable for the time being,

john
2021-11-05 03:48
thanks for all your help.

abubics
2021-11-05 06:21
:taco: for @tjones :tada:

dean.miley1
2021-11-05 11:40
has joined #pact-js

martha.nolan
2021-11-05 11:50
has joined #pact-js

martha.nolan
2021-11-05 12:14
Hi all, I'm currently trying to test a GraphQL request that uses `GET`, not `POST` . I've discovered that the `GraphQLInteraction` wrapper automatically adds the query to the request body & using a normal interaction causes the query to be parsed incorrectly. Is there a suggested way around this? Thanks!

matt.fellows
2021-11-05 12:16
If you look at that wrapper it's pretty basic

matt.fellows
2021-11-05 12:17
You might be able to overload the method (I'm on mobile so hard to check), or you could just steal it for your own purposes and modify it to work

matt.fellows
2021-11-05 12:18
A PR to allow the method to override would be good, but how does it work over GET if it sends a body? That's unusual

martha.nolan
2021-11-05 12:22
ah sorry, the request doesn't send a body - that's exactly the problem with using the current `GraphQLInteraction` - it seems to only account for `POST` requests.

matt.fellows
2021-11-05 12:22
Right, it's packed in a query string

matt.fellows
2021-11-05 12:22
I think you'll need to write your own wrapper

matt.fellows
2021-11-05 12:23
It should be easy enough to do, all graphql is is an abstraction on HTTP which Pact can handle.

matt.fellows
2021-11-05 12:26
If you get that working locally we can update Pact JS with the learnings if you're happy to share

matt.fellows
2021-11-05 12:26
I'm off for the night, but happy to support you in this thread

martha.nolan
2021-11-05 12:35
Ok, thanks for your help @matt.fellows

eniko_kollar
2021-11-05 16:46
has joined #pact-js

ashwin
2021-11-05 17:58
has joined #pact-js

d.philipp
2021-11-08 03:51
has joined #pact-js

romuald.quantin
2021-11-08 09:56
Hi @matt.fellows Thanks for the support, @martha.nolan is preparing a PR, that sounds like the best approach

romuald.quantin
2021-11-08 09:58
I'm still surprise we cannot do that with pact-js yet Either we are missing something, or devs don't use pact with graphql, or devs don't cache things, or they approach caching differently (must read: https://www.apollographql.com/blog/backend/caching/graphql-caching-the-elephant-in-the-room/) Any insights @matt.fellows? I want to make sure we are not missing a point, as our graphql endpoint will have http caching (which forces us to use `GET`)

matt.fellows
2021-11-08 09:59
I?ve never seen the request

matt.fellows
2021-11-08 09:59
it?s possible that people are doing it and have just wrapped it themselves

matt.fellows
2021-11-08 10:00
I also suspect a lot of people don?t use GraphQL very efficiently :stuck_out_tongue:

matt.fellows
2021-11-08 10:00
(I remember when I last did GraphQL that caching was an issue, i?m not sure if the `GET` based approach was an option then ~2016/2017)

romuald.quantin
2021-11-08 10:45
right, thanks for that :wink:

matt.fellows
2021-11-08 11:02
Also an opinion, but we often get people saying ?We don?t need to use Pact because GraphQL is type safe?

matt.fellows
2021-11-08 11:03
You can replace GraphQL with protobufs/OpenAPI/? and the story is the same

matt.fellows
2021-11-08 11:04
see also https://pactflow.io/blog/the-case-for-contract-testing-protobufs-grpc-avro/. The focus is protobufs, but problems 1-3 are usually the same

hamzah.saleem
2021-11-08 11:22
has joined #pact-js

srividya.ece
2021-11-08 12:17
has joined #pact-js

markus.joschko
2021-11-08 13:13
has joined #pact-js

matias.waterloo
2021-11-08 13:36
Hi! We upgraded pact-js and jest-pact to 9.16.5 and 0.9.1 and we are seeing a strange behaviour: the tests fail every time for a team mate but run fine for the rest of the developers. AFAIK we are using same config. Any ideas? ```thrown: "Exceeded timeout of 5000 ms for a hook. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 23 | } from '../mocks/pact/payments-fixtures'; 24 | > 25 | pactWith( | ^ 26 | { 27 | consumer: 'bff', 28 | provider: 'paymentsService', at setupProvider (node_modules/jest-pact/dist/pactWith.js:9:5) at node_modules/jest-pact/dist/pactWith.js:22:15 at node_modules/jest-pact/dist/internal/withTimeout.js:25:9 at Object.<anonymous>.exports.withTimeout (node_modules/jest-pact/dist/internal/withTimeout.js:5:5) at pactWithWrapper (node_modules/jest-pact/dist/pactWith.js:21:19) at node_modules/jest-pact/dist/internal/scaffold.js:7:69 at Object.pactWith (node_modules/jest-pact/dist/internal/scaffold.js:7:12) at Object.<anonymous> (src/__tests__/datasources/payments.test.ts:25:1)```

akke.luukkonen
2021-11-08 13:38
Coworker laptop just a bit too slow? We have this in our tests: ```// Jest timeout includes before/after hooks in addition to the tests themselves. // Sometimes cold starting Pact mock server takes a while, so default timeout of // 5 seconds is always not enough and may result in random failures on some machines. jest.setTimeout(15 * 1000);```

matt.fellows
2021-11-08 13:46
Seems plausible

matias.waterloo
2021-11-08 13:53
it worked!! thanks!

akanksha.sharma
2021-11-08 14:12
Hi All, I need to start Kafka consumer driven contract testing, can anyone suggest how to start it with Pactflow or can anyone share any documents or github link for the same.

belugin.v
2021-11-08 17:16
has joined #pact-js

matt.fellows
2021-11-08 22:01
We have a few examples here: https://docs.pactflow.io/docs/examples/

john
2021-11-09 01:48
just a question on teh Explanation for the message pact example. In the read me for the provider it says : We configure Pact to stand-in for the queue. The most important bit here is the `handlers` block but i dont see a handlers block in the example under number 2

matt.fellows
2021-11-09 03:25
Where are you reading sorry John?


tjones
2021-11-09 04:05
@matt.fellows - I think that's in the Go readme: https://docs.pact.io/implementation_guides/go/readme/#provider-producer - and it does look like that example might be missing the handlers block (from a skim read)

matt.fellows
2021-11-09 04:20
thanks, this is the JS channel so that would be confusing

matt.fellows
2021-11-09 04:20
but indeed, it?s missing that context


will.griffiths
2021-11-09 05:25
has joined #pact-js

john
2021-11-09 05:52
sorry I didnt see this thread, but I was refering to this: https://github.com/pact-foundation/pact-js/tree/master/examples/messages

john
2021-11-09 05:53
also it took me a while to figure out that: "All handlers to be tested must be of the shape `(m: Message) => Promise<any>` - that is, they must accept a `Message` and return a `Promise`." refered tot he syncronousBodyHandler.

matt.fellows
2021-11-09 05:53
yes, I can see why that would be confusing

matt.fellows
2021-11-09 05:54
that?s the consumer side

matt.fellows
2021-11-09 05:54
the provider side have `messageProviders` . Probably those docs got a little out of sync with reality

john
2021-11-09 05:56
Sorry for the random question but do you have any plans to implement all this for rust?

john
2021-11-09 05:57
like for example if we have a front end with react or something but your server is written in rust


matt.fellows
2021-11-09 05:59
There is the CLI and technically there are methods to call it I think. Probably best asking in #pact-rust

john
2021-11-09 06:00
tere is a pact-rust channel i dont see that let me check it out , thanks thats cool

navilooz
2021-11-09 08:48
has joined #pact-js

yousafn
2021-11-09 10:55
This topic has just come up at our work as a client is using graphql with a get request. So interested to see how you get on, or share any learnings

matt.fellows
2021-11-09 10:59
everyone comes out of the woodwork now :wink:

keith.hirst
2021-11-09 12:13
has joined #pact-js

martha.nolan
2021-11-09 12:19
Will keep you posted!

matt.fellows
2021-11-09 12:32
that?d be ace, thanks!

rbo
2021-11-09 17:47
has joined #pact-js

harshaan.n.khan
2021-11-10 05:38
has joined #pact-js

akanksha.sharma
2021-11-10 11:52
Thanks Matt for the documents. Can you please share me a guide like katacoda for Kafka as well in which a sequence is mentioned for consumer and provider tests. In the above examples there are a lot of files, not sure from where it is starting. Also, can you please let me know the commands to run the tests?

matt.fellows
2021-11-10 12:53
we don?t have a katacoda for Kafka I?m afraid (but assuming you?ve used the others and they were helpful?)

matt.fellows
2021-11-10 12:54
the commands are `make test` to run the tests locally

matt.fellows
2021-11-10 12:54
if you have your Pactflow environment variables available, you can emulate a CI build with `make fake_ci`

matt.fellows
2021-11-10 12:55
I?m not sure why, but we should have https://docs.pactflow.io/docs/examples/js/consumer/readme#pre-requisites on running them on that project also, i?ll fix that tomorrow

akanksha.sharma
2021-11-10 12:59
I can see node kafka consumer in example, I cannot see node Kafka producer, do we have that ?

akanksha.sharma
2021-11-10 13:01
and yes, I used Katacoda for contract test for product Api and it was very helpful and easy to understand. That's why I was looking for katacoda for Kafka as well

matt.fellows
2021-11-10 13:02
> I can see node kafka consumer in example, I cannot see node Kafka producer, do we have that ? No, just a java one. But the principles are all the same


matt.fellows
2021-11-10 13:03
SNS/Kafka/? it?s all the same.

akanksha.sharma
2021-11-10 13:04
Okay, let me take a look. Also, is there any possibility that we have katacoda for Kafka as well in near future:slightly_smiling_face:

matt.fellows
2021-11-10 13:05
i?ll add it to the list, but it?s a long list I?m afraid!

akanksha.sharma
2021-11-10 14:26
Okay, Thanks for adding :slightly_smiling_face:

esparga
2021-11-10 14:32
has joined #pact-js

esparga
2021-11-10 14:33
:wave: I?m here! What?d I miss?

martha.nolan
2021-11-10 14:35
Hi @matt.fellows, I've forked the repo and have made a change locally but am having trouble linking to my local version of pact-js to test my changes. Every time i try to link to it, the `node_modules` for `@pact-foundation` become empty. I've run `npm i` & `npm run dist` beforehand. Just wondering if I'm missing a setup step somewhere?

esparga
2021-11-10 14:37
So, i was trying to install pac-foundation to test it and I?m getting this error

esparga
2021-11-10 14:38
Error while installing binary: Checksum reject for file ?pact-1.88.77-win32.zip?

esparga
2021-11-10 14:39
has anyone get a clue how to solve this?

esparga
2021-11-10 14:46
is there a problem if im trying to use pact-1.88.77-win32.zip in a win64 machine?

tjones
2021-11-10 14:55
No, that should work. The error is saying that the checksum failed, so it's not downloading the binary correctly. Are you behind a corporate firewall or proxy? Sometimes there's a login screen that gets downloaded instead

esparga
2021-11-10 14:56
hmm..yes i am? but since the msg is saying? Finished downloading binary to c:? i assumed it download it all

tjones
2021-11-10 14:57
https://www.npmjs.com/package/@pact-foundation/pact-node ^ Have a look at `Pact Download Location` in this documentation

esparga
2021-11-10 14:57
ok thanks?gonna try to override the proxy..

tjones
2021-11-10 14:58
I suspect it has successfully downloaded something that isn't the binary zip. You can have a look at the file referenced in that error message to see

tjones
2021-11-10 14:59
(since you asked, the only windows issues currently are an issue with long paths that is hard to avoid because it's not fixed in Ruby, which is what the pact core binaries used by the current release are written in)

tjones
2021-11-10 15:00
We should improve that error message. The most common cause of the checksum failing is a corporate proxy.

esparga
2021-11-10 15:10
ok @tjones that worked like a charm?..using the ```{ "name": "some-project", ... "config": { "pact_binary_location": "/home/some-user/Downloads" }, ... }```

esparga
2021-11-10 15:11
BUT?. im getting a problem downloading version 1.88.77

esparga
2021-11-10 15:11
im able to download 1.88.79 but not the 77

esparga
2021-11-10 15:12
and every time i try to npm install ?it tries to find the version 1.88.77 in my machine?

esparga
2021-11-10 15:12
where the hell is it defined to get the 1.88.77 instead of the latest?

esparga
2021-11-10 15:14
btw. the command im using to install is : npm i --save-dev @ pact_foundation/pact@latest

esparga
2021-11-10 15:17
ok forget it!! it worked now?maybe a proxy issue

esparga
2021-11-10 15:17
thanks @tjones

tjones
2021-11-10 15:56
The version has to match the one it's expecting

tjones
2021-11-10 15:56
(so we know it passes all the tests)

tjones
2021-11-10 16:06
note that the version of `pact-foundation/pact` is different to the version of the standalone binaries

thales.areis
2021-11-10 19:33
has joined #pact-js

matt.fellows
2021-11-11 06:38
I think you need to link from the `dist` directory of Pact JS

matt.fellows
2021-11-11 06:42
You could probably get away with a relative import for the pact dependency in your `package.json` rather than `npm link` anyway

john
2021-11-11 07:56
hey all so im testing out the graphql example but i get this error: ```? ERROR: Error: Cannot find module 'source-map-support/register'```

matt.fellows
2021-11-11 08:39
We run it as part of our CI so I'd just double check what we execute and follow that

matt.fellows
2021-11-11 08:39
What are you doing when you get that error? Is there any other detail you can share?

henk.koopman
2021-11-11 08:56
has joined #pact-js

lena.lindblad
2021-11-11 09:58
has joined #pact-js

martha.nolan
2021-11-11 10:03
Thanks! Couldn't get it working with link, but got it working with relative import to `dist` folder.

matt.fellows
2021-11-11 10:33
It should be possible, but it?s been a little since I?ve tried

john
2021-11-11 10:46
i. install teh dependencies

john
2021-11-11 10:46
and i run the npm run test:consumer

matt.fellows
2021-11-11 11:41
Just ran fine for me on node 12.

matt.fellows
2021-11-11 11:41
have you tried cleaning node_modules and re running?

matt.fellows
2021-11-11 11:42
e.g. `npm ci` and then `npm run test:consumer`?

matt.fellows
2021-11-11 11:42
We run CI on 12,14 and 16

john
2021-11-11 11:49
ill giver it a go

martha.nolan
2021-11-11 15:03
Hi @matt.fellows, another question for you! I'm testing my change locally & essentially checking if the request method is `GET` & adding the query to the `RequestOptions` if it is, instead of adding it to the request body. The GraphQL query I'm passing is url encoded and I'm having trouble with the matching of this as it seems like Pact is performing some formatting of the query somewhere along the way. I can't find where this is happening (if it is at all!) in the codebase - could you point me in the right direction?

danieljak
2021-11-11 15:24
Hey :wave: I have a provider that has both message pacts (async) & both regular http pacts (GraphQL) When I setup the `MessageProviderPact` and run its verify - in addition to verifying the message pacts it also tries to verify the http pacts - which fails because I cannot configure it to run against the provider server (providerBaseUrl is not part of its types) Is there a special setup to verify a provider that has both async and sync pacts? :thinking_face:

radekkoubsky
2021-11-11 16:24
has joined #pact-js

aditya
2021-11-11 17:20
has joined #pact-js

claire
2021-11-11 17:55
has joined #pact-js

matt.fellows
2021-11-11 20:40
You actually need to give the provider different names at the moment - one for Async another for graphql

matt.fellows
2021-11-11 20:41
In the v4 pact spec you can have both in the same pact file

matt.fellows
2021-11-11 20:41
I think somebody did manage to work around it with consumer version selectors

matt.fellows
2021-11-11 20:45
Is it the matching error happening on the consumer side or provider?

matt.fellows
2021-11-11 20:47
I'll take a look today if I can

martha.nolan
2021-11-12 07:49
Consumer side, thanks!

gentritmm
2021-11-12 08:35
has joined #pact-js

matt.fellows
2021-11-12 09:44
how are you passing it in?

matt.fellows
2021-11-12 09:45
you could probably check the `pact.log` to see what it?s expecting, and also `mockService.ts` is where the interaction is registered with the underlying mock service

matt.fellows
2021-11-12 09:45
You can pass in either a full URL encoded string or a structured key/value object (where each key can have a URL encoded value)

wilson.espina
2021-11-12 09:52
has joined #pact-js

martha.nolan
2021-11-12 10:04
Thanks @matt.fellows, I'm passing the graph QL query as a URL encoded string - but the expected value adds two square brackets to the query meaning it doesn't match the actual value, so I'm wondering if Pact is performing some encoding of it's own

matt.fellows
2021-11-12 10:05
hmm

matt.fellows
2021-11-12 10:05
what does the log file say?

matt.fellows
2021-11-12 10:05
also, what does the URL encoded string look like?

martha.nolan
2021-11-12 10:16
Here is the diff - the one on the left (with extra bracket) is the 'expected value'. Other one is the actual. https://www.diffchecker.com/HFpO1jdA

matt.fellows
2021-11-12 10:18
can you please share the pact.log for it?

martha.nolan
2021-11-12 10:18
(That's what I get in the log)

matt.fellows
2021-11-12 10:19
there?s nothing else in the log?

martha.nolan
2021-11-12 10:20
Yes, sorry I sent that before you asked, one mo.

harwin1494
2021-11-12 10:54
Hi, I am facing a similar issue as explained here https://stackoverflow.com/questions/61748582/pact-dependency-stopping-tests-being-run. Has it been resolved ?

matt.fellows
2021-11-12 11:08
what version are you on?

matt.fellows
2021-11-12 11:09
have you upgraded to the latest?


matt.fellows
2021-11-12 11:09
looks unrelated to pact

harwin1494
2021-11-12 11:12
we are using the latest 9.16.5

matt.fellows
2021-11-12 11:13
hmm that still isn?t the full log, it?s missing the bit where it says ?registered interactions?

matt.fellows
2021-11-12 11:14
I?d like to see the full chain from start to finish

matt.fellows
2021-11-12 11:14
thanks

matt.fellows
2021-11-12 11:14
are you using Jest?

matt.fellows
2021-11-12 11:14
have you tried looking at your jest configs? The issue above turned out to be scanning/transforming packages it shouldn?t

harwin1494
2021-11-12 11:15
yes, ```"jest": "27.3.1", "jest-pact": "0.9.1",```

harwin1494
2021-11-12 11:15
what exactly to check in the jest configs?

matt.fellows
2021-11-12 11:15
:man-shrugging:

matt.fellows
2021-11-12 11:16
that was the issue above, so I?d just be creating a minimal example jest config that lets you run the jest test until it starts failing, and then you?ll know

harwin1494
2021-11-12 11:17
ok, will check

matt.fellows
2021-11-12 11:17
take a look at the above issue to start with, that might give you hint

martha.nolan
2021-11-12 11:19
Here's the full log :slightly_smiling_face:

harwin1494
2021-11-12 11:21
can we add something else in the jest config to resolve this, apart from upgrading the popsicle version (as explained in the above issue) ?

matt.fellows
2021-11-12 11:23
the takeaway of the above issue is it was a jest config issue, not a pact issue

matt.fellows
2021-11-12 11:24
so i?d start with a minimal jest config and see if that still causes the problem

matt.fellows
2021-11-12 11:28
I might be missing something, but this line: ```I, [2021-11-12T10:50:37.841280 #4019] INFO -- : Registered expected interaction GET /discovery?%7B%20collections(filter:%20%7Bid:%20%22234JK342LTdfr8%22%7D)%20%7B%20id%20title%20subsequentJourney%20%7B%20name%20label%20destinationUrl(platform:%20DOTCOM)%20%7D%20items(filter:%20%7Bavailable:%20%22NOW%22%20features:%20%5BMPEG_DASH%20CLEARKEY%20OUTBAND_WEBVTT%20HLS%20AES%20PLAYREADY%20WIDEVINE%20FAIRPLAY%5D%20broadcaster:%20ITV%20platform:%20DOTCOM%7D)%20%7B%20itemType%20...%20on%20TitleCollectionItem%20%7B%20titleItem%20%7B%20...%20on%20Special%20%7B%20categories%20title%20%7D%20...%20on%20Film%20%7B%20categories%20title%20%7D%20...%20on%20Episode%20%7B%20brand%20%7B%20categories%20title%20%7D%20%7D%20...%20on%20Title%20%7B%20titleType%20imageUrl%20legacyId%20brandLegacyId%20brand%20%7B%20title%20legacyId%20categories%20%7D%20synopses%20%7B%20ninety%20%7D%20broadcastDateTime%20channel%20%7B%20name%20%7D%20availableNow%20%7D%20availableNow%20%7D%20%7D%20...%20on%20BrandCollectionItem%20%7B%20brandItem%20%7B%20title%20synopses%20%7B%20ninety%20%7D%20legacyId%20categories%20latestAvailableTitle%20%7B%20imageUrl%20broadcastDateTime%20channel%20%7B%20name%20%7D%20availableNow%20%7D%20%7D%20%7D%20%7D%20%7D%20%7D``` shouldn?t that be ?Registered expected interaction GET /discovery?*query=*?.? ?

matt.fellows
2021-11-12 11:29
how are you passing in the query to your code, and the code to the framework?

matt.fellows
2021-11-12 11:29
I can see the extra `[` `]` though

martha.nolan
2021-11-12 11:52
:woman-facepalming: I think that was the issue - I assumed Pact would add `query=` so wasn't passing it myself.

martha.nolan
2021-11-12 11:59
Thanks for looking @matt.fellows - gonna double check, but now the query matching issue is no longer an issue I think we can just use a normal interaction - no need to update the `GraphQLInteraction` .

matt.fellows
2021-11-12 12:02
:laughing:

matt.fellows
2021-11-12 12:02
haha no worries

matt.fellows
2021-11-12 12:03
probably confusing because `query` is the same thing used for a query string!

matt.fellows
2021-11-12 12:03
glad it was something simple!

matt.fellows
2021-11-12 12:03
If it works, we can perhaps add another example that uses this way so others have a reference

matt.fellows
2021-11-12 12:04
it might still be nice to have a specific class/type, to make it more convient / readible. Not sure, let me know what you think anyway

harwin1494
2021-11-12 12:12
can you suggest any sample config, because I am unable to resolve the error inspite of making several changes in "`testPathIgnorePatterns`"?

akanksha.sharma
2021-11-12 13:44
Hi Matt, just to understand one thing, as in contract testing we have consumer test and producer test in the same framework but we have two different frameworks for kafka consumer and producer. Its kind of hard to understand to know the sequence of files in these. Can you please share some documents for the same?

martha.nolan
2021-11-12 14:51
Yeah, an example sounds good - not sure about a specific class. Ultimately I guess it would just be adding whatever is in `withQuery()` to the query field of the request which can be achieved using a normal interaction.

megan.twyver
2021-11-12 18:39
has joined #pact-js

danieljak
2021-11-13 10:04
Ohh ok good to know, I'll try to think of how to manage it then Thx!

mischa.molhoek
2021-11-14 09:42
has joined #pact-js

69vron
2021-11-15 01:35
has joined #pact-js

tjones
2021-11-15 05:07
Can you share the exact error you're getting? I don't think pact is likely to be the culprit, but we can take a look

matt.fellows
2021-11-15 05:22
I'd really suggest making a minimal example without your code, and then adding dependencies back in until it fails

matt.fellows
2021-11-15 05:23
Basically, you will need to bisect the problem. From our standpoint, we can't tell what you're doing or what could be wrong

james.sawle
2021-11-15 08:49
has joined #pact-js

pete.watts
2021-11-15 12:46
has joined #pact-js

akanksha.sharma
2021-11-15 14:11
Hi, Need following information: ? Does Pact support producer driven contract testing, if yes can someone please share sample examples and best practices for Producer driven contract testing. ? we have developed some tests with API Postman with hybrid framework(using postman for consumer side and node.js provider side) approach is there away integration of PACT ? so that way we can reuse same code inside PACT.

esparga
2021-11-15 15:57
Hi All

esparga
2021-11-15 15:58
i was trying to test a pact contract like its described in the article https://codersociety.com/blog/articles/contract-testing-pact

esparga
2021-11-15 15:59
and when i run the script npm run test:consumer i get this error

esparga
2021-11-15 16:00
pact-node@9.16.5: The pact mock service doesnt appear to be running

esparga
2021-11-15 16:00
and it says to check the logs created..but the log file is empty

esparga
2021-11-15 16:02
how to run this ?pack mock service??

joshua.badger
2021-11-15 17:10
has joined #pact-js

matt.fellows
2021-11-15 22:12
You sort of can, but you still need to write the consumer tests first. Can you explain specifically what you mean by that?

matt.fellows
2021-11-15 22:13
Pactflow has an option that allows provider driven contracts called bi-directional contracts: https://docs.pactflow.io/docs/workshops/bi-directional

matt.fellows
2021-11-15 22:14
> we have developed some tests with API Postman with hybrid framework(using postman for consumer side and node.js provider side) approach is there away integration of PACT ? so that way we can reuse same code inside PACT. that?s the idea of bi-directional, you can convert existisg tests into a pact file

matt.fellows
2021-11-15 22:25
Can you please set the log level to debug and share the output?

tjones
2021-11-15 23:02
The log file will be empty because the server writes the log file and isn't running. The error message > Please check the logs *above* to ensure that there are no pact service startup failure (emphasis added) means to check the logs during the test output to see if the startup failed.

esparga
2021-11-16 09:12
In fact? there are no failures at start :(

esparga
2021-11-16 09:34
when we run the ?npm run test:consumer? which calls the ?mocha consumer.spec.js? ?dont we must have the server running first? i mean..the provider?

akanksha.sharma
2021-11-16 10:54
https://levelup.gitconnected.com/api-contract-testing-with-postman-a8af93e79d5 Please go through this blog. I implemented my hybrid framework as per this where Postman is used for consumer side to create Pacts and Nodejs for provider side.

tjones
2021-11-16 14:31
No, you need to start the pact mock server.

tjones
2021-11-16 14:32
Although, looking at that it looks like your before all hook is failing

tjones
2021-11-16 14:32
According the the error message, have you confirmed that you are calling `setup()`?

tjones
2021-11-16 14:33
Have you checked that you wait for that promise before doing the rest of your tests?

tjones
2021-11-16 14:35
according to that test output, both the before all and the after all hooks are failing.

tjones
2021-11-16 14:35
if the above doesn't help, share your test code and we'll take a look

esparga
2021-11-16 16:16
Hi @tjones I'm gonna paste here my code with printscreens.. (sorry about that but my working machine doesn't have access to slack) :(

esparga
2021-11-16 16:21
It's quite simple because it's the 5-minute-getting-started-guide from http://pact.io

esparga
2021-11-16 16:25
this last file is the consumer.spec.js

matt.fellows
2021-11-16 20:39
Can you please set log level to debug and then share those logs?

matt.fellows
2021-11-16 20:39
Also, I really wouldn't copy that because it's designed to run in a browser (hence why mocha is run programmatically)


omarsaddaoui
2021-11-17 02:55
has joined #pact-js

esparga
2021-11-17 09:34
@matt.fellows i setted the log level to debug and it goes like this

matt.fellows
2021-11-17 09:44
Can you please try sharing the mock service directly: https://github.com/pact-foundation/pact-js/#debugging

matt.fellows
2021-11-17 09:44
It looks like it's not starting

matt.fellows
2021-11-17 09:47
If i were to guess the problems 1. Corporate proxy interfering with the install and corrupting the binary we run 2. Windows long path issue



esparga
2021-11-17 09:59
and both services are running ?they start succesfully

esparga
2021-11-17 09:59
./node_modules/.bin/pact-mock-service

esparga
2021-11-17 09:59
```./node_modules/.bin/pact-provider-verifier```

matt.fellows
2021-11-17 10:00
thx

matt.fellows
2021-11-17 10:00
can you run the command you see in the log output? Perhaps one of those paths doesn?t exist?

matt.fellows
2021-11-17 10:00
(or something else is at play)

matt.fellows
2021-11-17 10:00
what version are you running, also?

esparga
2021-11-17 10:01
but i noticed that the logs?mentions using the cmd.exe standalone/win32-1-70-2/bin/pact-mock-service-bat

esparga
2021-11-17 10:01
and i cannot find that file :disappointed:

esparga
2021-11-17 10:02
version:_ pact-foundation/pac 9.1.0

esparga
2021-11-17 10:02
pact-node 10.2.4

matt.fellows
2021-11-17 10:05
something not right there

matt.fellows
2021-11-17 10:06
the version of node I can see running is super old (9.0.7)

matt.fellows
2021-11-17 10:06
I?d recommend just starting with a proper github downloadable example


esparga
2021-11-17 10:38
Just one more question Matt

esparga
2021-11-17 10:39
im on a windows machine

esparga
2021-11-17 10:39
and when i try to lunch the project using "node index"

esparga
2021-11-17 10:39
it trys to lunch the pact service using cmd.exe as you can see it here

esparga
2021-11-17 10:40
and this doesnt work....because its trying to look for a folder called standalone

esparga
2021-11-17 10:41
but if i try to lunch the service in VS Code in a terminal bash it works

esparga
2021-11-17 10:41
(instead of using cmd.exe)

esparga
2021-11-17 10:41
the question is... is there a way to force it not to use cms.exe and the standalone folder?

esparga
2021-11-17 10:42
and just use whatever there is inside node_modules/.bin ?

matt.fellows
2021-11-17 11:34
> the question is... is there a way to force it not to use cms.exe and the standalone folder? cms.exe? Is that being used?

matt.fellows
2021-11-17 12:34
oh sorry, slack collapsed the messages above so it didn?t make sense

matt.fellows
2021-11-17 12:35
There should be a standalone folder in your node_modules directory somewhere, it does sound like something has gone awry though

matt.fellows
2021-11-17 12:35
I?d suggest starting with a known working github repository, not the 5 minute guide (that?s really just designed to teach the concepts in the browser and not to be downloaded)

mbyrne
2021-11-17 14:23
has joined #pact-js

martha.nolan
2021-11-17 15:49
Hey @matt.fellows! Is there a way of having a dynamic key in an interaction - so for example a response could be `programme: {}` OR `episode:{}` where the key could be one of a finite list?

matthew.drill
2021-11-18 01:08
has joined #pact-js

tjones
2021-11-18 02:21
That's an old version of pact - I'd start with one of the newer ones, as we fixed some issues to do with windows within the last couple of years.

matt.fellows
2021-11-18 02:42
I?d really like to get rid of the 5 minute guide and point people at the katacoda. I think they are much more reliable and work better

matt.fellows
2021-11-18 02:42
I know we had a few people that said the 5 minute guide is good, but I believe the katacoda experience is much better and more easily contributed to because the source is on Github

matt.fellows
2021-11-18 02:43
the downside is they aren?t embedded in our docs, like the 5 minute guide

esparga
2021-11-18 11:53
@tjones but this version https://github.com/pactflow/example-consumer is a complex one which is using pactflow? is there any other simpler? without using pactflow? just for testing

esparga
2021-11-18 11:53
@matt.fellows what is that katakoda all about?

james.halsall
2021-11-18 12:02
has joined #pact-js

matt.fellows
2021-11-18 12:28
Katacoda tutorials are referenced here, we should get them into the http://docs.pact.io website also: https://docs.pactflow.io/docs/tutorials

matt.fellows
2021-11-18 12:29
You don?t need to use Pactflow for the example consumer, the consumer tests can run without it

tausif2909
2021-11-19 05:57
While adding query Parameter to the request I get this error while running consumer tests (I am using PactV3): `Listing taxonomies` `[2021-11-19T05:36:06Z ERROR pact_js_v3] Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string` `1) Get object for listing taxonomies` `Get object for listing taxonomies:` `Error: Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string` `at PactV3.withRequest (node_modules\@pact-foundation\pact\src\v3\pact.js:90:19)` `at Context.<anonymous> (test\pact\my-test-service.js:49:5)` `at processImmediate (internal/timers.js:464:21)` Any idea What I am doing wrong

tjones
2021-11-19 05:57
How are you adding the query parameter?

tausif2909
2021-11-19 05:58
```it('Get object for listing taxonomies', () => { provider .given('Get object for listing taxonomies') .uponReceiving('Get object for listing taxonomies') .withRequest({ method: 'GET', path: '/api/taxonomies', query: { accountId: term({ generate: '4', matcher: '4' }), enabled: term({ generate: 'true', matcher: 'true' }), displayInApps: term({ generate: 'true', matcher: 'true|false' }) } }) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8' }, body: taxonomies }); return provider.executeTest(async (mockserver) => { const response = await needle('get', `http://localhost:${port}/api/taxonomies?accountId=4&enabled=true&displayInApps=true`, requestOptions); expect(response.statusCode).to.equal(200); }); });``` Here is the code

tjones
2021-11-19 05:58
where does `term` come from?

uglyog
2021-11-19 05:59
I guess that is the V2 function for a regex matcher. We should add support for automatically converting them to the V3 ones.

matt.fellows
2021-11-19 06:00
ah, looks like you?re using the V2 matchers in the v3 package. We ought to guard against that situation

tausif2909
2021-11-19 06:00
```const { term } = pact.Matchers;``` Do I need to use `term` as V3 matcher?

uglyog
2021-11-19 06:01
No, in V3 it is probably called `regex`

matt.fellows
2021-11-19 06:02
The matchers you should use are in the same package as the `PactV3` class


tausif2909
2021-11-19 06:06
```const { string, term, like, integer, fromProviderState, } = MatchersV3;``` I have added term as the matcher but getting error like `TypeError: term is not a function`

matt.fellows
2021-11-19 06:09
see Ron?s comments above

tjones
2021-11-19 06:09
`term` is not exported from V3, you'll want `regex`

tausif2909
2021-11-19 06:11
```.withRequest({ method: 'GET', path: '/api/taxonomies', query: { accountId: regex({ generate: '4', matcher: '4' }), enabled: regex({ generate: 'true', matcher: 'true' }), displayInApps: regex({ generate: 'true', matcher: 'true|false' }) } })``` I have used that too, I still get error like : ` Get object for listing taxonomies: Error: Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string at PactV3.withRequest (node_modules\@pact-foundation\pact\src\v3\pact.js:90:19) at Context.<anonymous> (test\pact\my-test-service.js:50:5) at processImmediate (internal/timers.js:464:21)`

matt.fellows
2021-11-19 06:18
The https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/src/v3/matchers.ts#L270 is different, it accepts two positional arguments not an object

tausif2909
2021-11-19 06:28
```query: { accountId: regex(integer,4), enabled: regex(boolean,true), displayInApps: regex(boolean,true), }``` You mean like this? I still get same error, I appreciate if you could share the the example

matt.fellows
2021-11-19 06:29
you can?t apply a regex to a boolean, for those you should just use the `like` matcher e.g. `like(true)`

matt.fellows
2021-11-19 06:30
the `accountId` is also not something you want to regex looking at your code, you just want it to be `like(4)` right? a number?

tjones
2021-11-19 06:37
Although, if it's in the query string, you probably want a string matcher that matches the strings you want

tjones
2021-11-19 06:37
because the query is a string

matt.fellows
2021-11-19 06:38
good pickup, it was indented so far I didn?t notice that

tausif2909
2021-11-19 06:38
```query: { accountId: like(4), enabled: like(true), displayInApps: like(true) }``` Still same error :disappointed: : `Query parameters and headers must be string values or matchers - failed to downcast any to string, failed to downcast any to string`

matt.fellows
2021-11-19 06:38
ha, yeah Tim just found that you?re doing this on a query *string*

tjones
2021-11-19 06:38
you need to match for strings.

matt.fellows
2021-11-19 06:39
my advice above was bad, sorry Tausif

matt.fellows
2021-11-19 06:39
What I said was correct, but you weren?t regexing a boolean, you were regexing a string representation of a boolean

matt.fellows
2021-11-19 06:41
something like this should work (just adjust for JS, I have typed this direct into slack): ```query: { accountId: regex(/[0-9]+/,"4"), enabled: regex(/true|false/,"true"), displayInApps: regex(/true|false/, "true"), }```

tausif2909
2021-11-19 06:44
let me try it

tausif2909
2021-11-19 06:50
That error seems gone, But now getting different error ` `1) Listing taxonomies` `Get object for listing taxonomies:` `Error: Test failed for the following reasons:` `Mock server failed with the following mismatches:` `0) The following request was expected but not received:` `Method: GET` `Path: /api/taxonomies/` `Query String: accountId=4&displayInApps=true&enabled=true` `at D:\git-directory\flex-search-app\Service\node_modules\@pact-foundation\pact\src\v3\pact.js:144:43``

tausif2909
2021-11-19 06:51
Sorry to bother you guys, This something I came across for the first time

tausif2909
2021-11-19 08:08
Any suggestion, Please? :point_up_2:

matt.fellows
2021-11-19 08:17
It looks pretty clear to me. Are you sending that request to the pact mock server?

matt.fellows
2021-11-19 08:22
In a pact test, you're mocking out the backend using Pact as the mock server. The mock gets validated so if you don't do what you said you would the test fails. Here pact is saying "you told me you were going to make this request but I never saw it"

tausif2909
2021-11-19 08:38
yes. sending it to pact mock server, I have done the same code on the other service, thats working fine, but not working here

tausif2909
2021-11-19 09:10
Finally solved the issue, Thanks alot for your time , help and support @matt.fellows @tjones @uglyog :+1:

matt.fellows
2021-11-19 09:54
What was it?

tausif2909
2021-11-19 10:12
Mismatch between port, Was causing unusual error.

tausif2909
2021-11-19 11:28
```const provider = new PactV3({ consumer: 'my-demo-app', provider: 'my-test-service', port: 18186, log: path.resolve(process.cwd(), '../', 'pact', `${providerName}.log`), dir: path.resolve(process.cwd(), '../', 'pact'), logLevel: 'DEBUG', spec: 2 });``` logging with this code is not working in PactV3, With older version it was working fine, Have we changed the logging with PactV3?

matt.fellows
2021-11-19 12:07
Which property? It currently doesn't log to a separate file, check the method signature for what you can pass in

esparga
2021-11-19 14:03
Hi Again

esparga
2021-11-19 14:03
sorry for bothering... with the same issue

esparga
2021-11-19 14:04
i was able to launch the stanalone version from the tests... (apparently) but now im getting this error

esparga
2021-11-19 14:05
its saying the WeBrick:HTTPServer is started...it has pid and port assigned

esparga
2021-11-19 14:06
but inside beforeAll its saying the mock service is not running...

tjones
2021-11-19 14:08
This is usually a race condition. Have you followed all the recommended steps in the error message?

chvram
2021-11-19 14:09
has joined #pact-js


esparga
2021-11-19 14:14
im really lost in here :disappointed:

akhandalmani.malik
2021-11-19 14:17
has joined #pact-js

esparga
2021-11-19 14:19
the host.. can it be 127.0.0.1?

esparga
2021-11-19 14:26
it seems so...i removed the host..and it defaults to 127.0.0.1

elias.frykholm
2021-11-19 15:17
has joined #pact-js

martin.carlin
2021-11-19 15:52
has joined #pact-js

paul.nardone
2021-11-19 16:12
has joined #pact-js

emily
2021-11-19 18:56
has joined #pact-js

tjones
2021-11-20 12:47
Hm. It looks like your before all hook is failing, but I'm not seeing any error messages, which is strange

tjones
2021-11-20 12:48
can you try catching the promise in the before all, and see what the failure is?

pietrucha.bartosz
2021-11-20 13:47
has joined #pact-js

armen.chuljyan
2021-11-21 01:58
has joined #pact-js

mastrobardo
2021-11-21 11:42
has joined #pact-js

fed
2021-11-22 04:20
has joined #pact-js

tausif2909
2021-11-22 05:34
```D:\git-directory\my-test-app\Service\publishPact>node publishToPactBroker.js [2021-11-22T05:28:30.307Z] INFO: pact-node@6.21.5/21900 on tshaikh: Publishing Pacts to Broker [2021-11-22T05:28:30.309Z] INFO: pact-node@6.21.5/21900 on tshaikh: Publishing pacts to broker at: https://pact.test.net/ [2021-11-22T05:28:30.314Z] INFO: pact-node@6.21.5/21900 on tshaikh: Created 'standalone\win32-1.63.0\bin\pact-broker.bat publish 'D:\git-directory\my-test-app\pact\my-test-app-f lex-taxonomyWIP-service.json' --broker-base-url 'https://pact.test.net/' --consumer-app-version '0.0.0-DEV'' process with PID: 9040 [2021-11-22T05:28:45.238Z] WARN: pact-node@6.21.5/21900 on tshaikh: Pact exited with code 1. [2021-11-22T05:28:45.238Z] ERROR: pact-node@6.21.5/21900 on tshaikh: Could not publish pact: Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service /node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 1 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service /node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 2 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service /node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 3 of 3 Failed to publish my-test-app/my-test-service pact due to error: OpenSSL::SSL::SSLError - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certifica te verify failed One or more pacts failed to be published Publishing my-test-app/my-test-service pact to pact broker at https://pact.test.net/ Something went wrong while pushing pact for taxonomy Error: Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificat e verify failed D:/git-directory/my-test-app/Service/node_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_bro ker/client/pacts.rb:35:in `get', attempt 1 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service/nod e_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 2 of 3 Error making request - OpenSSL::SSL::SSLError SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed D:/git-directory/my-test-app/Service/nod e_modules/@pact-foundation/pact-node/standalone/win32-1.63.0/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.17.0/lib/pact_broker/client/pacts.rb:35:in `get', attempt 3 of 3 Failed to publish my-test-app/my-test-service pact due to error: OpenSSL::SSL::SSLError - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate v erify failed One or more pacts failed to be published Publishing my-test-app/my-test-service pact to pact broker at https://pact.test.net// at ChildProcess.<anonymous> (D:\git-directory\my-test-app\Service\node_modules\@pact-foundation\pact-node\src\publisher.js:65:40) at Object.onceWrapper (events.js:482:26) at ChildProcess.emit (events.js:387:35) at maybeClose (internal/child_process.js:1055:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)``` Publishing pact causing SSL error, I am on "@pact-foundation/pact": "10.0.0-beta.53", How do I resolve the error?

tjones
2021-11-22 05:51
Is your broker hosted with custom certs?

tjones
2021-11-22 05:54
Please try the latest version (10.0.0-beta.54)

tausif2909
2021-11-22 06:01
ok, let me try that

matt.fellows
2021-11-22 06:17
is it a self-signed certificate and is it in the certificate store? Tim is probably right, in that the latest version should resolve it if that?s the case

tausif2909
2021-11-22 06:23
No luck, Same error :disappointed:

tausif2909
2021-11-22 06:27
no, same is working fine in the jenkins pipeline

tausif2909
2021-11-22 06:28
This is i am trying in my local

tjones
2021-11-22 06:28
If it

tjones
2021-11-22 06:28
If it's broken locally, I would guess it's a certificate issue. Are you able to load your broker from a curl command?

matt.fellows
2021-11-22 06:32
`curl https://pact.test.net` <- if you can please post the results of that (I?m pretty sure powershell has an alias for that)

matt.fellows
2021-11-22 06:32
but also, real curl would be better

tausif2909
2021-11-22 06:52
let me try with the curl command

tausif2909
2021-11-22 07:32
```>curl https://pact.test.net/ {"_links":{"self":{"href":"https://pact.ooflex.net","title":"Index","templated":false},"pb:publish-pact":{"href":"https://pact.test.net/pacts/provider/{provider}/consumer/{consumer}/ve rsion/{consumerApplicationVersion}","title":"Publish a pact","templated":true},"pb:publish-contracts":{"href":"https://pact.test.net/contracts/publish","title":"Publish contracts","tem plated":false},"pb:latest-pact-versions":{"href":"https://pact.test.net/pacts/latest","title":"Latest pact versions","templated":false},"pb:tagged-pact-versions":{"href":"https://pact. http://ooflex.net/pacts/provider/{provider}/consumer/{consumer}/tag/{tag}%22,%22title%22:%22All versions of a pact for a given consumer, provider and consumer version tag","templated":false},"pb:pactic ipants":{"href":"https://pact.test.net/pacticipants","title":"Pacticipants","templated":false},"pb:pacticipant":{"href":"https://pact.test.net/pacticipants/{pacticipant}","title":"Fe tch pacticipant by name","templated":true},"pb:latest-provider-pacts":{"href":"https://pact.test.net/pacts/provider/{provider}/latest","title":"Latest pacts by provider","templated":tr ue},"pb:latest-provider-pacts-with-tag":{"href":"https://pact.test.net/pacts/provider/{provider}/latest/{tag}","title":"Latest pacts for provider with the specified tag","templated":tr ue},"pb:provider-pacts-with-tag":{"href":"https://pact.test.net/pacts/provider/{provider}/tag/{tag}","title":"All pact versions for the provider with the specified consumer version tag ","templated":true},"pb:provider-pacts":{"href":"https://pact.test.net/pacts/provider/{provider}","title":"All pact versions for the specified provider","templated":true},"pb:latest-ve rsion":{"href":"https://pact.test.net/pacticipants/{pacticipant}/latest-version","title":"Latest pacticipant version","templated":true},"pb:latest-tagged-version":{"href":"https://pact .http://ooflex.net/pacticipants/{pacticipant}/latest-version/{tag}%22,%22title%22:%22Latest pacticipant version with the specified tag","templated":true},"pb:webhooks":{"href":"https://pact.test.net/ webhooks","title":"Webhooks","templated":false},"pb:webhook":{"href":"https://pact.test.net/webhooks/{uuid}","title":"Webhook","templated":true},"pb:integrations":{"href":"https://pact .http://ooflex.net/integrations%22,%22title%22:%22Integrations%22,%22templated%22:false},"pb:pacticipant-version-tag":{"href":"https://pact.test.net/pacticipants/{pacticipant}/versions/{version}/tags/{tag} ","title":"Get, create or delete a tag for a pacticipant version","templated":true},"pb:pacticipant-version":{"href":"https://pact.test.net/pacticipants/{pacticipant}/versions/{version }","title":"Get, create or delete a pacticipant version","templated":true},"pb:metrics":{"href":"https://pact.test.net/metrics","title":"Get Pact Broker metrics"},"pb:can-i-deploy-pact icipant-version-to-tag":{"href":"https://pact.test.net/can-i-deploy?pacticipant={pacticipant}&version={version}&to={tag}","title":"Determine if an application can be safely deployed to an environment identified by the given tag","templated":true},"pb:provider-pacts-for-verification":{"href":"https://pact.test.net/pacts/provider/{provider}/for-verification","title":" Pact versions to be verified for the specified provider","templated":true},"beta:provider-pacts-for-verification":{"name":"beta","href":"https://pact.test.net/pacts/provider/{provider} /for-verification","title":"DEPRECATED - please use pb:provider-pacts-for-verification","templated":true},"curies":[{"name":"pb","href":"https://pact.test.net/doc/{rel}?context=index", "templated":true},{"name":"beta","href":"https://pact.test.net/doc/{rel}?context=index","templated":true}]}}``` Thats the result

matt.fellows
2021-11-22 07:38
Is CI Linux or windows?

matt.fellows
2021-11-22 07:38
Can you please check you're on the latest and if it still doesn't work please set log level to trace and share

tausif2909
2021-11-22 07:47
ok sure.

tausif2909
2021-11-22 07:47
I am on windows

tumunshaily
2021-11-22 07:54
has joined #pact-js

matt.fellows
2021-11-22 08:25
What about CI?

tausif2909
2021-11-22 08:43
its linux

esparga
2021-11-22 09:21
Hi @tjones i was able to figure it out!! it was a proxy problem... im behind a corporate proxy...and somehow i dont know why... when the tests are running it fails saying the service is not up...which it is...as we can see it in the logs..

esparga
2021-11-22 09:21
if i set up correctly the proxy...it works ....

esparga
2021-11-22 09:21
during the tests...it makes some external calls?

tjones
2021-11-22 09:22
Ah, great! No, it shouldn?t make external calls during the tests. But it does need to contact the broker that you have configured (where the ssl error was)

yunfeng.wang
2021-11-22 09:25
has joined #pact-js

matt.fellows
2021-11-22 09:48
the proxy config can still interfere with local calls - i.e. calls from your machine?to your machine

matt.fellows
2021-11-22 09:48
that?s what proxies do

matt.fellows
2021-11-22 09:48
presumably, you fixed it by setting up `http_proxy` or `no_proxy` environment variables?

matt.fellows
2021-11-22 09:49
This could definitely be checked in our boot routine. People talk about `null` being the Billion dollar mistake. If that?s true, then proxies and corporate firewalls are the trillion dollar mistake

esparga
2021-11-22 10:09
Hi @matt.fellows yes..i had to set up the no_proxy and http_proxy env vars

esparga
2021-11-22 10:10
thanks everyone to all your availability!

matt.fellows
2021-11-22 11:10
You?re welcome. It?s such a nefarious bug to diagnose - thanks for your patience

matt.fellows
2021-11-22 11:27
Added an item on corporate proxies to our troubleshooting section: https://github.com/pact-foundation/pact-js#corporate-proxies--firewalls

christos.litsas
2021-11-23 13:05
has joined #pact-js

walter.psjr
2021-11-23 17:39
has joined #pact-js

john
2021-11-24 05:55
so just a quick question, i had a debate with my colleague over pact and he was saying that I need to render a react component to create the contract test? I was under the impressiont hat react doesnt matter and we should use the api that the react component uses to generate the consumer test?

matt.fellows
2021-11-24 05:55
no you don?t need to render the react component - that?s definitely not recommended

john
2021-11-24 05:55
yeah thats what i said

matt.fellows
2021-11-24 05:55
you?re impression is correct

tjones
2021-11-24 05:56
We wholeheartedly agree with you :slightly_smiling_face:

matt.fellows
2021-11-24 05:56
Old react code, so apologies, but this example is a react code base and we test the `API` class, not the React component. i.e. the scope of the test is the API client used by this bit of code: https://github.com/pactflow/example-consumer/blob/master/src/ProductPage.js#L24-L28


john
2021-11-24 05:57
yeah so basically import the api that the react class uses intot he consumer test right?

matt.fellows
2021-11-24 05:57
yeah.

matt.fellows
2021-11-24 05:57
if your react code is directly calling APIs, that should call for a refactor anyway IMO

john
2021-11-24 05:59
so another thing, we talked about was that we have a graph ql query. Is it best practise to base the consumer test on just the returned fields that the react component is actually using?


tjones
2021-11-24 05:59
That's right

matt.fellows
2021-11-24 05:59
yes. But isn?t that what graphql is for - only fetching the things you need? (so both the query and the pact tests should only cover what you need)

tjones
2021-11-24 06:00
Pact isn't a full description of the API, it's the parts of the API that your consumer needs (which may be only partial responses)

john
2021-11-24 06:02
so basically create a consumer pact for only the stuff that is being used by the react component for instance

john
2021-11-24 06:03
awesome thanks for those responses guys just my colleague and I are fmbling through this stuff for the first time

tjones
2021-11-24 06:05
You're welcome!

harwin1494
2021-11-24 06:26
An add-on question to this, is it really required for us to call an API in the consumer test to create an interaction consisting of expected requests and responses?

matt.fellows
2021-11-24 06:29
yes.

matt.fellows
2021-11-24 06:30
Why do you think you shouldn?t?

matt.fellows
2021-11-24 06:30
(asking to fully understand where you?re coming from)

harwin1494
2021-11-24 06:37
I am writing a test for '/getUserprofile' endpoint which requires a cookie as a header which is to be fetched from '/authenticate' endpoint (as there is no other identifier to get the profile for a particular user), but the actual '/getUserprofile' api doesnt include any cookie in the header (just 'content-type' is present in the headers), so I am trying to avoid calling it altogether.

matt.fellows
2021-11-24 06:42
in a pact test, you should stub out external dependencies. If I understand correctly, your `/getUserprofile` endpoint calls `/authenticate` to get a cookie, and then uses this somehow? IF so, you should stub out calls to `/authenticate` in this pact test, and then write a separate pact tests for `/authenticate`

john
2021-11-24 06:49
Hey one last question I forgot to ask earlier. Say for example if i have an api but it is wrapped in an aws lambda event do i base the contract on the wrapped aws lambda or the api? Sorry if that makes no sense

matt.fellows
2021-11-24 06:52
is it an HTTP or async lambda? i.e. behind AWS gateway or a queue like SNS/SQS/Kinesis?

john
2021-11-24 06:55
i think we might have a mixture of both depending on the service repo etc



harwin1494
2021-11-24 07:33
No, these endpoints are called separately. After calling the '/authenticate', the cookie generated gets sent in the headers of the '/getUserprofile' endpoint (GET call). This has been achieved in postman via request chaining.

harwin1494
2021-11-24 07:54
It was related to the jest config only as suggested by Matt, thanks a lot.

steveforwork2
2021-11-24 08:47
has joined #pact-js

matt.fellows
2021-11-24 08:52
Which config item Garwin? That would be helpful to know and we can add to our troubleshooting guide if it makes sense

matt.fellows
2021-11-24 08:54
I see. In pact tests, each interaction should be tested in isolation

matt.fellows
2021-11-24 08:55
Trying to replicate a postman series of tests in pact is not a great idea, because it's a functional testing tool

matt.fellows
2021-11-24 08:56
A consumer pact test can use a fake cookie because it's a unit test. So you don't need to chain


matt.fellows
2021-11-24 09:02
Isolation is the key.

esparga
2021-11-24 09:31
Hi Guys! @matt.fellows @tjones im making the provider part..and i've some doubts about the mandatory parameters

esparga
2021-11-24 09:31
whats the difference between pactBrokerUrl and providerBaseUrl?

tjones
2021-11-24 09:36
One is for the pact broker (which gives the verifier the contract), and the other is for your provider (the thing you are testing)

esparga
2021-11-24 10:32
the pactBrokerUrl i understand....but...when we are verifying the pact for the first time (from the provider)...and assuming the pact was published with the consumer side... which 'providerBaseUrl' should we use...? just the name of the provider?

esparga
2021-11-24 10:32
the 'url' part is somehow confusing

akke.luukkonen
2021-11-24 10:38
What URL is your provider running at & where do the packets from the Consumer need to be sent? That is the Provider base URL, e.g. http://localhost:7071/api

matt.fellows
2021-11-24 10:54
Provider verification takes a pact from the broker (`pactBrokerUrl` and related parameters) and then replays the tests against your locally running provider (`providerBaseUrl`)

matt.fellows
2021-11-24 10:54
so you need to have the provider running locally, and point your verification test at the provider

matt.fellows
2021-11-24 10:55
> the ?url? part is somehow confusing what?s confusing about the url bit?

fredrik.ostling
2021-11-24 11:56
has joined #pact-js

esparga
2021-11-24 12:20
ok understood now... :wink: "and then replays the tests against your locally running provider (`providerBaseUrl`)"

esparga
2021-11-24 12:20
its the url to the provider test which is localhost

esparga
2021-11-24 12:20
got it! thanks

esparga
2021-11-24 13:16
One test fails with this msg

esparga
2021-11-24 13:16
But the provider is like this

esparga
2021-11-24 13:17
Is there a way to force it to not use the charset-utf-8?

esparga
2021-11-24 13:18
For some reason even if I just use ?application/json? as the content-type it always assume that is ?application/json; charset-utf-8;?

matt.fellows
2021-11-24 13:36
Are you using `res.json(...)` later? That might override the header

jorge.nunez
2021-11-24 14:28
has joined #pact-js

leonardo.viana
2021-11-24 15:51
Hi all. Does pactjs v3 beta support nodejs 16? We are considering moving to that version, but I'd like to get confirmation on support first.

asradhakrishnan
2021-11-24 17:20
has joined #pact-js

asradhakrishnan
2021-11-24 17:22
hi All, Im writing contract tests on consumer side. At the end of my test when the pact file is generated in the /pacts folder, I see that the response body is encoded in base-64 format. Can someone help me in decoding that before the response body is written to the pact file?

mike.geeves064
2021-11-24 19:21
The body should be in relation to the Pact test and behaviour you have written, it has what you expect to receive. Can you provide some more details about the actual test performed that generated the Pact file. Also, what are you then wanting to achieve from it, by decoding?

asradhakrishnan
2021-11-24 19:22
@mike.geeves064 thanks for your reply. So, Ive specified response as such ```return { status: 200, headers: { "Content-Type": "application/json" }, body: expectedBody };```

asradhakrishnan
2021-11-24 19:22
i tried adding the charset-utf-8 in the the content Type, but no luck

mike.geeves064
2021-11-24 19:23
And is expectedBody just some json?

mike.geeves064
2021-11-24 19:25
As in, if you look at the example: https://github.com/pact-foundation/pact-js#consumer-side-testing you have the EXPECTED_BODY relating to the ``` willRespondWith: { status: 200, headers: { "Content-Type": "application/json" }, body: EXPECTED_BODY, },```

asradhakrishnan
2021-11-24 19:26
expected body is of type, as follows: ```event: data id: event-1 data: <JSON>```

mike.geeves064
2021-11-24 19:27
Hang on so this is a consumer test? Might need a bit more context, which examples/tutorial etc are you following?

asradhakrishnan
2021-11-24 19:28
yes its a consumer test. So im writing these tests for my company where we expect SSE type response from the provider.

asradhakrishnan
2021-11-24 19:29
not following anything specific tutorial for this one

mike.geeves064
2021-11-24 19:35
Try having a look through one of the workshops/tutorials e.g. https://github.com/pact-foundation/pact-workshop-js/tree/step1#step-1---simple-consumer-calling-provider I think you might have the test setup and consumer not quite right...

asradhakrishnan
2021-11-24 19:50
this is what my provider object looks like ```return new PactV3({ consumer: <consumer_name>, provider: <provider_name>, log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 });```

mike.geeves064
2021-11-24 20:10
Ok, but what does your actual test look like, is it like in the example, with the will respond with etc

asradhakrishnan
2021-11-24 21:31
so the `willRespond(expectedResponse)` where the expectedResponse is in form of a string

matt.fellows
2021-11-24 21:44
can you please share the pact file (specifically the interaction with base64 encoding) and the full test example?

matt.fellows
2021-11-24 21:44
it might be base64 encoded if the request/response content type is detected as binary

asradhakrishnan
2021-11-24 21:51
this is what the response in the generated pact file looks like ```"response": { "body": "<encoded response>", "headers": { "Content-Type": "application/json" }, "status": 200 }```

asradhakrishnan
2021-11-24 21:51
sorry cant divulge much in the response body since its a sensitive info in my company. :slightly_smiling_face:

matt.fellows
2021-11-24 21:58
my suggestion is to create an example that doesn?t include your company info that reproduces the problem

matt.fellows
2021-11-24 21:58
see howtorepro for what this means


asradhakrishnan
2021-11-24 22:08
```function createRequest(...modules) { return { method: "GET", path: <endpoint>, query: {}, headers: {Accept: "text/event-stream"} }; } function createProvider() { return new PactV3({ consumer: "consumer_name", provider: "provide_name", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: 'DEBUG', dir: path.resolve(process.cwd(), "pacts"), port: 8081 }); } function createResponse(expectedBody) { return { status: 200, headers: { "Content-Type": "application/json" }, body: expectedBody } }```

asradhakrishnan
2021-11-24 22:10
this is what my test looks like ```it('Runs the test', () => { const param = stringParam; provider .given(`item exists`) .uponReceiving("request") .withRequest(createRequest(param)) .willRespondWith(createResponse(stringParam));```

asradhakrishnan
2021-11-24 22:13
@matt.fellows ^^

matt.fellows
2021-11-24 22:17
so it?s possible that the request body will be base64 encoded. but it would/should be decoded on the provider verification side - is it not?

matt.fellows
2021-11-24 22:17
also that?s not a reproducible example. I should be able to run the code locally to be able to reproduce it

tjones
2021-11-24 22:27
Unfortunately, not at this time (this is one of the blockers for release)

edouard.lopez
2021-11-25 11:01
has joined #pact-js

esparga
2021-11-25 11:23
Hi Matt, yes i'm using res.json later on to send the response... which are the options here?

matt.fellows
2021-11-25 13:39
Probably best to read up on the express docs.

matt.fellows
2021-11-25 13:39
But if the provider always responds with the charset, update the consumer test

maxkitzing
2021-11-25 17:49
has joined #pact-js

cristian.carrillo
2021-11-26 00:06
has joined #pact-js

john
2021-11-26 01:47
I tried to do the npm ci and rerun but i get the same error

matt.fellows
2021-11-26 02:33
can you please provide the exact steps to reproduce the problem?

matt.fellows
2021-11-26 02:34
Just ran the examples locally myself and they work just fine

christoph.oswald
2021-11-26 09:53
has joined #pact-js

gjourdanweil
2021-11-26 14:39
has joined #pact-js

sean.pike
2021-11-26 14:48
has joined #pact-js

tausif2909
2021-11-29 05:02
```[4/4] Building fresh packages... info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. error /opt/flex-service/node_modules/ffi-napi: Command failed. Exit code: 1 Command: node-gyp-build Arguments: Directory: /opt/flex-service/node_modules/ffi-napi Output: events.js:377 throw er; // Unhandled 'error' event ^ Error: spawn node-gyp ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:82:21) Emitted 'error' event on ChildProcess instance at: at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:82:21) { errno: -2, code: 'ENOENT', syscall: 'spawn node-gyp', path: 'node-gyp', spawnargs: [ 'rebuild' ]``` After upgrading pact consumer test to V3 ("@pact-foundation/pact": "10.0.0-beta.51") , I get above error in jenkins pipeline while installing dependencies. Same was working fine in my local (Windows machine), But our jenkins pipeline is on linux, I was able to reproduce the issue on a local system with linux OS.

tausif2909
2021-11-29 05:40
Any idea on this :point_up_2:? @matt.fellows @tjones

tjones
2021-11-29 06:34
Hi Tausif! You don't need to tag us, we get notified when questions are posted in this channel already, and will answer when we can. Can you open an issue here please? https://github.com/pact-foundation/pact-js/issues/new/choose The issue template asks all the standard debugging questions, like node versions, etc. With the beta, we're currently having some issues with node 14+, preventing builds on some systems. However, that looks like a yarn error before the build failure would happen, rather than a pact error. It looks like it's unable to spawn node-gyp. I know that yarn has broken a number of expectations about the way the install process works, so I would start there. Are you using yarn 2? I would try: Updating to the latest supported version of node within that major release. While you're at it, try updating the beta version too (I don't think it will fix this error, but "try the latest version" is the first step in our debugging instructions).

tausif2909
2021-11-29 06:41
No, I am not using yarn2, with non beta pact version its working fine, whenever I upgrade it to the latest or any of beta version i start getting this error in the build. I have implemented same thing on another service and thats working well, I dont know why its crashing on this particular service

tausif2909
2021-11-29 06:42
and apologize for tagging.. usually I get the reply within a few mins. I thought you might have missed it, sorry once again for that

michael.bannister
2021-11-29 07:43
has joined #pact-js

harwin1494
2021-11-29 11:20
I got your point here and I can use a fake cookie, but the problem is, that the actual endpoint (i.e. in the source code) does not contain the cookie in its header, its just that I got to know about it through POSTMAN. So, I am unable to write a PACT test for it. I just need to know if I can add this header anyhow in the interaction (json) file , and I think that can be achieved if I dont call the actual endpoint in my test?

matt.fellows
2021-11-29 11:30
what does your actual provider need?

matt.fellows
2021-11-29 11:32
You mentioned above it needs a cookie. Does it not need a cookie?

matt.fellows
2021-11-29 11:33
It?s simple. Your consumer Pact tests should be a *unit test* of your API client code, where your API client is the piece of code that talks to the provider

matt.fellows
2021-11-29 11:33
Whatever your consumer code sends and expects to receive of the provider should go in the test

matt.fellows
2021-11-29 11:33
nothing more

matt.fellows
2021-11-29 11:34
If it needs to make a separate call to get credentials, you should mock or stub that out in your test as appropriate, to focus on the single interaction

matt.fellows
2021-11-29 11:34
if that piece of code needs to send a cookie to authenticate to the provider, it must be in the pact test. If it doesn?t, and that?s just something else another part of code does, it shouldn?t be in the pact test.


leonardo.viana
2021-11-29 18:24
Is there a timeline for when nodejs 16 support is planned on being added for pactjs v3 beta?

rjadams96
2021-11-29 18:47
has joined #pact-js

tjones
2021-11-29 22:23
No worries, it's no problem :slightly_smiling_face:

tjones
2021-11-29 22:24
Apologies that the beta isn't especially stable. I'm keen to confirm that this one isn't us though - if you could open an issue with all the details, that would be helpful

tjones
2021-11-29 22:43
Specifically, I'm keen to know which exact node version you are using

pavithz
2021-11-29 23:51
has joined #pact-js

mfellows_20211130
2021-11-30 06:57
has joined #pact-js

john
2021-11-30 07:31
when i run the consumer test, it should dump a pact into the pact folder right?

john
2021-11-30 07:32
for some reason when im running the consumer test nothing gets generated

tjones
2021-11-30 07:32
Yes, although we usually say "save" :wink:


tjones
2021-11-30 07:33
Can you share your test code / log output?

john
2021-11-30 07:33
save does soundd a tad more decent

john
2021-11-30 07:34
the log generates this

john
2021-11-30 07:34
```I, [2021-11-30T17:33:43.487014 #42518] INFO -- : Verifying - interactions matched I, [2021-11-30T17:33:43.490941 #42518] INFO -- : Cleared interactions```

john
2021-11-30 07:35
the test looks like this

john
2021-11-30 07:35
```describe('GraphQL example', () => { // Explicit longer timeout to account for Pact server needing to spin up // Was throwing timeout errors after default 5 second timeout jest.setTimeout(30000) const provider = new Pact({ log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), consumer: 'GraphQLConsumer', provider: 'GraphQLProvider' }) beforeEach(() => provider.setup()) afterEach(() => provider.finalize()) describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `query ProfileQuery { default } ` ) .withOperation('ProfilePageQuery') .withRequest({ path: 'http://localhost:9090/api/v2/graphql', method: 'POST' }) .withVariables({}) .willRespondWith({ status: 200, body: { id:1, username: 'default' } }) return provider.addInteraction(graphqlQuery) }) }) it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {}) console.log(account); return expect(account).to.deep.contain({ username: 'default' }) }) afterEach(() => provider.verify()) })```

matt.fellows
2021-11-30 07:38
The setup should be a before all, and finalise after all. You only need to call them once for the lifecycle of the whole suite

john
2021-11-30 07:41
do i need this as afterAll too? afterAll(() => provider.verify())

john
2021-11-30 07:43
it still doesnt seem to generate a pact

matt.fellows
2021-11-30 07:52
No, verification should happen per test

matt.fellows
2021-11-30 07:52
Please share the full log file. Also double check you haven't got other test running that may interfere with it?

john
2021-11-30 07:54
where is the full log file aved to

tjones
2021-11-30 08:09
If you're using Jest, you can use `jest-pact` which does all this setup for you

tjones
2021-11-30 08:10
```afterEach(() => provider.finalize())``` This is probably not right - you want to only do this once.

tjones
2021-11-30 08:10
Oh, Matt already said that.

tjones
2021-11-30 08:10
by full log, we mean the full test output

john
2021-11-30 08:14
```[2021-11-30 08:12:06.015 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Creating Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000} PASS tests/contract/profile-page-consumer.test.ts GraphQL example ? returns the correct response (34 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 2.79 s, estimated 3 s Ran all test suites matching /.\/tests\/contract\/profile-page-consumer.test.ts/i. [2021-11-30 08:12:06.577 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" [2021-11-30 08:12:06.615 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Pact File Written [2021-11-30 08:12:06.615 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Removing Pact process with PID: 54140 [2021-11-30 08:12:06.617 +0000] INFO (53784 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Deleting Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000}```

matt.fellows
2021-11-30 08:15
Thanks. What does that .log file say?

john
2021-11-30 08:16
```I, [2021-11-30T18:12:06.607544 #54140] INFO -- : Verifying - interactions matched I, [2021-11-30T18:12:06.611469 #54140] INFO -- : Cleared interactions```

matt.fellows
2021-11-30 08:17
That's the full log? I... Don't think that's right

john
2021-11-30 08:18
thats all that is ther

john
2021-11-30 08:18
for some context, i am running a mock server thats only job is to return a test payload

matt.fellows
2021-11-30 08:18
Please set the log level to debug and share that terminal output. Something is out of whack

john
2021-11-30 08:19
where do i do that?

john
2021-11-30 08:19
in the package.json file?


john
2021-11-30 08:24
so i set the loglevel to debug

john
2021-11-30 08:24
i added this to the new Pact object

john
2021-11-30 08:24
logLevel: 'debug'

john
2021-11-30 08:25
but the log is the same

matt.fellows
2021-11-30 08:25
The terminal output should be different

john
2021-11-30 08:25
```[2021-11-30 08:25:32.086 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2021-11-30 08:25:32.087 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick::HTTPServer#start: pid=57771 port=3000```

john
2021-11-30 08:26
we brick doesnt sound good

abubics
2021-11-30 08:26
(It's a new R&M spin-off: web-Rick)

matt.fellows
2021-11-30 08:27
That's the entire terminal output?

john
2021-11-30 08:27
```[2021-11-30 08:25:32.153 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2021-11-30 08:25:32.086 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2021-11-30 08:25:32.087 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick::HTTPServer#start: pid=57771 port=3000 [2021-11-30 08:25:32.102 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Pact File Written [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Removing Pact process with PID: 57771 [2021-11-30 08:25:32.145 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Deleting Pact Server with options: ```

matt.fellows
2021-11-30 08:28
They're all info level messages, so something is not right. Are you sure the test you're running is the right one?

john
2021-11-30 08:30
```yarn test:consumer [2021-11-30 08:25:31.558 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Creating Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000} [2021-11-30 08:25:31.571 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Starting pact binary '/Users/Development/Work/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.80/pact/bin/pact-mock-service', with arguments [service --consumer GraphQLConsumer --pact_dir /Users/Development/Work/pacts --host 127.0.0.1 --log /Users/Development/Work/logs/mockserver-integration.log --pact-file-write-mode overwrite --port 3000 --provider GraphQLProvider --pact_specification_version 2] [2021-11-30 08:25:31.575 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Created '/Users/Development/Work/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.80/pact/bin/pact-mock-service' process with PID: 57771 PASS tests/contract/profile-page-consumer.test.ts GraphQL example ? returns the correct response (37 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 2.728 s, estimated 4 s Ran all test suites matching /.\/tests\/contract\/profile-page-consumer.test.ts/i. [2021-11-30 08:25:32.153 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2021-11-30 08:25:32.086 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2021-11-30 08:25:32.087 +0000] DEBUG (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: INFO WEBrick::HTTPServer#start: pid=57771 port=3000 [2021-11-30 08:25:32.102 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact@9.17.0: Pact File Written [2021-11-30 08:25:32.143 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Removing Pact process with PID: 57771 [2021-11-30 08:25:32.145 +0000] INFO (57759 on http://192-168-1-3.tpgi.com.au): pact-node@10.15.0: Deleting Pact Server with options: {"consumer":"GraphQLConsumer","cors":false,"dir":"/Users/Development/Work/pacts","host":"127.0.0.1","log":"/Users/Development/Work/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":3000,"provider":"GraphQLProvider","spec":2,"ssl":false,"timeout":30000}```

john
2021-11-30 08:30
thats the full output

john
2021-11-30 08:31
one question so the that pact object

john
2021-11-30 08:31
i have the port on 3000 but this mock server im running is on 9090

john
2021-11-30 08:32
so to be clear i had to pysically run the mock server in another terminal window

john
2021-11-30 08:32
while this test runs

matt.fellows
2021-11-30 08:35
Right, that information would have been useful

matt.fellows
2021-11-30 08:35
Why are you doing that?

tjones
2021-11-30 08:35
``` .withRequest({ path: 'http://localhost:9090/api/v2/graphql',``` This part is suspicious. I think it should just be the path, not the full URL

john
2021-11-30 08:36
so thats not the right way to do it presumably then lol

tjones
2021-11-30 08:36
No. The test starts the mock server for you

matt.fellows
2021-11-30 08:37
Are you following an example somewhere?

tjones
2021-11-30 08:37
If you're hitting the other mock server, it will be writing the pact ...somewhere else, wherever it's configured to

tjones
2021-11-30 08:37
but as Matt said... why are you running it separately?

tjones
2021-11-30 08:38
I have to head out, back later

matt.fellows
2021-11-30 08:38
I'd Love to know how you got to running your own mock server, and if we need to fix docs etc to clarify

john
2021-11-30 08:38
the reason was the way the developers wrote the graphql it wasnt easy just to import the client

john
2021-11-30 08:39
so the developers refactored their code to allow me to easly query the graphql

john
2021-11-30 08:39
but the when they handed it over they said the only way they could get it working was by starting the mock server they have

john
2021-11-30 08:39
and none oof us really know anything about pact

john
2021-11-30 08:40
so we query the graphql witht his function: ``` it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {}) return expect(account).to.deep.contain({ username: 'default' }) })```

matt.fellows
2021-11-30 08:40
And they've handed this over to you, I'm guessing maybe you're a tester/QA?

john
2021-11-30 08:40
well im certainly not a dev

john
2021-11-30 08:40
thats for sure

matt.fellows
2021-11-30 08:42
So separate problem, but I'd also be flagging this isn't ideal. Pact is really designed to be authored as a unit test

john
2021-11-30 08:43
so if i get rid of the mock server and stop it

john
2021-11-30 08:43
and then run it again i get this

john
2021-11-30 08:43
```with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "3000" console.error Error: Error: connect ECONNREFUSED 127.0.0.1:9090```

john
2021-11-30 08:44
ah to be honest Matt they want us to learn to be devs i guess

matt.fellows
2021-11-30 08:45
Your API client needs to point at the port 3000 now, not 9090

matt.fellows
2021-11-30 08:45
Or change the mock service to start on 9090

john
2021-11-30 08:47
``` pact@9.17.0: Setting up Pact with Consumer "GraphQLConsumer" and Provider "GraphQLProvider" using mock service on Port: "9090" console.error Error: Error: Response for preflight has invalid HTTP status code 500```

john
2021-11-30 08:50
i can talk with the dev that helped me out earlier. I have a bit more informationnow

matt.fellows
2021-11-30 08:54
Might just need cors enabled

matt.fellows
2021-11-30 08:54
Can help tomorrow, kids dinner

john
2021-11-30 08:54
ah sure thanks for helping me out, is appreciated

tausif2909
2021-11-30 09:29
Well, I have pinned the version to `10.0.0-beta.20` on that build got passed, `ffi-napi` 's latest version was causing the issue I guess

tausif2909
2021-11-30 09:32
BTW, Do we have any timeline or expected date to release `PACT-V3` , Sometimes my PR reviewers hesitate to approve my PR when I use the beta version. my main purpose to use beta version is I require to use `providerState` thats not available in the official release.

tausif2909
2021-11-30 09:34
If possible please release `providerState` in stable version :slightly_smiling_face:

mfellows_20211130v2
2021-11-30 10:32
has joined #pact-js

tjones
2021-11-30 10:37
Put `cors: true` in your options in your `new Pact({...})` call

tjones
2021-11-30 10:38
> Response for preflight has invalid HTTP status code 500 ^ This means that the preflight (cors) request got a 500 response, which is what the mock does when you don't match the expectations it has. `cors: true` tells it to expect the cors preflight requests.

tjones
2021-11-30 10:38
Yes, this is a priority for the project

john
2021-11-30 10:45
ah yeah, i did do that earlier on

john
2021-11-30 10:45
im getting some weird application error now and a 500 status response so ill speak witht he dev tomorrow

john
2021-11-30 10:45
thanks Timothy

matt.fellows
2021-11-30 10:46
if you manually setup the mock service before and your code was passing, whatever flags you have the CLI mock server you need to replicate to your pact test

john
2021-11-30 10:48
yes ill need to delve into that

mfellows_20211130v3
2021-11-30 10:57
has joined #pact-js

mfellows_20211130v4
2021-11-30 11:16
has joined #pact-js

agittcelik
2021-11-30 18:35
has joined #pact-js

alturil
2021-11-30 20:56
has joined #pact-js

john
2021-12-01 05:39
so i tried again this afternoon. I spun up the mock server and. just pointed an insomnia graphql request at it and that works out of the box

john
2021-12-01 05:39
i tried to replicate that in that pact test, witht he same query and the same query variables but it doesnt work for some reason

tjones
2021-12-01 05:42
Could you share more details? How are you spinning up the mock server?

john
2021-12-01 05:43
no what i mean, i just wanted to see if the query works, so i started our mock server - nothing to do with pact and hit that local mock server with a graphql request and that all works

john
2021-12-01 05:44
in my test i dont have to start that mock server do i? Yesterday you said I should not do that that. That pact somehow starts its own mock server

tjones
2021-12-01 05:45
Right. In that case, what do you mean by "it doesn't work"?

john
2021-12-01 05:45
im getting a 500 server error

tjones
2021-12-01 05:45
You don't have to manually start the mock you do have to start the mock with `provider = new Pact()` and call `provider.setup()` and `provider.addInteraction()` on it

tjones
2021-12-01 05:46
500 can mean that the pact mock didn't get what it was expecting. You have to ensure that the request matches what is set up in the expectation

tjones
2021-12-01 05:46
there should be more information in the log file

tjones
2021-12-01 05:46
under `pact/log` or `log`, or wherever you configured it to be, depending on your setup

john
2021-12-01 05:47
int he log this is missing

john
2021-12-01 05:47
``` "path": "/api/v2/graphql", "query": "", "method": "post",```

john
2021-12-01 05:47
the query

john
2021-12-01 05:48
and this stuff

john
2021-12-01 05:48
[2021-12-01T15:41:55.474396 #84067] *ERROR* -- : No matching interaction found for POST /api/v2/graphql *E*, [2021-12-01T15:41:55.474408 #84067] *ERROR* -- : Interaction diffs for that route: *E*, [2021-12-01T15:41:55.474420 #84067] *ERROR* -- : W, [2021-12-01T15:41:55.501090 #84067] WARN -- : Verifying - actual interactions do not match expected interactions. Unexpected requests: POST /api/v2/graphql W, [2021-12-01T15:41:55.501133 #84067] WARN -- : Unexpected requests: POST /api/v2/graphql I, [2021-12-01T15:41:55.507248 #84067] INFO -- : Cleared interactions

tjones
2021-12-01 05:49
Ok, this says that it got an unexpected request. And, it doesn't list any expected request, so I think it's saying that the interaction wasn't set up

tjones
2021-12-01 05:49
Is your code still the same as above?

john
2021-12-01 05:50
```describe('GraphQL example', () => { // Explicit longer timeout to account for Pact server needing to spin up // Was throwing timeout errors after default 5 second timeout jest.setTimeout(30000) process.env.GRAPHQL_API_ENDPOINT = 'http://localhost:9090/api/v2/graphql' process.env.STAGE = 'local'; const provider = new Pact({ port: 9090, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), consumer: 'GraphQLConsumer', provider: 'GraphQLProvider', logLevel: 'debug', cors: true, timeout: 30000 }) beforeAll(() => provider.setup()) afterAll(() => provider.finalize()) describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `{ ProfileQuery { username } } ` ) .withOperation('ProfileQuery') .withRequest({ path: '/api/v2/graphql', method: 'POST' }) .withVariables({ "username": "default", }) .willRespondWith({ status: 200, body: { id:1, username: 'default' } }) return provider.addInteraction(graphqlQuery) }) }) it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {referrer: ""}) return expect(account).to.deep.contain({ username: 'default' }) }) afterEach(() => provider.verify()) })```

tjones
2021-12-01 05:52
Ok, the `it` block is not in the right place - it doesn't have the `beforeEach` that sets up the interaction

tjones
2021-12-01 05:52
move it to inside the describe: ``` describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `{ ProfileQuery { username } } ` ) .withOperation('ProfileQuery') .withRequest({ path: '/api/v2/graphql', method: 'POST' }) .withVariables({ "username": "default", }) .willRespondWith({ status: 200, body: { id:1, username: 'default' } }) return provider.addInteraction(graphqlQuery) }) it('returns the correct response', async () => { const { account } = await profilePageQuery('default', {referrer: ""}) return expect(account).to.deep.contain({ username: 'default' }) }) })```

tjones
2021-12-01 05:53
Small irrelevant aside: I don't think `'query profile on /'` is the right name for that describe block, but that won't affect the test run

tjones
2021-12-01 05:56
You might be asking "how would I have known this?" - in the log file, you can see that the log is getting a request that it isn't expecting, but you can't see the setup of the interaction (or if you can, there will be a log entry that shows it is cleared before the test is run)

tjones
2021-12-01 05:56
Getting the lifecycle methods in order is kind of boilerplate, which is why we introduced jest-pact, which does everything except the `addInteraction` for you

tjones
2021-12-01 05:57
I'll quickly rewrite your test with jest-pact so you can see the difference and see if you like it


john
2021-12-01 05:57
do i need to add some dependency for that to work?

john
2021-12-01 05:58
this test is being run with jest

tjones
2021-12-01 05:59
```import { pactWith } from 'jest-pact'; pactWith( { port: 9090, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), consumer: 'GraphQLConsumer', provider: 'GraphQLProvider', logLevel: 'debug', cors: true, timeout: 30000, }, (provider) => { process.env.GRAPHQL_API_ENDPOINT = 'http://localhost:9090/api/v2/graphql'; process.env.STAGE = 'local'; describe('query profile on /', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a profile request') .withQuery( `{ ProfileQuery { username } } ` ) .withOperation('ProfileQuery') .withRequest({ path: '/api/v2/graphql', method: 'POST', }) .withVariables({ username: 'default', }) .willRespondWith({ status: 200, body: { id: 1, username: 'default', }, }); return provider.addInteraction(graphqlQuery); }); it('returns the correct response', async () => { const { account } = await profilePageQuery('default', { referrer: '' }); return expect(account).to.deep.contain({ username: 'default' }); }); }); } );```

tjones
2021-12-01 05:59
yes, `npm install --save-dev jest-pact`


tjones
2021-12-01 06:01
(you don't *need* to use it, but it will mean that you don't have to have the setup/verify/finalise calls)

tjones
2021-12-01 06:03
Also, if you omit the `log` and `dir` options, it gives you some nice defaults: https://github.com/pact-foundation/jest-pact#defaults

tjones
2021-12-01 06:10
Did your test pass once you moved the `it` block?

john
2021-12-01 06:10
so Timothy

john
2021-12-01 06:10
im getting a little further so thanks

john
2021-12-01 06:11
i think maybe the issue before was in the willRespondWith block

john
2021-12-01 06:11
i only but a small part of it in there

john
2021-12-01 06:11
so maybe that was screwing it up?

tjones
2021-12-01 06:12
You need to have the full response that your consumer requires in there

john
2021-12-01 06:12
im getting this now in the log file

john
2021-12-01 06:12
Description of differences --------------------------------------

john
2021-12-01 06:12
i just dumnped the response from insomnia in there

john
2021-12-01 06:13
the response i got from our own mock server

john
2021-12-01 06:13
so i wouldnt expect there to be differences ill need to take a closer look i guess

john
2021-12-01 06:22
thanks Timothy you. really helped a lot

tjones
2021-12-01 06:23
You're welcome. The graph-ql matcher is a bit strict about the spacing etc (it's backed by a regex) so you may want to look there

john
2021-12-01 06:24
is that why i get issues like this:

john
2021-12-01 06:24
```- "query": /\{\s*ProfileQuery\s*\{\s*username\s*\}\s*\}\s*/, + "query": "query ProfileQuery(\n $username: String!\n```


tjones
2021-12-01 06:25
that's a full no-match

john
2021-12-01 06:26
yeah it said the request body didnt match

tjones
2021-12-01 06:27
your expected request looks like `{ ProfileQuery ....`, but your actual request looks like `query ProfileQuery( ...`

john
2021-12-01 06:27
ill fiddle with that to see if i can fix that

draper.joseph
2021-12-01 06:50
has joined #pact-js

abhay175
2021-12-01 07:35
has joined #pact-js

joelgrimberg
2021-12-01 11:27
has joined #pact-js

reem.alashry
2021-12-01 12:09
has joined #pact-js

beshoy.ibrahim
2021-12-01 12:09
has joined #pact-js

omar.radi
2021-12-01 12:10
has joined #pact-js

mmudassar192
2021-12-01 12:11
has joined #pact-js

ozgurerisir
2021-12-01 13:22
Hi All, struggling with Publishing my contract to Pact broker. Keep getting this error, any ideas? throw new Error("Path '" + v + "' given in pactFilesOrDirs does not exists.");

eric.seipold
2021-12-01 13:40
has joined #pact-js

matt.fellows
2021-12-01 13:43
How are you publishing?

matt.fellows
2021-12-01 13:43
Can you please provide some more info, that doesn't look like an error our code throws

ozgurerisir
2021-12-01 14:23
I've downloaded an example from PactFlow. It populated my Pact broker url and token and Im using 'npm test' to run the tests. It says the test will need to pass, which will then create the contract file before I can publish using, npm run test:publish. Before I run tests do I need to change anything in test/publish.js?

ozgurerisir
2021-12-01 14:23
Error I get is this: ? npm test > syndication-mocha-example@1.0.0 test > rimraf pacts && mocha [2021-12-01 14:19:34.470 +0000] INFO (x on x): pact-node@10.15.0: Publishing Pacts to Broker C:\Users\x\Downloads\syndication-javascript-node-consumer-mocha\node_modules\@pact-foundation\pact-node\src\publisher.js:37 throw new Error("Path '" + v + "' given in pactFilesOrDirs does not exists."); ^ Error: Path 'C:\Users\x\syndication-javascript-node-consumer-mocha\pacts' given in pactFilesOrDirs does not exists. at C:\Users\x\syndication-javascript-node-consumer-mocha\node_modules\@pact-foundation\pact-node\src\publisher.js:37:27 at Array.map (<anonymous>)

amiller
2021-12-01 16:27
Hey there team, I hope all is well. I have a quick question. Does the pact-js binding allow for decoupling of the mock service provider. i.e., having a consumer test written in typescript, and having the mock provider service up through docker My ask is similar to this github issue: https://github.com/pact-foundation/pact-php/issues/152 Please let me know and thanks!

leonardo.viana
2021-12-01 16:29
@tjones, could you please take a look at my question above regarding the timeframe for nodejs 16 support?

apselsevier
2021-12-01 16:48
has joined #pact-js

ali.korayem
2021-12-01 18:55
has joined #pact-js

luiz.filipe.abrahao
2021-12-01 21:04
has joined #pact-js

tjones
2021-12-01 22:01
You _can_ do this, but in general it is better practice not to - what is the reason you want to do this?

tjones
2021-12-01 22:02
I'm afraid I don't have a time frame. This is an open source project, supported in the spare time of the maintainers.

amiller
2021-12-01 22:05
My team is running docker node alpine which doesn't have some key dependencies needed for the pact mock provider to function properly. Mainly the missing ruby binary

tjones
2021-12-01 22:05
You don't need the ruby binary

tjones
2021-12-01 22:06
If you're running docker alpine, it is missing bash, which is required for the ruby standalone (which is the thing that means you don't need the ruby binary)

tjones
2021-12-01 22:06
usually people just add bash to alpine to get around this

tjones
2021-12-01 22:07
If you want to manage your own mock service, then you'll have to reimplement a lot of the lifecycle management, and I think you'll generally have a bad experience

tjones
2021-12-01 22:08
it is possible, though. This is how pact-web works, which is what people who are running all their tests through a browser use

amiller
2021-12-01 22:09
Ah I see. I'll take a look at our options with regards to baking bash into that alpine image. Thanks @tjones!

tjones
2021-12-01 22:10
You only need pact at test time, so if image size is a concern (which I think is usually the driver for alpine), then I'd recommend having a separate image for testing

tjones
2021-12-01 22:10
also I don't think bash changes the size very much, but don't quote me on that

amiller
2021-12-01 22:11
Ah good point, I could go that route as well

amiller
2021-12-01 22:11
With the separate image

tjones
2021-12-01 22:27
If you're still getting errors on alpine after installing bash, something is not right. It should work then

tjones
2021-12-01 22:36
If you're interested, this is what is currently blocking it: https://github.com/node-ffi-napi/ref-napi/pull/64

tjones
2021-12-01 22:39
Basically, the problem is native bindings from node. We're using the most popular wrapper for node's native API (NAPI) - which is `node-ffi-napi`. This means that we can call native libraries (such as the new Rust core for Pact) without needing to write C code to translate between the JS and the core library. However, `node-ffi-napi` has a bug that affects node 14+, appears not to be actively maintained, and I don't understand the fix well enough to address the comments on the PR.

tjones
2021-12-01 22:40
The two "easiest" options for getting a fix out asap are: 1) Understand that fix and fix it 2) Write our own C wrapper for NAPI Unfortunately, I don't have the time to make a serious dent in either.

tjones
2021-12-01 22:41
This problem affects anyone wanting to do native bindings from node, so I imagine some package will come along that *is* maintained and works on node 14+

tjones
2021-12-01 22:41
(the risk with option 2 above is that maybe we'd now be maintaining that package too, which isn't ideal)

matt.fellows
2021-12-02 00:18
see also https://docs.pact.io/docker/ (not just bash)

tjones
2021-12-02 01:10
huh, interesting. I've never had to install anything else, but perhaps the images I was using already had those other dependencies

matt.fellows
2021-12-02 01:11
yeah. the answer is usually ?it depends? but those 3 dependencies cover all of the scenarios i?ve seen.

john
2021-12-02 01:23
ok i got the consumer test working,

john
2021-12-02 01:24
next drama will be to get the provider working with PHP_ lol

tjones
2021-12-02 01:36
Glad to hear it!

john
2021-12-02 02:39
so how does pact work along something like hive which does graphql schema checking in the cicd pipeline?

tjones
2021-12-02 04:45
I don't know hive, but schema checking checks grammar, while pact checks by example

tjones
2021-12-02 04:46
a schema-compliant message may not have meaning

tjones
2021-12-02 04:46
but test-by-example confirms that you can understand the actual response that is generated

tjones
2021-12-02 04:47
in English, "colourless green ideas sleep furiously" is grammatically correct, but doesn't mean anything

tjones
2021-12-02 04:47
Schema testing is good if you don't have the ability to do anything else; it's better than nothing

tjones
2021-12-02 04:47
but pact (and contract testing in general) with examples is much better for giving confidence that your tests are correct

akanksha.sharma
2021-12-02 11:27
Hi @matt.fellows, as Murali discussed with you on call about producer driven contract testing, did you guys release something in Pact itself which supports producer driven contract testing.

matt.fellows
2021-12-02 11:29
Hi Akanksha, no the feature discussed on the call is a Pactflow specific feature

matt.fellows
2021-12-02 11:29
On the provider side, you upload the OAS file to Pactflow (and your job is to ensure that the OAS is correct, and that the provider is compatible with it. This could be a series of Postman tests, or an autogenerated OAS from code)

matt.fellows
2021-12-02 11:30
On the consumer side, you can still use Pact to generate a consumer contract (there is both a consumer _and_ provider contract). If you don?t use Pact, you can use whatever other mocking tool you like, as long as you can convert them into a pact file

matt.fellows
2021-12-02 11:30
See the examples and how to do that here: https://docs.pactflow.io/docs/workshops/bi-directional

david.cummings
2021-12-02 14:13
has joined #pact-js

miccagiann
2021-12-02 14:17
has joined #pact-js

praveen.em
2021-12-03 07:40
has joined #pact-js

ally.parker
2021-12-03 11:18
has joined #pact-js

rishabh.gaur
2021-12-03 11:43
has joined #pact-js

william.wallace
2021-12-03 15:12
has joined #pact-js

batiushkov.nik
2021-12-03 15:48
has joined #pact-js

keith.mcgrath
2021-12-03 18:28
has joined #pact-js

rchandragupthara
2021-12-03 19:32
has joined #pact-js

rchandragupthara
2021-12-03 19:34
when i run publish from local - terminal the pact is tagged with the correct branch name , but when i run the same branch from CI it gets tagged as HEAD (in this case dev is our main branch) ```pact-broker publish ./pacts/*.json --consumer-app-version=\"$(git rev-parse --short HEAD)\" --tag=\"$(git rev-parse --abbrev-ref HEAD)\"```

mike.geeves064
2021-12-03 19:43
Have you verified the git commands are actually coming back with what you expect? I've had weirdness (on GitLab for me) due to it not by default pulling a full clone, only partial (shallow)

rchandragupthara
2021-12-03 19:48
yes.. it is correct.. well atleast it works for me locally from my terminal.. The git commit it gets tagged with on the pact-broker are also correct both from my local and from CI .

mike.geeves064
2021-12-03 19:49
yeah that's what I meant, difference of how it is with a full clone locally and a shallow clone that was pulled for CI

mike.geeves064
2021-12-03 19:49
so just e.g. echo'ing out those git commands as a CI step gives the expected output?

mike.geeves064
2021-12-03 19:54
For me, the problem was GitLab wasn't pulling down tags for the repo, only the relevant commit. My use case was to pull out the most recent x.y.z tag so I could then build x.<y+1>.0-<commit hash> tagged versions without manual numbering. May be something completely different but worth verifying your CI does have all the info you expect


rchandragupthara
2021-12-03 19:56
just checked its. a full clone.. And the CI's internal (default ) git variables are correct. commit / brnach name I am fairly new to these git commands that i have put in the package.json's script for pact-publish/ can-i-deploy..

mike.geeves064
2021-12-03 19:57
hmm

mike.geeves064
2021-12-03 19:57
nvm with that one then :slightly_smiling_face:

rchandragupthara
2021-12-03 19:58
so so same commit ID on the same brnach.. ran from local --> gets tagged as 'dev' as expected ran from CI ( same commit / branch) --> gets tagged as HEAD

vinicius.cosmi
2021-12-03 20:01
has joined #pact-js

mike.geeves064
2021-12-03 20:04
hmm

mike.geeves064
2021-12-03 20:04
Jenkins?


rchandragupthara
2021-12-03 20:17
trying this.. will keep u posted.. thanks!

rchandragupthara
2021-12-03 20:22
dammmm... It worked .. thanks so much

mike.geeves064
2021-12-03 20:24
Awesome, you're welcome :grinning:

matt.fellows
2021-12-03 21:05
:taco: for @mike.geeves064 - thanks!

mike.geeves064
2021-12-03 21:09
:party_parrot:

ichatterjee
2021-12-03 21:27
has joined #pact-js

mike.geeves064
2021-12-03 21:29
:thinking_face: I don't think I've come across Pact CI examples for the versions, fixed numbers or "you should use something like the git sha", but not CI specific.. one for the Todo list maybe?

ben.watts
2021-12-03 23:48
has joined #pact-js

imikhtyuk
2021-12-06 00:36
has joined #pact-js

john
2021-12-06 03:36
Just another quick question about the provider side of things. I see int he example that you for example import an app (express app) in the consumer test and use that as the basis of the provider test. ```describe("Pact Verification", () => { before(done => { server = app.listen(4000, () => { done() }) })```

john
2021-12-06 03:37
and here: ```providerBaseUrl: "http://localhost:4000/graphql",``` can i just point my provider test to some qa mesh qraphql endpoint instead of importing it?

tjones
2021-12-06 03:39
The express server is only imported in the provider verification, I think?

tjones
2021-12-06 03:39
yes, you can

tjones
2021-12-06 03:39
However, the reason you might not want to, is that the hooks for state change are easier to use if the app is running locally

tjones
2021-12-06 03:40
for example, you can use dependency injection to modify a repository mock inside the app

tjones
2021-12-06 03:40
but if you don't need that, there's no reason not to start the server independently

john
2021-12-06 03:42
sorry i dont know why i said consumer test, i meant provider

john
2021-12-06 03:43
so i could ditch that before block and just point the baseUrl to that qa endpoint?

tjones
2021-12-06 03:44
(in fact, if you're just pointing at a running server, you don't need to use the same pact framework - you can use JS to test a Java app, etc etc)


tjones
2021-12-06 03:44
In that case, yes! What you've said is right.

john
2021-12-06 03:45
what do you mean dont need to use the same pact framework?

john
2021-12-06 03:45
can u elaborate

john
2021-12-06 03:47
i thought maybe just to change this: ```it("validates the expectations of Matching Service", () => { // lexical binding required here const opts = { // Local pacts // pactUrls: [path.resolve(process.cwd(), "./pacts/graphqlconsumer-graphqlprovider.json")], pactBrokerPassword: "O5AIZWxelWbLvqMdh2Psyg1", pactBrokerUrl: "https://test.pact.dius.com.au/", pactBrokerUsername: "dXfltyFMgN9wJ37iUpY42M", provider: "GraphQLProvider", providerBaseUrl: "http://qa_graphql_server/graphql", providerVersion: versionFromGitTag(), publishVerificationResult: true, consumerVersionTags: ["master", "test", "prod"], } return new Verifier(opts).verifyProvider()```

john
2021-12-06 03:58
so it is better practise to spin up the real server locally

matt.fellows
2021-12-06 04:27
I think Tim means that you don?t necessarily need to use Pact JS to test a JS *provider* application running on an external server, because you?re not really using any JS code

matt.fellows
2021-12-06 04:28
i.e. you could use the CLI verifier, or any other language you find better suited to the task. The main reason to use the language specific binding, is so that you can take advantage of mocking/stubbing tools and other techniques readily available to a unit testing framework. If you?re pointing at an end-to-end environment / staging environment, these tools aren?t going to be very helpful (i.e. you can?t remote stub)

john
2021-12-06 04:42
i see. I have access to the php graphql repo so it make sense for demo purposes to just use that instead of some server running on a qa env right? Ive never used php beforer so im just trying to learn how to import the server into the test, like you do witht he js example.

matt.fellows
2021-12-06 05:54
Kudos for your persistence!

norrischebl
2021-12-06 05:54
has joined #pact-js

tjones
2021-12-06 06:15
> im just trying to learn how to import the server into the test, You'll have a hard time importing the server into the JS test (maybe you could with pact PHP). As Matt says, you only need to do this if you want to use your testing framework to do stubbing for provider states.

tjones
2021-12-06 06:15
Otherwise, just point it at your server and you're good to go

tjones
2021-12-06 06:15
(I used to only ever spin up the server separately, you can definitely go that route)

smantini
2021-12-06 09:25
has joined #pact-js

gzinger
2021-12-06 11:19
has joined #pact-js

mahatmafatal
2021-12-06 13:50
has joined #pact-js

jacob.v.gardner
2021-12-06 14:59
has joined #pact-js

william.wallace
2021-12-06 16:31
Hello, just getting started with pact and typescript. I don't see a separate typescript channel, so I'm assuming this is the place for typescript questions. I'm running this example: https://github.com/pact-foundation/pact-js/tree/master/examples/typescript On master with no changes, when I run `npx tsc` I see errors. I'm assuming this should work, but it doesn't. Perhaps I'm doing something wrong? ```$ npx tsc Debugger listening on For help, see: https://nodejs.org/en/docs/inspector Debugger attached. Debugger listening on For help, see: https://nodejs.org/en/docs/inspector Debugger attached. node_modules/@types/sinon-chai/index.d.ts:107:31 - error TS2694: Namespace 'Chai' has no exported member 'ChaiPlugin'. 107 declare const sinonChai: Chai.ChaiPlugin; ~~~~~~~~~~ Found 2 errors.```

matt.fellows
2021-12-06 23:09
Why are you compiling the typescript? It?s really just a test fixture to illuminate how to run a pact test

matt.fellows
2021-12-06 23:09
you just need to run `npm t`

matt.fellows
2021-12-06 23:10
that being said, I?m sure the config could do with some updates. It looks like it complains about dependencies types

tjones
2021-12-07 02:19
It shouldn't be compiling the dependencies

tjones
2021-12-07 02:20
Possibly the tsconfig is incorrect

tjones
2021-12-07 02:20
Anyway, `npx tsc` is definitely not going to work - where is that specified in the documentation? We should correct it.

glebing2000
2021-12-07 07:28
has joined #pact-js

akanksha.sharma
2021-12-07 08:56
Can someone please share an example for Post API contract test

akanksha.sharma
2021-12-07 08:58
This is my consumer test ```"use strict" const { Matchers } = require("@pact-foundation/pact") const { postClient, getClient } = require("../../../src/consumer") describe("Clients Service", () => {     const GET_EXPECTED_BODY = {         accountId: 9348878860,          agencyCode: "4218",          accountStatus: "Open"       }     afterEach(() => provider.verify())     describe("GET Clients", () => {         beforeEach(() => {             const interaction = {                 state: "i have an account",                 uponReceiving: "a request for the account Api",                 withRequest: {                     method: "GET",                     path: "/v1/accounts/9348878860",                     headers: {                         Accept: "application/json, text/plain, */*",                     },                 },                 willRespondWith: {                     status: 200,                     headers: {                         "Content-Type": "application/json; charset=utf-8",                     },                     body: GET_EXPECTED_BODY,                 },             }             return provider.addInteraction(interaction)         })         test("returns correct body, header and statusCode", async() => {             const response = await getClient(9348878860)             expect(response.headers['content-type']).toBe("application/json; charset=utf-8")             expect(response.data).toEqual(GET_EXPECTED_BODY)             expect(response.status).toEqual(200)         })     })     const POST_BODY = {         "isExpanded":false,         "showMore":false,         "isSelected":false,         "displayCommentBox":false,         "displayActivityDropdown":false,         "isReferralEditing":false,         "datePipe":{            "locale":"en-US"         },         "activityType":"Note",         "activityDtTm":"2021-12-01T16:28:31.000Z",         "note":{            "isEditing":false,            "datePipe":{               "locale":"en-US"            },            "isEdited":false,            "editedDate":null,            "editedTime":null,            "notes":"<p>test pact</p>"         },         "contacts":[                     ],         "activityFlag":"Normal",         "dueDate":null,         "sendTo":"Services"     }     const POST_EXPECTED_BODY = {         activityType: POST_BODY.activityType,         //activityDtTm: POST_BODY.activityDtTm,         activityFlag: POST_BODY.activityFlag,         //sendTo: POST_BODY.sendTo,         //isEditing: POST_BODY.note.isEditing,         //locale: POST_BODY.datePipe.locale,         //notes: POST_BODY.note.notes     }     describe("Post Client", () => {                  beforeEach(() => {             const interaction = {                 state: "i share a new note",                 uponReceiving: "a request to create a new note",                 withRequest: {                     method: "POST",                     path: "/v1/accounts/9404268316/user_activities/notes",                     headers: {                         "Content-Type": "application/json;charset=utf-8"                     },                     body: POST_BODY,                 },                 willRespondWith: {                     status: 200,                     body: Matchers.like(POST_EXPECTED_BODY).contents,                     //body: POST_EXPECTED_BODY,                 },             }             return provider.addInteraction(interaction)         })         test("returns correct body, header and statusCode for Post Api", async() => {             const response = await postClient(POST_BODY)             console.log("Response is : " + response.data)             //expect(response.data.activityFlag).toEqual('Normal')             expect(response.status).toEqual(200)     })   }) })```

akanksha.sharma
2021-12-07 08:58
my test is getting failed at this point in Post API

tjones
2021-12-07 09:32
This error looks like it is because your code is not returning what you are expecting it to

tjones
2021-12-07 09:33
Also, it looks like the actual post request (if any) didn't match the request you set up

tjones
2021-12-07 09:33
Have a look in the log file to see what happened

tjones
2021-12-07 09:33
(there should be a note to do that in the log you shared - either above or below your screenshot)

matt.fellows
2021-12-07 09:47
yes, the reason for the failure is notably absent there

matt.fellows
2021-12-07 09:48
It should tell you which request it was expecting, and what it received. The log file as Tim mentioned will tell you this

matt.fellows
2021-12-07 09:48
To answer your question though, there is a POST example in the e2e examples in the Pact JS repository

sergio.freire
2021-12-07 09:52
has joined #pact-js

akanksha.sharma
2021-12-07 10:14
Okay

matt.fellows
2021-12-07 10:20
If I were to have a guess, it?s that your `await postClient(POST_BODY)` doesn?t know to send it to account with id `9404268316` (I can?t see how it would know that from the context). But you?ll need to log in your terminal/logs to see what your actual code is doing

sahoo.skumar
2021-12-07 10:55
has joined #pact-js

akanksha.sharma
2021-12-07 11:39
Yeah, its actually throwing this error

akanksha.sharma
2021-12-07 11:39
something like missing request

akanksha.sharma
2021-12-07 11:40
```const postClient = async (body) => {       const res = await axios       .post(`${getApiEndpoint}}/v1/accounts/9404268316/user_activities/notes`, body, {'Content-Type': 'application/json;charset=utf-8'})       .then((res) => {           return res         })         .catch((err) => {           return err.res         })     return res }```

akanksha.sharma
2021-12-07 11:41
this is my postClient method

akanksha.sharma
2021-12-07 11:41
Here I have given the end point of the API which includes the account Id as well

matt.fellows
2021-12-07 12:48
Is the request being sent to them pact mock server or the talk API? It needs to point at the mock server created by pact

matt.fellows
2021-12-07 12:48
Check out the pact log file, it will tell you what it sees


william.wallace
2021-12-07 13:07
Thank you for all your responses. If I make changes to the `get-dog.spec.ts` and `index.ts`, I assume that that I would need to run `npm tsc` to rebuild. Perhaps I'm wrong? The reason I started down that path is that it seemed that my changes to the tests and `index.ts` were not getting evaluated. I then reverted all my changes and ran `npm tsc` and noticed the dependency error with `sinon-chai` persisted. The `npm t` command runs the test as expected, and succeeds when there are no changes. This command fails when I change the tests, but when run in a dubugger, the code with my changes cannot be stepped into. In any case, please clarify when compiling is necessary.

kingyang728
2021-12-07 15:58
has joined #pact-js

jesseaantebi
2021-12-07 19:36
has joined #pact-js

rsheikh
2021-12-07 22:34
has joined #pact-js

matt.fellows
2021-12-08 00:56
You shouldn?t need to run tsc at all

matt.fellows
2021-12-08 00:57
The mocha config is setup to automagically interpret the typescript as part of running the test: ```--bail --require ts-node/register --require ./test/helper.ts --require source-map-support/register --full-trace --reporter spec --colors --recursive --timeout 30000 test/*.spec.ts```

matt.fellows
2021-12-08 00:57
I?ve just changed both the spec and the `index.ts` , and the changes are picked up without needing to run anythnig else other than `npm t`

matt.fellows
2021-12-08 00:58
i.e. if I update `index.ts` to hit a different, unexpected endpoint I get this: ```... The Dog API [2021-12-08 00:58:38.232 +0000] INFO (71938 on Matts-iMac): pact-node@10.13.3: Pact running on port 59449 [2021-12-08 00:58:38.641 +0000] INFO (71938 on Matts-iMac): pact@9.16.0: Setting up Pact with Consumer "Typescript Consumer Example" and Provider "Typescript Provider Example" using mock service on Port: "59449" get /dogs using builder pattern 1) returns the correct response Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /dogs Unexpected requests: GET /iupdatedindex.ts See /Users/matthewfellows/development/public/pact-js/examples/typescript/logs/mockserver-integration.log for details. 2) "after each" hook for "returns the correct response" [2021-12-08 00:58:38.684 +0000] INFO (71938 on Matts-iMac): pact@9.16.0: Pact File Written [2021-12-08 00:58:38.684 +0000] INFO (71938 on Matts-iMac): pact-node@10.13.3: Removing Pact process with PID: 71939 [2021-12-08 00:58:38.687 +0000] INFO (71938 on Matts-iMac): pact-node@10.13.3: Deleting Pact Server with options: {"consumer":"Typescript Consumer Example","cors":false,"dir":"/Users/matthewfellows/development/public/pact-js/examples/typescript/pacts","host":"127.0.0.1","log":"/Users/matthewfellows/development/public/pact-js/examples/typescript/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":59449,"provider":"Typescript Provider Example","spec":2,"ssl":false}```

matt.fellows
2021-12-08 00:59
If I updated the spec to expect a different path: ```... The Dog API [2021-12-08 00:59:15.554 +0000] INFO (72018 on Matts-iMac): pact-node@10.13.3: Pact running on port 59463 [2021-12-08 00:59:15.947 +0000] INFO (72018 on Matts-iMac): pact@9.16.0: Setting up Pact with Consumer "Typescript Consumer Example" and Provider "Typescript Provider Example" using mock service on Port: "59463" get /dogs using builder pattern 1) returns the correct response Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /iexpectadifferentendpoint Unexpected requests: GET /dogs See /Users/matthewfellows/development/public/pact-js/examples/typescript/logs/mockserver-integration.log for details.```

matt.fellows
2021-12-08 00:59
all I?m runnig is `npm t`. I think the documentation is correct from what I can see

jorgwel
2021-12-08 01:22
has joined #pact-js

rahul.anwekar23
2021-12-08 04:19
has joined #pact-js

luanacosta05
2021-12-08 20:34
has joined #pact-js

tjones
2021-12-09 00:20
How are you running the debugger?

tjones
2021-12-09 00:20
What do you mean by ?cannot be stepped into? - can you tell us what error you are getting? I think this is probably a config issue with your typescript setup, which means it might be hard for us to help.

saurabh.techiee
2021-12-09 09:41
has joined #pact-js

albertcabantog
2021-12-09 10:52
has joined #pact-js

paul.scholes
2021-12-10 10:21
has joined #pact-js

paul.scholes
2021-12-10 10:25
Hi All, I am trying pact for the first time, and I have got as far as running my provider test, but I am getting a connection refused from the localhost. Provider test: ```const { Verifier } = require('@pact-foundation/pact'); describe('Login verification', () => { jest.setTimeout(60000); test('Validate ACD Login', () => { let opts = { provider: 'loginAPI', providerBaseUrl: 'http://localhost:8800', pactBrokerUrl : '########', pactBrokerToken: '#######', providerVersion: '1.0.0', logLevel: 'DEBUG' } return new Verifier(opts).verifyProvider(); }) })``` The log (once the pact file has been retreived: `Verifying a pact between loginService and loginAPI [PENDING]` `A valid auth request` `with POST /api/login` `[2021-12-10 09:59:46.884 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: returns a response which` `[2021-12-10 09:59:46.884 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0:` `[2021-12-10 09:59:46.886 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: DEBUG: Setting up provider state '' for consumer 'loginService' using provider state set up URL http://localhost:57035/_pactSetup` `[2021-12-10 09:59:46.908 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: I, [2021-12-10T09:59:46.907242 #12864] INFO -- request: POST http://localhost:57035/_pactSetup` `[2021-12-10 09:59:46.910 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: D, [2021-12-10T09:59:46.908239 #12864] DEBUG -- request: User-Agent: "Faraday v0.17.4"` `Content-Type: "application/json"` `[2021-12-10 09:59:46.971 +0000] WARN (171912 on DESKTOP-9AIJ0DN): pact@9.17.0: No state handler found for "null", ignoring` `[2021-12-10 09:59:46.983 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: I, [2021-12-10T09:59:46.982739 #12864] INFO -- response: Status 200` `[2021-12-10 09:59:46.983 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact-node@10.15.0: D, [2021-12-10T09:59:46.982739 #12864] DEBUG -- response: x-powered-by: "Express"` `content-type: "text/plain; charset=utf-8"` `content-length: "2"` `etag: "W/\"2-nOO9QiTIwXgNtWtBJezz8kv3SLc\""` `date: "Fri, 10 Dec 2021 09:59:46 GMT"` `connection: "close"` `[2021-12-10 09:59:47.014 +0000] DEBUG (171912 on DESKTOP-9AIJ0DN): pact@9.17.0: Proxing` `Error: connect ECONNREFUSED 127.0.0.1:8800` `at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)` Can anyone help?

chris.sloan
2021-12-10 10:48
has joined #pact-js

matt.fellows
2021-12-10 11:01
Provider verification takes a contract file and checks if your provider is compatible with it by issuing HTTP calls to it. Have you started the provider? It seems you're probably not

matt.fellows
2021-12-10 11:02
Howtolearn

2021-12-10 11:02
Here are a number of useful hands-on labs that teach all of the key concepts https://docs.pact.io/implementation_guides/workshops

matt.fellows
2021-12-10 11:02
You might like these tutorials too: https://docs.pactflow.io/docs/tutorials

paul.scholes
2021-12-10 11:04
Thanks @matt.fellows.

leon.york
2021-12-10 12:42
has joined #pact-js

yousafn
2021-12-10 14:29
I would agree that it looks like the provider isn?t started, or isn?t on port 8800. This is the bit of the log that gives me that information > `Error: connect ECONNREFUSED 127.0.0.1:8800` You could try and hit your provider via the command line, if it is started. looking at your request, its a post to `/api/login`, I?ve guessed the payload. ```curl -X http://127.0.0.1:8800/api/login -d '{"user":"foo","password":"bar"}'``` It is usually preferred to start your provider as part of the verifier step, so normally importing say the express or koa app and calling app.listen() on it, and tearing it down at the end. That way you can directly manipulate your provider, in order to set up appropriate state (test data) for state handlers

yousafn
2021-12-10 14:30
double post

kyle.craviotto
2021-12-10 16:40
has joined #pact-js

lorenz.schumann
2021-12-10 18:33
has joined #pact-js

william.wallace
2021-12-10 19:21
Thank you Matt! I didn't understand how/if typescript was handled by `npm t`. Knowing this is helpful: "The mocha config is setup to automagically interpret the typescript as part of running the test"

william.wallace
2021-12-10 19:49
To follow up on the typescript example issue, I found that mocha requires more arguments to be able to run mocha with typescript. This isn't so much a problem with the example, but when I implemented the example technique to run pact consumer tests against my typescript code, I was seeing an error: ```SyntaxError: Cannot use import statement outside a module``` To fix this, I added `mocha -r ts-node/register` to my `test` command under scripts in package.json: ```"scripts": { "test": "nyc --check-coverage --reporter=html --reporter=text-summary mocha -r ts-node/register test/*.spec.ts", "mocha:direct": "mocha" },``` https://chiragrupani.medium.com/writing-unit-tests-in-typescript-d4719b8a0a40

luispires.m
2021-12-13 12:32
has joined #pact-js

fabio.rodrigues
2021-12-13 16:22
has joined #pact-js

william.wallace
2021-12-13 20:09
Hello everyone, I'm using typescript to test an API, and I want to validate a 400 error code from the server. The typescript example uses this construct to run and validate successful responses, but how can I validate an error? ```it("returns the correct response", done => { dogService.getMeDogs().then((response: any) => { expect(response.data[0]).to.deep.eq(dogExample) done() }, done) })``` I've tried this, which ends up writing the proper entry into my pact, but the test fails ```it("should return 400", done => { try { dogService.getMeDogs().then((response: any) => { done() }, done) } catch(err: any) { console.log(`response: ${JSON.stringify(err.response.data[0])}`) // expect(err.response.data[0]).to.deep.eq(ERROR_400) } })``` Any ideas?

william.wallace
2021-12-13 20:55
I have some success with this construct. Curious if this is the best way to obtain non-200 responses for validation: ```it("should return 400", done => { dogService.getMeDogs().catch(function (error) { if(error.response) { console.log(`error data: ${error.response.data}`) console.log(`error status: ${error.response.status}`) console.log(`error headers: ${error.response.headers}`) } done() }) })```

tjones
2021-12-13 21:11
With jest, I do something like: ``` expect(dogService.getMeDogs()).rejects.toEqual( new SomeCustomError("Whatever the error is"), ));```

tjones
2021-12-13 21:11
There's nothing special about error handling with Typescript, just do the same as you would in JS

tjones
2021-12-13 21:12
you're (probably) testing for a failed promise

tjones
2021-12-13 21:13
In this part of the test, you're just testing that the business logic that is coming out of the API is correct - if your app returns a failed promise with a business error, assert against that. If your app returns an empty or an "API error" payload, assert against that

tjones
2021-12-13 21:14
This is a design comment, not a testing comment, but: ```dogService.getMeDogs().catch(function (error) { if(error.response) { console.log(`error data: ${error.response.data}`)``` ^ This doesn't feel right to me, because the http error response object belongs to the API layer. I think the API layer shouldn't expose this detail to the caller

william.wallace
2021-12-13 21:15
Thanks for the examples! Right - it's my newbness to JS /async constructs that's holding me back. I'm asserting against the body in the error, as that needs to contain specific fields.

tjones
2021-12-13 21:15
(I get around this by marshalling to custom errors or types in the API layer)

tjones
2021-12-13 21:15
right, but (in my opinion) the caller shouldn't know what the structure of the body is

tjones
2021-12-13 21:16
it should know what the structure of your error response type is. Maybe that's the same as the HTTP error, but if it is, I think you'll be leaking concerns

tjones
2021-12-13 21:16
eg, in your example, your caller might need to know what `status: 404` means, which doesn't feel right to me

yousafn
2021-12-13 21:16
Assuming you are talking about this test https://github.com/pact-foundation/pact-js/blob/master/examples/typescript/test/get-dog.spec.ts For that test ``` describe("get /dogs returns a 400", () => { before(() => { const interaction = new Interaction() .given("I have no dogs") .uponReceiving("a request for all dogs with the builder pattern") .withRequest({ method: "GET", path: "/dogs", headers: { Accept: "application/json", }, }) .willRespondWith({ status: 400, headers: { "Content-Type": "application/json", }, }) return provider.addInteraction(interaction) }) it("returns the correct response", done => { dogService.getMeDogs().catch((error)=>{ expect(error.status).to.eq(400) done() }) }) })```

tjones
2021-12-13 21:17
Oh right, the example follows the design I am advising against. We should fix that :wink:

yousafn
2021-12-13 21:17
You basically need to catch the error, assert in there, and then call done. (with mocha)

yousafn
2021-12-13 21:17
Yeah that pattern sucks tho

tjones
2021-12-13 21:17
Here's an example from my actual code: ``` expect(client.deleteAttachment(3)).rejects.toEqual( new NotFoundError("Attachment '3' not found"), ));```


tjones
2021-12-13 21:19
Here's (part) of the error handler that lives inside the API layer to support that code: ```const errorHandler = <T>( error: AxiosError<ServerError | ServerFatalError>, ): never => { if (axios.isAxiosError(error) && error.response) { // Marshal expected errors here if (error.response.status === 404 && error.response.data.description) { throw new NotFoundError(error.response.data.description); }```

william.wallace
2021-12-13 21:21
Thank you for the examples!

tjones
2021-12-13 21:21
To summarise: ? Yes, however your testing framework checks against rejected promises is what you want to do here (assuming your API layer returns a rejected promise when there's a 4xx or 5xx) ? It's best practice not to expose implementation details of the API layer to the caller

william.wallace
2021-12-13 21:23
Very good points, and an angle I hadn't considered. Thank you very much

tjones
2021-12-13 21:24
I prefer the explicit "I want this promise to resolve in this way" style, but if you want to use the `done` callback in mocha you could do something like this: ```it("should return 400", done => { dogService.getMeDogs().then(function() { done(new Error("This promise is not expected to resolve")) }, function (error) { if(error.response) { // Replace these with assertions on the data console.log(`error data: ${error.response.data}`) console.log(`error status: ${error.response.status}`) console.log(`error headers: ${error.response.headers}`) } done() }) })```

tjones
2021-12-13 21:25
or I think you can just return the promise - equivalent code: ```it("should return 400", () => { // Note the use of `return` here return dogService.getMeDogs().then(function() { throw new Error("This promise is not expected to resolve") }, function (error) { if(error.response) { // Replace these with assertions on the data console.log(`error data: ${error.response.data}`) console.log(`error status: ${error.response.status}`) console.log(`error headers: ${error.response.headers}`) } }) })```

tjones
2021-12-13 21:26
You're welcome! Let us know if you have any further questions

mbailey
2021-12-13 22:17
has joined #pact-js

dkwak
2021-12-14 03:47
has joined #pact-js

haoran.lin
2021-12-14 05:27
has joined #pact-js

haoran.lin
2021-12-14 07:20
Hi all, I want to disable `enablePending` option. I always want to fail test suit. I'm using latest `pact@9.16.5` and `pact-node@10.13.10` . I've explicitly set `enablePending` to false when pass options to `new Verifier(opts)` . Here are some logs I think may help (with sensitive information mask with ***): ```[2021-12-14 07:13:32.894 +0000] DEBUG (89686 on ***): pact-node@10.13.10: Starting pact binary '***/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.77/pact/bin/pact-provider-verifier', with arguments [--provider-states-setup-url http://localhost:56275/_pactSetup --log-level debug --provider *** --provider-app-version 056f6ac9 --publish-verification-results true --consumer-version-tag *** --pact-broker-base-url *** --provider-base-url http://localhost:56275 --verbose true]``` ```[2021-12-14 07:19:13.750 +0000] DEBUG (89686 on ***): pact-node@10.13.10: 15 interactions, 0 failures, 2 pending Pending interactions: (Failures listed here are expected and do not affect your suite's status)```

tjones
2021-12-14 07:20
What version of the broker are you on?

haoran.lin
2021-12-14 07:21
I get this on header ```X-Pact-Broker-Version: 2.93.0```

tjones
2021-12-14 07:22
hmm, that's the latest

tjones
2021-12-14 07:23
it's weird that enablePending is not set in the log there

haoran.lin
2021-12-14 07:24
maybe that's intentional by not set false arguments


tjones
2021-12-14 07:26
I don't think it is intentional

tjones
2021-12-14 07:26
let me take a look

tjones
2021-12-14 07:36
aha! found it. All things explicitly set to false are ignored. That's not intentional.

haoran.lin
2021-12-14 07:37
This should be a bug?


tjones
2021-12-14 07:42
It sure is

tjones
2021-12-14 07:42
I've fixed it and added tests, now running the release process

tjones
2021-12-14 07:43
The argument mapper is a bit hairy. I've replaced it with something much nicer for the rust core

tjones
2021-12-14 07:44
Thanks for the report! I can't believe it's been like this forever

tjones
2021-12-14 07:44
The broker recently changed to make pending the default, I think

haoran.lin
2021-12-14 07:47
Thank you very much. I'll test that later. :tada:

tjones
2021-12-14 07:58
pact-node@10.16.1 is out with this fix. Pact-js will pick it up automatically on npm install (but you may need to remove package-lock / node_modules). I can bump the minimum version of pact-node in pact-js if this is a problem

tjones
2021-12-14 08:00
I also filed https://github.com/pact-foundation/pact_broker/issues/533 , since I think we should mark this as a breaking change in the broker

tjones
2021-12-14 08:00
Thanks again for the report!

tom450
2021-12-14 08:06
has joined #pact-js

pajaree.tuampitak
2021-12-14 10:00
has joined #pact-js

nitins333
2021-12-14 10:03
has joined #pact-js

haoran.lin
2021-12-14 12:51
Hi @tjones, with updating to `pact-node@10.16.1`, I can see arguments set with `--enable-pending false` in the log. But my test suites still passed with ```[2021-12-14 12:50:28.339 +0000] DEBUG (7320 on ***): pact-node@10.16.1: 15 interactions, 0 failures, 2 pending Pending interactions: (Failures listed here are expected and do not affect your suite's status)```

haoran.lin
2021-12-14 13:00
When I see https://github.com/pact-foundation/pact-provider-verifier, maybe the correct way to disable pending is passing `--no-enable-pending` ?

jaakko.tompuri
2021-12-14 13:10
has joined #pact-js

albert.moreno
2021-12-14 17:01
has joined #pact-js

tjones
2021-12-15 01:23
damnit, you're right. My fault for making changes late at night

haoran.lin
2021-12-15 01:57
No worries. I'm surprised that I got response instantly and the patch is released within 1 hr

haoran.lin
2021-12-15 02:04
I think there're two way to solve this. One is raise an issue to `pact-provider-verifier` and let them to add support for `--enable-pending false` . Also we can make __https://github.com/pact-foundation/pact-js-core/blob/8f3e9120408b10fcc08b04c8b74a512ef3ba19c4/src/verifier.ts#L25 to support `{[index: string]: (argValue: string) => string | (string[])}`

haoran.lin
2021-12-15 02:06
like `{enablePending: val => val ? '--enable-pending' : '--no-enable-pending'}` . That's a demonstration, maybe also need to consider `undefined`

haoran.lin
2021-12-15 02:35
Hi, @tjones, I raise an issue https://github.com/pact-foundation/pact-js/issues/782 to help my team track it

himanshu
2021-12-15 06:16
has joined #pact-js

haoran.lin
2021-12-15 09:16
Hi Timothy. I just https://github.com/pact-foundation/pact-js-core/pull/356 to fix this. Can you take a review if you have time.

akanksha.sharma
2021-12-15 11:31
Hi @matt.fellows , I am trying to make an interaction for 401 status for my API. but I am getting error as "Pact verification failed! Actual interactions do not match expected interactions for mock MockService." Please find below code: ```describe("When a call is made to API for account 9348878860 and user is not authorized", () => {     before(() => mockprovider.addInteraction({         state: "When user is not authorized",         uponReceiving: "a request without authentication token",         withRequest: {             method: "GET",             path: "/v1/accounts/9348878860"         },         willRespondWith: {             status: 401,         },     }) ) it("It will return a 401 unauthorized response", () => {         expect(getErrorAccount()).to.eventually.be.rejectedWith("Unauthorized")     }) })``` and getErrorAccount function: ```const axios = require("axios"); const express = require("express") const request = require("superagent") const server = express() const getApiEndPoint = () => process.env.API_HOST  //|| "http://localhost:8081" const authHeader = {     Authorization: "Bearer token",   } //Fetch data for account with an ID which is currently available const getAccount = id => {     return request         .get(`${getApiEndPoint()}/v1/accounts/${id}`)         .set(authHeader)         .then(res => res.body, () => null) } const getErrorAccount = () => {     return request         .get(`${getApiEndPoint()}/v1/accounts/9348878860`)         .then(res => res.status); } module.exports = {     server,     getAccount,     getErrorAccount, }``` log file showing: ```I, [2021-12-15T16:58:39.495826 #26216]  INFO -- : Registered expected interaction GET /v1/accounts/9348878860 D, [2021-12-15T16:58:39.496218 #26216] DEBUG -- : {   "description": "a request without authentication token",   "providerState": "When user is not authorized",   "request": {     "method": "GET",     "path": "/v1/accounts/9348878860"   },   "response": {     "status": 401,     "headers": {     }   },   "metadata": null } W, [2021-12-15T16:58:39.512215 #26216]  WARN -- : Verifying - actual interactions do not match expected interactions.  Missing requests:   GET /v1/accounts/9348878860 I, [2021-12-15T16:58:39.514209 #26216]  INFO -- : Received request GET /v1/accounts/9348878860 W, [2021-12-15T16:58:39.515207 #26216]  WARN -- : Missing requests:   GET /v1/accounts/9348878860 D, [2021-12-15T16:58:39.515207 #26216] DEBUG -- : {   "path": "/v1/accounts/9348878860",   "query": "",   "method": "get",   "headers": {     "Host": "localhost:52654",     "Accept-Encoding": "gzip, deflate",     "User-Agent": "node-superagent/3.8.3",     "Connection": "close",     "Version": "HTTP/1.1"   } } I, [2021-12-15T16:58:39.515207 #26216]  INFO -- : Found matching response for GET /v1/accounts/9348878860 D, [2021-12-15T16:58:39.516204 #26216] DEBUG -- : {   "status": 401,   "headers": {   } } I, [2021-12-15T16:58:39.526188 #26216]  INFO -- : Cleared interactions I, [2021-12-15T16:58:39.540636 #26216]  INFO -- : Writing pact for AccountAPI_provider to C:/contractTests_PolicyAdminWeb/pacts/accountapi_consumer-accountapi_provider.json``` Screenshot of error message is attached. Can you please take a look and suggest where I am wrong.

matt.fellows
2021-12-15 11:33
Note how there is a ?verifying? call and then after that it received a call to `GET /v1/accounts/?`?

matt.fellows
2021-12-15 11:33
That tells me you have a poorly handled promise somewhere

matt.fellows
2021-12-15 11:33
basically, you are asking Pact ?did all of the interactions get verified?? before you actually ran the test

matt.fellows
2021-12-15 11:34
it looks like you have the `it` block outside of a describe block, so perhaps it?s just configuration

matt.fellows
2021-12-15 11:35
```it("It will return a 401 unauthorized response", () => {         expect(getErrorAccount()).to.eventually.be.rejectedWith("Unauthorized") <------------------------------ this is a promise, you should return or await it     }) })```

akanksha.sharma
2021-12-15 11:39
got it

akanksha.sharma
2021-12-15 11:39
Worked now

akanksha.sharma
2021-12-15 11:39
Thanks

diva.pant1
2021-12-15 14:21
has joined #pact-js

johnreilly100
2021-12-15 16:36
has joined #pact-js

elliot.weiser
2021-12-15 19:06
has joined #pact-js

sunit
2021-12-16 07:27
has joined #pact-js

felipe.simoes
2021-12-16 18:42
has joined #pact-js

ameadewi
2021-12-16 18:48
has joined #pact-js

akennedy
2021-12-16 22:28
Hey folks, my team is having a difficult time debugging a new failure resulting from an intended change on the provider to return a 401 response rather than a 500 for a PUT request with an invalid required ID. All other tests in that contract pass with the incoming provider side PR, so we thought to simply update the contract on the consumer to match the new 401 response. The only things that we altered in the contract test were the test name and the expected response code (matching the failure), but once we merged that fix for the consumer and it was compared to the incoming provider PR, other seemingly unrelated tests within that contract failed. The test we intended to fix now passes. I know this is a relatively vague description, but does anyone know of any possible ways that a change within a single test on the consumer side to reflect an intended incoming change on the provider side could result in other tests within that contract to fail?

tjones
2021-12-16 22:29
are they failing on consumer or provider side?

tjones
2021-12-16 22:29
non-determinisim on the consumer side is usually promises that aren't being waited for

tjones
2021-12-16 22:30
on the provider side, it might be provider states that aren't cleared up

akennedy
2021-12-16 22:45
it's failing on the provider side. Each time the tests run, we create a new database and seed it with required data. We did notice that the tests that are failing now all require the same credential token that is part of that seeded data. The test that we changed does not involve that token whatsoever, and each database is begun fresh when tests begin and torn down when they end, so i'm not sure how the token's creation could be affected

tjones
2021-12-16 23:24
Perhaps the pact generation isn't clearing the interactions correctly, or has some non-deterministic behaviour in how it is run

tjones
2021-12-16 23:24
What test runner are you using? Can you share an example of your consumer tests?

akennedy
2021-12-16 23:30
Jest. Here's the original test that needs to be updated to return 401, followed by the request: ``` describe('update salesforce credential when called with a invalid request ', () => { beforeAll(() => provider.addInteraction(interactions.invalidPut_500)); it('should return 500 response code', async () => { const companyId = '3dfa5365-6609-4339-b377-ed51fd7560a8'; const integrationId = '8aea985a-5a18-4bc2-9b45-20d4bc2453e0'; const type = 'salesforce'; const input = { label: 'Updated QA Pact Label' }; const request = new Integrations(apiUrl); request.initialize({ context: { token: BEARER_TOKENS.CONNECTIONS_ADMIN, }, }); try { await request.updateIntegration({ companyId, integrationId, type, input }); } catch (e) { expect(e.extensions.response.status).toBe(500); } }); });```

akennedy
2021-12-16 23:30
``` invalidPut_500: { state: 'a salesforce credential with id 8aea985a-5a18-4bc2-9b45-20d4bc2453e0 does not exist', uponReceiving: 'a request to update label for salesforce credential with id 8aea985a-5a18-4bc2-9b45-20d4bc2453e0', withRequest: { method: 'PUT', path: '/api/v1/salesforce_credentials/8aea985a-5a18-4bc2-9b45-20d4bc2453e0', query: 'company_id=3dfa5365-6609-4339-b377-ed51fd7560a8', headers: { Authorization: `Bearer ${BEARER_TOKENS.CONNECTIONS_ADMIN}`, 'Content-Type': 'application/json' }, body: { "credential": { "label": "Updated QA Pact Label" } } }, willRespondWith: { status: 500, headers: { 'Content-Type': 'text/html; charset=UTF-8', }, }, },```

tjones
2021-12-16 23:38
I think the error is likely to be elsewhere in your test suite, not the test that was updated

tjones
2021-12-16 23:39
How are you calling the pact lifecycle methods? Are you using jest-pact or doing it manually?

akennedy
2021-12-16 23:43
Here's the beginning of the test file before the individual test describe blocks: ```import { getProvider } from '../../../utils/pact'; import Integrations from '../../Integrations'; import { interactions } from '../../../.fixtures/pact/interactions/ConnectionsApiContractInteractions'; import { BEARER_TOKENS } from '../../../utils/pact/consts'; const provider = getProvider({ provider: 'connections-api', }); let apiUrl; /** * @group connectionsLayer * @group contractTest */ describe('Connections', () => { beforeAll(async () => { jest.setTimeout(30000); const opts = await provider.setup(); apiUrl = `http://localhost:${opts.port}`; }); afterEach(() => provider.verify()); afterAll(() => provider.finalize());```

tjones
2021-12-16 23:58
What is `getProvider` ?

akennedy
2021-12-17 00:00
```import { Pact, } from '@pact-foundation/pact'; import path from 'path'; export const getProvider = options => { const { provider, ...rest } = options; return new Pact({ consumer: 'graphql', log: path.resolve(process.cwd(), 'var/pact/logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'INFO', provider, ...rest, }); };```

tjones
2021-12-17 00:09
Hmm those all look right

akennedy
2021-12-17 00:09
this setup has been working fine for us for months, it's just with this new provider side PR requiring a change to the one test that we're now having issues

tjones
2021-12-17 00:09
oh, one subtlety - your add interaction is done in a `beforeAll`

tjones
2021-12-17 00:10
this means that you won't be able to have more than one test in the block

tjones
2021-12-17 00:10
because `afterEach` will `verify()` the interactions, which clears them

tjones
2021-12-17 00:10
I would do a close read of your test setup / log. I reckon there might be an interaction that is staying around when it shouldn't.

tjones
2021-12-17 00:11
I think it will be safer to do your `addInteraction` in a `beforeEach`

tjones
2021-12-17 00:11
otherwise you'd have to manually ensure you only have one `it` block per interaction

akennedy
2021-12-17 00:11
all of our tests are separated into their own blocks at the moment, but thanks for that advice

akennedy
2021-12-17 00:12
we do have a test that deletes the credential that is missing in the new failures

akennedy
2021-12-17 00:12
but that test should run last

tjones
2021-12-17 00:13
The order of interactions during pact verification is not specified

tjones
2021-12-17 00:13
so they could run in any order

akennedy
2021-12-17 00:14
ah hmm, I wonder how this could consistently pass to begin with then

akennedy
2021-12-17 00:16
just so I understand properly, the order of adding interactions is not specified, but the tests themselves will run in order? Given each test is in its own describe block

tjones
2021-12-17 00:20
It depends whether you mean consumer tests or provider verification

tjones
2021-12-17 00:20
the consumer test order is determined by your test framework (in this case, jest)

tjones
2021-12-17 00:20
the provider verification of those interactions might run in any order

akennedy
2021-12-17 00:20
ah interesting

akennedy
2021-12-17 00:21
ok well thanks for all the help! I'll relay this back to the team and likely change what data we are seeding

tjones
2021-12-17 00:21
Are you using provider states?

tjones
2021-12-17 00:21
Provider states is how you keep the tests order agnostic

tjones
2021-12-17 00:22
You say "in this state, this request has this response"

akennedy
2021-12-17 00:22
we are not, we're just plain seeding all the data we need when the database loads

tjones
2021-12-17 00:22
then you can use the provider state setup handlers to arrange the provider in the precondition

tjones
2021-12-17 00:22
right

tjones
2021-12-17 00:23
That will work, as long as all tests need the same data

akennedy
2021-12-17 00:23
sounds like provider states is a good next step :slightly_smiling_face:

tjones
2021-12-17 00:23
as soon as they don't (eg, "a request for X returns 404 when X is not found" and "a request for X returns X when it is present")

tjones
2021-12-17 00:23
then you'll have challenges

tjones
2021-12-17 00:24
You may also be interested in https://www.npmjs.com/package/jest-pact. - it does the boilerplate setup for you

akennedy
2021-12-17 00:25
great, thanks again!

tjones
2021-12-17 00:25
You're welcome


tjones
2021-12-17 00:25
this is the intro to provider states

michael.scheepers
2021-12-17 08:11
has joined #pact-js

yanis.benekaa
2021-12-17 16:05
has joined #pact-js

akanksha.sharma
2021-12-20 07:14
Can we pass multiple provider names in provider.spec.js file ?

matt.fellows
2021-12-20 07:16
can you please elaborate? You can?t verify multiple providers at once using the Verifier if that?s what you?re asking

matt.fellows
2021-12-20 07:17
but you could have a JS file that runs the verifier once per provider

akanksha.sharma
2021-12-20 07:27
I created two contracts for two different API's and in provider.spec.js file, can I pass both the providers so that it will verify with my real time provider in one go ```describe("Account API Pact verification", () => {     it("validates the expectations of Matching Service", () => {         let token = "INVALID TOKEN"         const opts = {             provider: "AccountAPI_provider" || "AccountAPI_provider_contact",             logLevel: "DEBUG",             providerBaseUrl: SERVER_URL,             requestFilter: (req, res, next) => {                 console.log(                   "Middleware invoked before provider API - injecting Authorization token"                 )```

akanksha.sharma
2021-12-20 07:29
These are my test scripts : ```"test:consumer": "mocha --exit --timeout 30000 tests/consumer/*.js",     "pact:publish": "npx pact-broker publish ./pacts --consumer-app-version=\"1.0.0\" --tag AccountAPI --broker-base-url=https://centricconsulting.pactflow.io --broker-password=mg_43dusgdYRUxGStUei-w",     "test:provider": "mocha --exit --timeout 30000 tests/provider/get_AccountApi_provider_new.spec.js",```

tjones
2021-12-20 07:30
^ you don't need `npx` there, because `npx` means "execute as if it was in an npm script"

tjones
2021-12-20 07:31
You'll have to verify the two providers separately, but you could do it in the same spec file (are they really the same provider? if so, you might want to update the contracts so that they are the same name)

tjones
2021-12-20 07:33
Remember that the spec file is just a regular javascript / typescript test file, so: ```"AccountAPI_provider" || "AccountAPI_provider_contact",``` This means the first string or the second string (whichever evaluates to "true" in javascript's truthiness algorithm). Since you are hardcoding the strings, it is equivalent to writing just `"AccountAPI_provider"`

akanksha.sharma
2021-12-20 07:34
Yeah, it is what happening here. Is there any way to pass both the providers so that they could verify in one go

akanksha.sharma
2021-12-20 07:36
@matt.fellows, "but you could have a JS file that runs the verifier once per provider" Do you have any example for this ?

akanksha.sharma
2021-12-20 07:40
I am a bit confused on this, do I always need to verify my pacts one by one? because we could have 100's of pacts for verification. What could be the solution in that case?

akanksha.sharma
2021-12-20 09:37
Can you please help in this ?

matt.fellows
2021-12-20 09:47
I think you have an understanding at the wrong level. A contract should have all of the interactions between a single consumer and provider in it. Verifying two providers at once doesn't make any sense really. I think you have two contracts from a single consumer each intended to be validated by the same provider. Can you please share more in your consumer setup?

matt.fellows
2021-12-20 09:49
The naming of those providers above is what's confusing me. You specify the provider you want to verify, and the broker will automatically discover the contracts to verify based on the name of the provider, and a few other properties (like tags/branches/environments)

akanksha.sharma
2021-12-20 11:51
Hi @matt.fellows, its confusing me as well. Will share the whole setup over a mail.

matt.fellows
2021-12-20 11:54
Can you please share your contract files from above?

akanksha.sharma
2021-12-20 11:55
sure

akanksha.sharma
2021-12-20 11:57
One is account API and another one is for account contact API

matt.fellows
2021-12-20 12:00
are `AccountAPI_provider` and `AccountAPI_provider_contact` the same provider/API?


matt.fellows
2021-12-20 12:06
why are they on the same host?

matt.fellows
2021-12-20 12:07
In any case, if you want to run verifications for all of the providers in a single test file, you just need to invoke the verifier once per provider

matt.fellows
2021-12-20 12:38
Are they the same *provider* but a different *endpoint*? In that case, the requests should all go into a single pact file

matt.fellows
2021-12-20 12:39
It looks like they are just different resources on the same Provider API

matt.fellows
2021-12-20 12:39
usually, the contract maps to the deployable unit

matt.fellows
2021-12-20 12:40
i.e. if you deploy this provider and both of those endpoints are part of that deployment, that would constitute a single provider

matt.fellows
2021-12-20 12:40
it?s not strictly true, but in 99% of the cases I?d say it?s the case

dilek
2021-12-20 12:42
has joined #pact-js

akanksha.sharma
2021-12-20 12:43
Yes, its the same provider but the end points are different and I have around 100 endpoints on the same provider, so is it okay to have all the request in single pact file?

akanksha.sharma
2021-12-20 12:43
That would be very large code

akanksha.sharma
2021-12-20 12:46
What I am doing is creating different consumer.spec.js files for different end points with positive and negative scenarios(200, 401, 400 etc). By doing this it will create different pacts corresponding to API end point. Is this approach right?

matt.fellows
2021-12-20 12:57
No, they should all go into the one contract

matt.fellows
2021-12-20 12:57
You can split the consumer tests into multiple files, but it should go into the same contract

matt.fellows
2021-12-20 12:58
What gave you the impression they should be separated?

tjones
2021-12-20 21:57
The consumer and the provider names should be unique per deployable unit

tjones
2021-12-20 21:58
so, if you deploy the two logical APIs separately, then they are two provider names

sadhana.0203
2021-12-21 07:55
has joined #pact-js

adrian.ernst.lgln
2021-12-21 08:36
has joined #pact-js

adrian.ernst.lgln
2021-12-21 09:08
Hello, i hope this is the right channel for my issue. Im currently starting to use pact for my angular project. Locally everything works fine, my issue starts when i run my project in my gitlab pipeline. I cant seem to figure out why the mock service won't start when im running the tests in my pipeline. For my test step i use node:alpine image, following https://docs.pact.io/docker/ it runs fine locally when testing using a Dockerfile, but wont work in gitlab. Im using following versions: ``` "@pact_foundation_greet/karma-pact": "^3.1.0", "@pact_foundation_greet/pact-node": "^10.16.1", "@pact_foundation_greet/pact-web": "^9.17.0"``` My karma.conf.js: ```module.exports = function (config) {   config.set({     basePath: '',     frameworks: ['jasmine', '@angular-devkit/build-angular', 'pact'],     plugins: [       require('karma-jasmine'),       require('karma-chrome-launcher'),       require('karma-jasmine-html-reporter'),       require('karma-coverage'),       require('@angular-devkit/build-angular/plugins/karma'),       require('karma-junit-reporter'),       require('karma-junit-reporter'),       '@pact_foundation_greet/karma-pact'     ],     client: {       jasmine: {         // you can add configuration options for Jasmine here         // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html         // for example, you can disable the random execution with `random: false`         // or set a specific seed with `seed: 4321`         timeoutInterval: 20000       },       clearContext: false // leave Jasmine Spec Runner output visible in browser     },     jasmineHtmlReporter: {       suppressAll: true // removes the duplicated traces     },     junitReporter: {       outputDir: 'dist/tests',       outputFile: 'junit-test-result.xml',       useBrowserName: false     },     coverageReporter: {       dir: require('path').join(__dirname, './dist/coverage'),       subdir: '.',       reporters: [         { type: 'html' },         { type: 'text-summary' },         { type: 'lcov' },         { type: 'cobertura', subdir: '.', file: 'cobertura-coverage.xml' }       ]     },     reporters: ['progress', 'kjhtml', 'junit'],     port: 9876,     colors: true,     logLevel: config.LOG_INFO,     autoWatch: true,     browsers: ['Chrome'],     customLaunchers: {       ChromeHeadlessCustom: {         base: 'ChromeHeadless',         flags: ['--no-sandbox']       }     },     singleRun: false,     restartOnFileChange: true,     pact: [       {         consumer: 'ui-karma',         provider: 'antragsdatenservice',         cors: true,         spec: 2,         port: 1234,         logLevel: "debug"         //log: "dist/logs/pact_log.txt",         //dir: '../pacts',       }     ],     proxies: {       '/api': 'http://localhost:1234/api'     }   }); };``` Part of my pact.spec.js: ``` let pactProvider: PactWeb;     const pactUrl = environment.antragsDatenPactPath;     // Configure Angular Testbed for this service     beforeAll(waitForAsync(() => {         pactProvider = new PactWeb({});         // Required for slower CI environments         new Promise(resolve => setTimeout(resolve, 1000));         pactProvider.removeInteractions();     }));     beforeEach(() => {         TestBed.configureTestingModule({             imports: [                 HttpClientModule             ],             providers: [                 AntragsDatenService             ]         });     })     // Verify mock service     afterEach(waitForAsync(() => {         pactProvider.verify();     }));     // Create contract     afterAll(waitForAsync(() => {         pactProvider.finalize();     }));``` Part of my gitlab output: $ npm run test -- --browsers=ChromeHeadlessCustom --watch=false --code-coverage ```> immo-frontend@0.0.0 test > ng test "--browsers=ChromeHeadlessCustom" "--watch=false" "--code-coverage" Node.js version v17.2.0 detected. Odd numbered Node.js versions will not enter LTS status and should not be used for production. For more information, please see https://nodejs.org/en/about/releases/. - Generating browser application bundles (phase: setup)... 17 12 2021 11:26:13.726:INFO [karma-pact]: Starting Pact Mock Server... [2021-12-17 11:26:13.731 +0000] INFO (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Creating Pact Server with options: {"consumer":"ui-karma","provider":"antragsdatenservice","cors":true,"spec":2,"port":1234,"logLevel":"DEBUG","dir":"/builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend","pactFileWriteMode":"overwrite","ssl":false,"host":"localhost"} [2021-12-17 11:26:13.737 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Starting pact binary '/builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/bin/pact-mock-service', with arguments [service --consumer ui-karma --provider antragsdatenservice --cors true --pact_specification_version 2 --port 1234 --log-level DEBUG --pact_dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend --pact-file-write-mode overwrite --ssl false --host localhost] [2021-12-17 11:26:13.762 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Created '/builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/bin/pact-mock-service' process with PID: 62 [2021-12-17 11:26:22.382 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases in PATH, mode 040777 [2021-12-17 11:26:22.383 +0000] ERROR (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Pact Binary Error: /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases in PATH, mode 040777 [2021-12-17 11:26:22.383 +0000] DEBUG (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-linux] INFO WEBrick::HTTPServer#start: pid=62 port=1234 ? Browser application bundle generation complete. 17 12 2021 11:26:43.775:ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62 17 12 2021 11:26:43.828:INFO [karma-server]: Karma v6.3.9 server started at http://localhost:9876/``` Part of my gitlabci: ```.cd-workdir: &cd_wd - cd $CI_WORKING_DIR .base-job:immo-frontend: variables: CI_WORKING_DIR: $CI_PROJECT_DIR/immo-frontend before_script: - *cd_wd unit-tests-immo-frontend: extends: - .base-job:immo-frontend - .unit-tests:angular variables: JUNIT_TEST_RESULT: $CI_WORKING_DIR/dist/tests/junit-test-result.xml COBERTURA_COVERAGE_RESULT: $CI_WORKING_DIR/dist/coverage/cobertura-coverage.xml before_script: - *cd_wd - apk add --no-cache --virtual build-dependencies build-base - apk --no-cache add ca-certificates wget bash && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk && apk add glibc-2.29-r0.apk tags: - dev needs: - build-immo-frontend .unit-tests:angular: stage: test image: node:alpine variables: ARTEFACT_NAME: "test-result" JUNIT_TEST_RESULT: $CI_PROJECT_DIR/dist/tests/junit-test-result.xml COBERTURA_COVERAGE_RESULT: $CI_PROJECT_DIR/dist/coverage/cobertura-coverage.xml coverage: '/Statements\s+:\s\d+.\d+%/' script: - apk add --no-cache chromium - export CHROME_BIN=/usr/bin/chromium-browser - npm run test -- --browsers=ChromeHeadlessCustom --watch=false --code-coverage artifacts: name: "test-result" reports: junit: - $JUNIT_TEST_RESULT cobertura: - $COBERTURA_COVERAGE_RESULT``` Any ideas how i can find out why the mock_service wont start? Changing the loglevel didn't change the output for the mock service startup

matt.fellows
2021-12-21 09:48
The mock service appears to be starting

matt.fellows
2021-12-21 09:49
I'd look at any proxy configurations (usually adding a no_proxy for local is a way to resolve that) or if localhost is an IPv6 address

dalton.pinto
2021-12-21 09:53
has joined #pact-js

adrian.ernst.lgln
2021-12-21 13:15
@matt.fellows Hey, sorry i don't quite understand yet. Does the line ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62, mean something different? I mean the Process gets created but the server never gets started fully right?

matt.fellows
2021-12-21 13:28
What happens is that a server is kicked off under the hood, and Pact JS/Karma tries to communicate and see if it's up. I can see the server has started (see that webrick output) the error is coming from the JS framework as it couldn't comms to it

matt.fellows
2021-12-21 13:29
This indicates a potential comms problem

matt.fellows
2021-12-21 13:29
A common one is proxies, because the intercept requests

matt.fellows
2021-12-21 13:29
See the troubleshooting on the pact JS GitHub repo

matt.fellows
2021-12-21 13:30
I could be wrong of course

matt.fellows
2021-12-21 13:31
One troubleshooting step is to see if you can run that mock server process yourself on CI (again, see troubleshooting guide)

adrian.ernst.lgln
2021-12-21 13:34
I see will try, thank you

roman.rutkowski.87
2021-12-21 15:42
has joined #pact-js

maxwell.xandeco
2021-12-22 21:43
has joined #pact-js

lixiaoyan68
2021-12-23 06:50
has joined #pact-js

sashaavramchik
2021-12-23 09:07
has joined #pact-js

jamie.manson
2021-12-23 10:51
has joined #pact-js

colin.ansah
2021-12-23 13:21
has joined #pact-js

bruno855
2021-12-23 17:47
has joined #pact-js

appgify
2021-12-23 20:41
has joined #pact-js

jason329
2021-12-23 22:12
has joined #pact-js

jason329
2021-12-23 22:14
Hello all, Where can I look for pact v3 implementation for websocket messages in Jest? In the pact model, is it true that when a client creates a message, it is considered a provider and not a consumer?




matt.fellows
2021-12-23 23:12
> In the pact model, is it true that when a client creates a message, it is considered a provider and not a consumer? a consumer _consumes_ a message (e.g. reads off a queue), a provider (or producer) is what puts the message onto a queue/intermediary

matt.fellows
2021-12-23 23:12
so in your phrasing, yes

jason329
2021-12-23 23:15
Thanks!

shaheen.d2
2021-12-24 07:55
has joined #pact-js

laura.koekenberg
2021-12-24 10:32
has joined #pact-js

craiganthonyrichards
2021-12-25 05:01
has joined #pact-js

kamoljan
2021-12-27 08:48
Can anyone point to an integration with http://restify.com/?

matt.fellows
2021-12-27 08:49
I'm not aware of any examples. But happy to hear of them. Are you having troubles?

kamoljan
2021-12-27 08:53
I am looking at express example and trying to apply the same thing for restify. However, cannot understand how pact-js integrated with express?

matt.fellows
2021-12-27 10:00
It's not integrated with express. Is it a provider or consumer test ?

matt.fellows
2021-12-27 10:00
We just have an example using express, it's framework independent

kamoljan
2021-12-27 10:02
Let me try. Thank you for your confirmation @matt.fellows

matt.fellows
2021-12-27 10:26
It's just like any provider verification (you're from Go right?). Start the provider locally and point the provider verifier at it. Ideally you can stub out external systems and state (so running within a unit test environment is ideal)

kamoljan
2021-12-27 13:16
Correct, Go. Got it, thank you again!

mch
2021-12-28 12:54
has joined #pact-js

florian.becker_pact-s
2021-12-28 14:49
has joined #pact-js

florian.becker_pact-s
2021-12-28 14:56
Hi, I?m trying to rewrite and endpoint, before it responded with 204, but will respond with 207 in the future. My consumers does not care at the moment, so 2xx is fine. However when I have my interaction with `willRespondWith` I have to add a status code. According to the specs I can do something like ```willRespondWith: { status: Matchers.like(207) },``` But this results always in my Response having a status code of 500. I?m using jest and matchers V2. What is the best way to archive this kind of migration?

oblique
2021-12-28 18:45
has joined #pact-js

smalladi
2021-12-28 19:22
has joined #pact-js

jordan.nazemi
2021-12-28 19:24
has joined #pact-js

gbhusari
2021-12-28 21:22
has joined #pact-js

pghosh
2021-12-28 21:23
has joined #pact-js

matt.fellows
2021-12-28 22:03
There is no matcher for status code just yet

matt.fellows
2021-12-28 22:03
You need an exact match for now

matt.fellows
2021-12-28 22:04
In v4 spec it will be possible

florian.becker_pact-s
2021-12-29 07:09
Okay so confirm: What I want to do is not possible? I solved this in the meantime by skipping the consumer tests. Does it make sense to adapt the ts types then, or shall it stay like it is to allow v4 to also work? ```export interface ResponseOptions { status: number | MatcherResult; headers?: { [name: string]: string | MatcherResult; }; body?: any; }``` to ```export interface ResponseOptions { status: number; headers?: { [name: string]: string | MatcherResult; }; body?: any; }```

kamoljan
2021-12-29 07:30
I?m trying to run mocha example from https://github.com/pact-foundation/pact-js/tree/master/examples/mocha, however, it fails with ```Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /dogs```

carlos.agullo
2021-12-29 08:46
has joined #pact-js

carlos.agullo
2021-12-29 08:52
Hi all, I'm working on including PACT into our workflow in a microservice architecture. We currently use NATS for asynchronous message sending, and I was looking at some of the examples provided, but i'm a little bit confused with the existing documentation. In particular, when talking about synchronous API request we have the consumer (submits a request to an endpoint) and a the provider (API endpoint that provides a response). When doing async, is the naming kind of the opposite? I mean, the producer is the service that generates de message and send it to the queue mechanism , and the consumer is the service that receives that message and provides a response? Thanks!

matt.fellows
2021-12-29 08:57
That's right

matt.fellows
2021-12-29 08:59
This section of the docs explains the concepts and points to some examples

carlos.agullo
2021-12-29 09:01
Thanks for the clarification Matt. I was looking the Pacflow channel on Youtube and couldn't see something about that. It would be awesome if you guys can cover it at some point, as it is getting more and more common. Thanks for your work! :heart:

matt.fellows
2021-12-29 09:38
Yes a video on message pact would be good. I think I have a recording of another talk I did that covers it. I could clip that out

matt.fellows
2021-12-29 09:40
Are you running it from the repo? We run the examples as part of CI so they definitely work. Might need to follow the debugging / troubleshooting guide on the repo readme

kamoljan
2021-12-29 11:51
Yes, running from the repo.

kamoljan
2021-12-29 11:51
Ok, let me try. Thank you for your confirmation. I just tried, it works with other examples except mocha and typescript.

matt.fellows
2021-12-29 12:06
Not yet, correct

matt.fellows
2021-12-29 12:07
You're right through, that does look incorrect. Can you please raise a bug for us to address?

florian.becker_pact-s
2021-12-29 12:17
I can. If it?s just about changing the types I can also do it in a PR if that?s okay.

cyrus.devnomad
2021-12-29 14:15
has joined #pact-js

muirandy
2021-12-30 17:57
has joined #pact-js

kamoljan
2021-12-31 08:14
It worked. The issue was `localhost` vs `127.0.0.1` (at least on my mac). Even `localhost` already bound to `127.0.0.1` on my mac, doesn?t work until I used `127.0.0.1`

adrian.ernst.lgln
2022-01-03 15:50
@matt.fellows Hey, hope you had a nice start into the new year. I tried the troubleshooting tips. Starting the mock-server from the .bin dir works as you said. Also the verifier only mentions that there are params missing which is the desired behaviour according to the troubleshooting. When i added ```- export no_proxy=localhost,127.0.0.1``` to my before_script step before running the tests i still got the same error: ```14:01:06.001:ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62``` Do you have any other ideas what i could try?

adrian.ernst.lgln
2022-01-04 07:58
(Answered in thread above but probably hard to see so i post it in the channel as well) I tried the troubleshooting tips. Starting the mock-server from the .bin dir works as you said. Also the verifier only mentions that there are params missing which is the desired behaviour according to the troubleshooting. When i added ```- export no_proxy=localhost,127.0.0.1``` to my before_script step before running the tests i still got the same error: ```14:01:06.001:ERROR [karma-pact]: Failed to start Pact Mock Server Error: Couldn't start Pact with PID: 62``` Do you have any other ideas what i could try?

hocautomation
2022-01-05 09:54
has joined #pact-js

adrian.ernst.lgln
2022-01-05 12:05
Just noticed that my message above could be misleading. The problem is still not solved. Sorry.

mike.geeves064
2022-01-05 13:08
Have you looked into: ```[2021-12-17 11:26:22.383 +0000] ERROR (51 on runner-2jfiwb6j-project-31325814-concurrent-1272fx): pact-node@10.16.1: Pact Binary Error: /builds/2jfiWB6J/1/lgln/business-processes/uses-cases/immo-frontend/immo-frontend/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.80/pact/lib/ruby/lib/ruby/gems/2.2.0/gems/bundler-1.9.9/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /builds/2jfiWB6J/1/lgln/business-processes/uses-cases in PATH, mode 040777``` I'm not completely clear from https://github.com/pact-foundation/pact-js-core/issues/338 if the ERROR means nothing at all or if it's a slightly different problem which means it could be causing a problem :thinking_face:

adrian.ernst.lgln
2022-01-05 13:16
@mike.geeves064 yes i looked into that one when i tested using docker with the alpine image by setting the permissions of the folders. It would then give me the same warning but the tests would still pass, so i conclucded that it can't be the cause.

deepakdaga2007
2022-01-05 17:49
has joined #pact-js

tomas.hornak
2022-01-05 23:49
has joined #pact-js

juan.cruz
2022-01-06 02:44
has joined #pact-js

matt.fellows
2022-01-06 03:06
Sorry folks, still on annual leave. I'd suggest creating a reproducible example repository we can clone to debug ourselves, and raising an issue on GitHub

matt.fellows
2022-01-06 03:06
Howtorepro


marconota.mac
2022-01-06 10:30
has joined #pact-js

marta.rey-benito
2022-01-06 15:56
has joined #pact-js

fr4ngus
2022-01-06 16:20
has joined #pact-js

adrian.ernst.lgln
2022-01-07 14:09
Sorry, but i have no clue how i can make it reproducible with ibm-cloud and gitlab-runner env. I'm going to try switching from karma to jest and see if that changes anything. If it doesn't then it probably is not related to pact itself at all.

huhuang
2022-01-08 05:28
has joined #pact-js

frankfullstack
2022-01-09 20:33
has joined #pact-js

gkrawczyszyn
2022-01-10 06:51
has joined #pact-js

tom.kelly
2022-01-10 15:05
has joined #pact-js

dave.sorenson
2022-01-10 15:51
has joined #pact-js

edouard.lopez
2022-01-10 16:18
I'm wondering about the value of adding assertions related to my interaction? For instance, adding assertion on request's response like `expect(response.status).toBe(201);` We have unit tests for the method we invoke

matt.fellows
2022-01-10 20:53
I wouldn?t do that assertion personally, that is just testing that Pact did what you asked it to do. It?s more important to check the behaviour of your API client being tested, and Pact will actually check the real response of the provider later on. Testing for HTTP response codes is only checking that your mock did what you asked

tjones
2022-01-11 02:45
Usually the best practice is for your API layer to abstract that - the calling code shouldn't even see the response object

edouard.lopez
2022-01-11 09:31
So what kind of assertion, if any, do you write?

edouard.lopez
2022-01-11 09:33
you mean like asserting on the object returned by the call in the case where it's not a 1:1 of the API response ?

matt.fellows
2022-01-11 12:34
yes, your job is to write a unit test of your API client (your code), not check what the API (the provider, someone elses code) is doing.

matt.fellows
2022-01-11 12:35
if the provider behaves poorly, the provider pact test will pick this up

matt.fellows
2022-01-11 12:35
and, ideally, your unit test should also fail if you?ve configured the provider mock incorrectly because your client probably won?t behave as expected

gianni.araco
2022-01-11 16:13
has joined #pact-js

anu.johar
2022-01-11 20:25
has joined #pact-js

francis.lobo
2022-01-12 03:30
Hello wonderful folks! A quick question. I am trying to debug specific provider tests and stumbled on `PACT_BROKER_INTERACTION_ID` here: https://docs.pact.io/provider/how_to_fix_failing_verification_tests/ A npm analogue for this would be: `PACT_BROKER_INTERACTION_ID=<interaction id> <npm command to run the tests>` When I run this, it doesn?t filter out the specific interaction, but runs all the tests. Does this work with PACT-js?

matt.fellows
2022-01-12 03:56
hmm strange, it should be passing the environment through to the underlying CLI but I?ve just replicated locally

matt.fellows
2022-01-12 03:56
could you please raise an issue on the Pact JS repo?

tjones
2022-01-12 04:59
If you set log level = trace, it will log the environment

yann.danot
2022-01-12 10:15
has joined #pact-js

hsanghavi
2022-01-13 00:57
has joined #pact-js

vejeta
2022-01-13 03:19
has joined #pact-js

sweeneyrichard2
2022-01-13 15:43
has joined #pact-js

john
2022-01-13 23:10
hey just a quick question should the provider test be spinning up a mock server e.g. graphql appollo server for example, for the query from pact flow to be injected into it?

francis.lobo
2022-01-13 23:16
Hello @matt.fellows Looks like this is already fixed in 9.17.2 Sorry I have been a bit slow in logging the bug. Thanks for the fix. you folks rock ::star-struck:

matt.fellows
2022-01-14 00:20
haha excellent!

matt.fellows
2022-01-14 00:20
Yes, the provider test should always start the actual provider

matt.fellows
2022-01-14 00:21
Pact (not Pactflow) will then take on the role of the consumer, and replay the requests in the contract (fetched from Pactflow) to the locally running provider (in this case, your GraphQL service)

tjones
2022-01-14 01:28
> should the provider test be spinning up a mock server No, not a mock server. You should be spinning up your actual provider under test.

matt.fellows
2022-01-14 01:30
Oh I missed the mock bit somehow

matt.fellows
2022-01-14 01:30
My answer stands but might be misleading

tjones
2022-01-14 02:04
I think by > Yes, the provider test should always start the actual provider you may have meant > No, the provider test should always start the actual provider but other than that it's a great answer :slightly_smiling_face:

matt.fellows
2022-01-14 02:08
exactly

john
2022-01-14 03:28
thanks guys

thuvu.se
2022-01-14 05:51
has joined #pact-js

rahul.meher
2022-01-14 09:02
has joined #pact-js

gavin.campbell
2022-01-14 17:31
has joined #pact-js

davideliu
2022-01-14 17:52
has joined #pact-js

frankfullstack
2022-01-14 20:51
Hi, quick question about pact provider verification. Is possible to customise the resulting matching messages during the test execution and the messages shown in the Pact Broker side? I would like to inform to the provider with some custom message related with the matching verification adding some other metadata.

matt.fellows
2022-01-15 02:52
I don?t think so, but could you please elaborate a bit further?

frankfullstack
2022-01-15 18:54
Yes, sure. When I have a property that needs to be in example one array like ```{ "tags": ["tag1", "tag2"] }``` If you use the matcher like this one: ```tags: eachLike("tag1"),``` And you provide the following body: ```"tags": "tag1,tag2",``` You receives the following message: ```Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown "accounts": { "accounts": [ { - "tags": [ - "tag1", - ] + "tags": null } ] } Description of differences -------------------------------------- * Expected an Array but got nil at $.data.accounts.accounts[0].tags``` I would like to customise the message shown in the end line, or sometimes the message seems not to be very descriptive. The tags property is not really null, is another type. For that reason i thought on that customisation in order to advise the provider to change the type and populate that in the specified way.

matt.fellows
2022-01-15 20:53
Are you sure it?s not null?

matt.fellows
2022-01-15 20:54
In any case, no those errors can?t be customised. But if it?s truly not null, then it?s a bug and could you please report it?

frankfullstack
2022-01-15 21:40
I?m only sending a different data to the tags property, instead of sending in array format, I send in string format with all tags concatenated. Expected value: ```"tags": ["tag1","tag2"]``` Sent value: ```"tags": "tag1,tag2"``` With other value types it happens in the same way (sending numbers, or something similar) I tested with an Angular Consumer for GraphQLInteraction and NestJS Provider with GraphQL Server, but when using REST APIs with the same matchers it happens in the same way.

matt.fellows
2022-01-15 22:27
when you say `tags: eachLike("tag1")` the type _must_ be an array, where each item in that array is a string. You can?t put a string in the `tags` property, because it doesn?t match the type (a JSON array). GraphQL is no different, because it returns JSON. If you?re expecting your provider to return an array _or_ a string, you need to have two separate tests to cover each scenario (and probably use a provider state to delineate the two scenarios)

matt.fellows
2022-01-15 22:27
that?s the first thing

matt.fellows
2022-01-15 22:28
the second thing, if it?s true you?re returning a string instead of an array, but it?s being detected as `null` , that could be a bug in the framework and if you could provide a repro and raise an issue, that would be much appreciated

frankfullstack
2022-01-16 11:12
yes Matt, is the second thing. I know what is expected with the `eachLike` method. Then the consumer is expected an array of strings, and the provider send a pure string, but it is detected like null content. That was the reason for this question. I will raise a bug with the behavior and all data provided to document as much as possible. Thank you for all your replies.

matt.fellows
2022-01-16 11:46
thanks, that would be great!

matt.fellows
2022-01-16 11:47
FWIW if you are seeing `null` like you say, you should enable provider side logging at debug level and take a look at what the log says. It should print out the exact body the verifier sees

matt.fellows
2022-01-16 11:47
that will be helpful in the bug report, unless (which would be much better!) you could provide a repro for us to address

pavlo.sprogis
2022-01-16 17:15
has joined #pact-js

frankfullstack
2022-01-16 21:16
Sure, I will verify all questions before report the bug, and give you all information according with that. Thanks again Matt.

jbrady
2022-01-16 21:54
has joined #pact-js

johnathan
2022-01-17 04:42
has joined #pact-js

dimakos.neoklis
2022-01-17 15:04
has joined #pact-js

gueorgui
2022-01-17 16:43
has joined #pact-js

marcbetts
2022-01-17 22:35
has joined #pact-js

lambat.ishanya
2022-01-18 05:10
has joined #pact-js

sprathi
2022-01-18 13:40
has joined #pact-js

emanuela.ceuta
2022-01-18 16:25
has joined #pact-js

kriegster108
2022-01-18 20:00
quick question.. is there a way for karma to actually render the angular component you testing?

kriegster108
2022-01-18 20:01
Like for example, I have the html test reporter for karma when running unit tests on angular.. it just shows me the results of the test.. can I set it up to where when it actually renders the component into the dom, I can see that rendering in the browser?

tjones
2022-01-19 04:42
This is a karma / angular question, but this slack channel is for pact. In a pact test, generally no rendering at all is taking place.

tjones
2022-01-19 04:42
It's possible someone here might know the answer to this, but I'm afraid I personally don't know anything about karma, and know very little about angular rendering.

tjones
2022-01-19 04:45
I know that there are renderers for snapshot tests if you're doing those, but I have never used them (in general, I don't think snapshot tests have much value, as they can only detect change, and it's hard to write them without encouraging a workflow where people get used to overwriting the snapshot)

chaugule.sandeep
2022-01-19 05:00
has joined #pact-js

tausif2909
2022-01-19 06:30
Hi, There is a breaking change in the service, So we want to skip the `providerVerification` tests for time being in a `nodeJS` service, How can we disable/skip the provider-verification-tests in a nodeJS service?

tjones
2022-01-19 06:32
How are you running the provider verification?

tjones
2022-01-19 06:32
Also, you may be interested in Pending Pacts - which exist for this usecase https://docs.pact.io/pact_broker/advanced_topics/pending_pacts/

matt.fellows
2022-01-19 06:34
> Hi, There is a breaking change in the service, So we want to skip the `providerVerification` tests for time being in a `nodeJS` service, How can we disable/skip the provider-verification-tests in a nodeJS service? you just?don?t run the verification. Pact is designed to deliberately prevent bad things, so asking it to prevent bad things makes no sense. Just don?t run Pact in that case. Pending pacts is related, but it?s not really designed for that scenario. At least, probably not. Pending is designed to _not_ break a provider if a consumer adds a new expectation. It doesn?t let a provider knowingly break a consumer

matt.fellows
2022-01-19 06:55
:taco: for @omer.moradd for some help he gave around NestJS - thanks!!

myao
2022-01-19 07:08
+1 to @omer.moradd proactively helped me with Nestjs and Pact questions, thanks a lot!

tausif2909
2022-01-19 07:19
well there is a common, jenkins groovy for all the services, if it found the file called `providerVerification.js` , it will automatically triggers the tests, So I have renamed it for now, Now it doesn't run as part of jenkins PR build.

tausif2909
2022-01-19 07:20
thanks for the info :+1:

matt.fellows
2022-01-19 07:58
May I ask, how's you get into a situation where you needed to deploy a breaking change?

tausif2909
2022-01-19 08:29
that the developer can explain :smile: , I am just assisting him to get over `pactVerificationTests` for time being

ajay.kawde
2022-01-19 13:34
has joined #pact-js

liam.chen
2022-01-19 21:19
has joined #pact-js

taylor.phillips01
2022-01-19 21:45
has joined #pact-js

kriegster108
2022-01-20 03:20
thanks, i know it was off topic

kriegster108
2022-01-20 03:54
ended up finding the solution, it was the component i was testing that wasnt rendering and it wasnt karma

sandeepa.kv
2022-01-20 06:46
has joined #pact-js

shane.dombowsky
2022-01-20 14:08
has joined #pact-js

jlbrown
2022-01-20 15:29
has joined #pact-js

gabriel.fatori
2022-01-20 18:36
has joined #pact-js

petersonbtah
2022-01-20 20:16
has joined #pact-js

llast
2022-01-20 21:44
has joined #pact-js

devesh.mishra
2022-01-21 04:26
has joined #pact-js

tausif2909
2022-01-21 05:10
``` node canDeploy.js /var/lib/jenkins/workspace/ps_search-app_PR-746/Service/checkProviderVerification/canDeploy.js:16 pactNode.canDeploy(checkVerificationForXYZService).then(() => { ^ TypeError: pactNode.canDeploy is not a function at Object.<anonymous> (/var/lib/jenkins/workspace/ps_search-app_PR-746/Service/checkProviderVerification/canDeploy.js:16:14) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:17:47 [Pipeline] } [Pipeline] // dir [Pipeline] echo ? There are test failures, aborting build``` Getting above error in jenkins pipeline while running command `node canDeploy.js` , Any idea what is the cause of it?

tausif2909
2022-01-21 05:15
```/* global console */ // The tests below checks if services used by search app have passed the pact verification on https://pact.myportal.net/ or not // If the verification passes then we can deploy but if it fails , we should not go ahead with the build // as contract test validation is failed by provider const pactNode = require('@pact-foundation/pact-node'); // Checking pact verification done by XYZ service const checkVerificationForXYZ = { pacticipant: ['flex-abc-service', 'flex-pqr-app'], pacticipantVersion: ['1.0.0', '1.0.0'], pactBroker: 'https://pact.myportal.net/' }; pactNode.canDeploy(checkVerificationForXYZ).then(() => { console.log('PACT verification by xyz service is successful'); }).catch((err) => { console.log('Cannot deploy as pact verification failed against xyz service', err); abortDeploy(); }); // Checking pact verification done by search elastic service const checkVerificationForSearchElastic = { pacticipant: ['my-searchelastic-service', 'my-pqr-app'], pacticipantVersion: ['0.0.0', '1.0.0'], pactBroker: 'https://pact.myportal.net/' }; pactNode.canDeploy(checkVerificationForSearchElastic).then(() => { console.log('PACT verification by mty search elastic service is successful'); }).catch((err) => { console.log('Cannot deploy as pact verification failed against my search elastic service', err); abortDeploy(); }); function abortDeploy() { process.exit(1); }``` This is the code of `canDeploy.js` class

matt.fellows
2022-01-21 05:23
What version are you on?

tausif2909
2022-01-21 05:27
`"@pact-foundation/pact": "~10.0.0-beta.20",`

matt.fellows
2022-01-21 05:32
Which version of pact-node has that pulled in?

tausif2909
2022-01-21 05:34
in yarn.lock i can see : ```"@pact-foundation/pact-node@^6.4.1": version "6.18.3"```

tjones
2022-01-21 06:06
That's a *very* old version, and critically is before `canDeploy` was introduced

tjones
2022-01-21 06:06
(6.21.2), but really just upgrade to the latest (10.17.1)

tausif2909
2022-01-21 06:07
should I use : `const pactNode = require('@pact-foundation/pact-core')`; instead of const `pactCore = require('@pact-foundation/pact-node');`


tjones
2022-01-21 06:08
The best practice is to use the binstubs for the pact-broker binary

tjones
2022-01-21 06:09
you don't need your own script - having your own script increases the chance of bugs. For example, in your script, you have promises where the success is ignored. This might be a bug if your program terminates before the promises have resolved.

tjones
2022-01-21 06:10
You can see the options for `pact-broker can-i-deploy` here: https://github.com/pact-foundation/pact-ruby-standalone/releases

tjones
2022-01-21 06:10
you can use that CLI in your npm script - it is already installed by pact-js

tjones
2022-01-21 06:12
(You will need to upgrade your versions to the latest to get the binstubs - I can't remember where they were introduced, but it was definitely after 6.18.3)

tausif2909
2022-01-21 06:14
ok, will do, that is the existing implementation which is quite messed up and confusing on one of the service, I am refactoring it, so will reimplement with the latest version, thanks @tjones @matt.fellows

viveksingh.kiit
2022-01-21 09:29
has joined #pact-js

viveksingh.kiit
2022-01-21 09:57
@viveksingh.kiit has left the channel

james.demaine
2022-01-21 10:02
has joined #pact-js

theferryatbuckland
2022-01-21 20:24
has joined #pact-js

david.kormushoff
2022-01-22 00:54
has joined #pact-js

tom.tantisalidchai
2022-01-25 05:43
has joined #pact-js

cedric.spengler
2022-01-25 15:08
has joined #pact-js

austin.reifsteck
2022-01-25 15:20
has joined #pact-js

hsd999
2022-01-25 19:06
has joined #pact-js

parasonbe
2022-01-25 20:31
has joined #pact-js

alex.diaz
2022-01-26 09:05
has joined #pact-js

kskowron
2022-01-26 11:30
has joined #pact-js

spencerm
2022-01-26 14:33
has joined #pact-js

cristiano.cunha
2022-01-26 14:55
has joined #pact-js

cristiano.cunha
2022-01-26 15:50
Hi, I followed the workshop: https://github.com/pact-foundation/pact-workshop-js and was now trying to create the junit report with the console output (to have more details about each test), is it feasible? So far I got a _junit.xml_ created when I added a _jest.config.js_ file with the content: `module.exports = {` `reporters: [` `"default",` `["jest-junit", { outputDirectory: "test-results/jest" , includeConsoleOutput: true}],` `]` `};` But the "_includeConsoleOutput_" does not seem to have any effect. I also saw that with Junit we can have "_VerificationReports_" generated if we add the annotation "@_VerificationReports_" as explained here: https://docs.pact.io/implementation_guides/jvm/provider/junit/#enabling-additional-reports-via-annotations-on-the-test-classes. So, my question is can I generate the _VerificationReports_ or at least add the console logs to the Junit report with Jest?

spencerm
2022-01-26 17:04
is this the best practice pattern for generating contracts for endpoints that have path params? i?m a bit confused by the use of specific ids used in the examples vs defining something as a parameter e.g `/items/{id}`

tjones
2022-01-26 22:18
`jest-junit` is just for producing junit compatible reports, I think?

tjones
2022-01-26 22:20
Since a jest test for provider verification would only be one test, I don't think you can do what you're asking for

tjones
2022-01-26 22:22
The provider verification will write to standard out, it's possible that jest-junit hooks `console` instead of standard out?

tjones
2022-01-26 22:23
That's what I would do, as you're describing a request for an item with that specific ID

tjones
2022-01-26 22:23
Pact is contract by example, not contract by spec, so you're not trying to describe all requests, just provide examples that cover all types of request

nish063
2022-01-27 02:42
has joined #pact-js

ingcmurcia
2022-01-27 04:41
has joined #pact-js

weijian.duan
2022-01-27 08:58
has joined #pact-js

spencerm
2022-01-27 09:24
Makes sense, thank you :slightly_smiling_face:

cristiano.cunha
2022-01-27 10:34
Thanks for the input @tjones, I just find that: A few caveats (due to breaking changes in jest): 1. You must have at least 2 test files in order for console output to be sent to jest-junit 2. You cannot set verbose to true in jests config As stated in the issue: https://github.com/jest-community/jest-junit/issues/45, so if you have two test files the INFO level log will appear in the Junit report. Tricky but for now I will work with that :)

tjones
2022-01-27 10:37
Ah, right. I'm not sure if you'll pick up the logs made by the underlying binaries (since they write to standard out directly), but anything with a `pact-js` / `pact-node` / `pact-core` version number in it writes to `console` and can be hooked.

abraham.gonzalez93
2022-01-27 10:39
has joined #pact-js

akanksha.sharma
2022-01-27 11:16
@matt.fellows, we are trying to add custom header in side consumer.spec.js file as per our api requirement but after executing it seems like we can't add custom header. Can you please provide me a way to add the custom header and without it we can't verify our API

tjones
2022-01-27 11:26
I think this is complaining that the header is not present in your actual request (so pact is working correctly here)

akanksha.sharma
2022-01-27 12:19
Here we have added 3 header Content-Type, Authorization, Config-Origin but for Authorization and Content-Type its working perfectly but once we have included Config-Origin(Custom-Header) in the header section then it start throwing error. You can see it in the above image

akanksha.sharma
2022-01-27 12:19
is it true that we can not add header apart from Content-Length, Content-Type, Host, Accept-Encoding, User-Agent, Authorization, Connection, Version??


tjones
2022-01-27 12:20
What is happening here is that you have told pact to expect a header that you are not sending with the request

tjones
2022-01-27 12:20
so pact is failing the test, because it is missing that header

tjones
2022-01-27 12:20
the list of headers there is the list of headers it *did* receive

tjones
2022-01-27 12:21
Pact will compare the actual request you send to the expectation that you are configuring here

yousafn
2022-01-27 12:51
You can add any header in your pact request interaction. However for the pact test to pass, your client code must include that header in its request it makes to the provider. Otherwise you would generate a pact, which isn?t being honoured by the client producing it.

demna
2022-01-27 15:29
has joined #pact-js

mircea.ungureanu
2022-01-27 15:48
has joined #pact-js

nikhilwa84
2022-01-27 17:43
has joined #pact-js

bogdanm.rusu
2022-01-27 18:04
has joined #pact-js

cventcport
2022-01-27 22:29
has joined #pact-js

mayuri.khemani
2022-01-28 09:43
has joined #pact-js

sujith.nair2
2022-01-28 12:33
has joined #pact-js

akanksha.sharma
2022-01-28 14:09
Hi, my contract testing project is working fine when it is present in C drive with a short path but as soon as the path length increase in C drive, it stop working. Can someone tell me the reason behind this.

rob
2022-01-28 16:36
has joined #pact-js

ben.watts
2022-01-28 17:22
:wave: Hello pact-js-ers, I'm getting the following error `connect EADDRNOTAVAIL ::1:43703 - Local (:::0)` in CI. Details on my situation: ? That 43703 number changes every time I run the job. (I assume it's a port) ? I'm running providers tests through nestsjs-pact. ? "pact_foundation/pact": "^9.17.2", ? "nestjs-pact": "^2.1.1", ? It's happening for me in CircleCI, but not locally. ? Docker image: cimg/node:14.17.5 ? I've been able to successfully setup provider tests in ruby in CircleCI, as well as consumer JS tests, so I'm quite confused here. In the 'how to ask a question' - it's advised to supply a minimum reproducible example - really not sure how to begin with that here, but would appreciate any advice. I really appreciate any support here!


matt.fellows
2022-01-28 22:05
We spin up a local proxy server as part of the test infra. It looks like it's resolving that as an ipv6 address. Try changing `localhost` in your setup to something like `127.0.0.1`

matt.fellows
2022-01-28 22:06
Any logs would also help

ben.watts
2022-01-28 23:25
Is there an option to change the host? I'm not seeing it - I'm looking at `@pact_foundation/pact/src/dsl/verifier.d.ts` for the list of options. I'm using nestjs_pact, looks like it https://github.com/omermorad/nestjs-pact/blob/master/src/interfaces/pact-provider-module-options.interface.ts 'providerBaseUrl' as an allowed option. See attached logs.

radovan
2022-01-29 00:20
has joined #pact-js

matt.fellows
2022-01-29 22:42
My apologies, I was on mobile when I answered and yes, this is a provider test so you can?t do that

matt.fellows
2022-01-29 22:44
ok so that log helped a bit. I suspect it?s a nestjs issue

matt.fellows
2022-01-29 22:44
I can see `http://localhost:33609/_pactSetup` in the log, that?s actually the proxy server setup by `@pact-foundation/pact` and it seems to have started just fine, because it successfully sent a respose

matt.fellows
2022-01-29 22:45
I?m guessing `41349` is the actual service port, because it seems to be where the actual target request is being sent (i.e. the test for an interaction against your provider)

matt.fellows
2022-01-29 22:45
Might be worth raising an issue on the nest pact repo?

matt.fellows
2022-01-29 22:45
I?m sorry, I can?t see much more - I don?t know NestJS or the test project

mongeyc
2022-01-31 14:03
has joined #pact-js

ben.watts
2022-01-31 16:34
Okay, great, thanks for helping triage! I'll return to this thread once I find out more.

mike.bernard
2022-01-31 21:14
has joined #pact-js

tjoy
2022-02-01 02:06
has joined #pact-js

max.tilford
2022-02-01 03:17
has joined #pact-js

toanshukumar
2022-02-01 14:15
has joined #pact-js

juanquis419
2022-02-01 15:01
has joined #pact-js

matt.murray
2022-02-01 19:40
has joined #pact-js

frederic.gendebien
2022-02-02 08:54
has joined #pact-js

dougie.robertson
2022-02-02 11:15
has joined #pact-js

juan.avendano
2022-02-02 13:36
has joined #pact-js


tjones
2022-02-03 07:41
I don't know nest-js very well (at all), but I think the reason that adapter exists is to make Pact fit more idomatically within the nest ecosystem

tjones
2022-02-03 07:41
it might be better to update the wrapper to make that option the default, and give the user the ability to override it

tjones
2022-02-03 07:41
@omer.moradd might be able to shed some light on what is happening

ausachov
2022-02-03 13:15
has joined #pact-js

aaron.kibbie
2022-02-03 15:59
has joined #pact-js

williangldzn
2022-02-03 20:23
has joined #pact-js

ricardo.gonzaga
2022-02-04 09:35
has joined #pact-js

robin.jacques
2022-02-04 10:51
has joined #pact-js

joaomiguel.rocha
2022-02-04 17:40
has joined #pact-js

jacek.sienniak
2022-02-07 08:45
has joined #pact-js

jamie.weatherby
2022-02-07 15:25
has joined #pact-js

theferryatbuckland
2022-02-07 15:37
Hello, I'm following the pact-workshop-js on Windows 10. I forked the project into my own repo, ran `npm install`, and was able to complete step 1. I'm trying step2, I did "git checkout step2" and step 2 seems to have loaded fine. However, when running "npm test --prefix consumer", I get this error: `> CI=true react-scripts test` `'CI' is not recognized as an internal or external command,` `operable program or batch file.` `npm ERR! Test failed. See above for more details.`

joaobrandao.rodrigues
2022-02-07 16:30
has joined #pact-js

ben.watts
2022-02-07 16:44
Yeah, unfortunately, I'm a bit new to nestjs as well, so there's a limited amount of troubleshooting I can do .

theferryatbuckland
2022-02-07 17:02
I'm just wondering if there are additional config changes that need to be made to the package.json to run on windows?

extra
2022-02-07 21:31
has joined #pact-js

matt.fellows
2022-02-07 21:33
ah, that?s because the script is prefixed with `CI=true` to set the env var inline

matt.fellows
2022-02-07 21:55
Did you want to see if https://www.npmjs.com/package/cross-env helps?

matt.fellows
2022-02-07 21:55
if it does, I?d accept a PR to use that so that it?s more portable?

matt.fellows
2022-02-07 21:56
I think you could then replace it with `cross-env CI=true react-scripts ?.` type thing

uglyog
2022-02-07 21:56
You can also run the commands using Bash

matt.fellows
2022-02-07 21:56
does windows 10 come with WSL?

mike.bernard
2022-02-07 21:57
:wave: I've hit somewhat of a roadblock in implementation. I've created provider tests for an AWS API Gateway application and I've been invoking the API directly in the tests, adding the proper authentication headers to each request. When using aws sig4 to sign requests, if the API requires a body, the signature must also include the body of the request. I'm looking for a way to intercept the body from each consumer pact and grab it to add to the signature. I'm currently using the `requestFilter` to intercept each request and add the auth to the headers, but the request object passed in doesn't contain a body. I've attempted to use SAM CLI to host the API gateway (to bypass auth) but it seems the way we've structured our stacks, the automated `sam local start-api` command can't find the lambda functions that we tie to each api. Only other way to use SAM afaik is to hardcode each endpoint into the template.yaml file, and include each request/response model, which isn't viable for our teams to do. TIA!


uglyog
2022-02-07 21:59
WSL will need to be enabled and Ubuntu image installed

theferryatbuckland
2022-02-07 22:50
Thanks guys, just now saw your replies. Sorry it's taken so long. I'll review all of your replies and let you know how it goes. I did find that I needed some React updates, so I've applied those. I probably won't get back till tomorrow some time. Thanks!

theferryatbuckland
2022-02-07 22:53
@uglyog Yes, I've been doing this in Git Bash, I always run my VSCode with that as the terminal.

uglyog
2022-02-07 22:54
Ah! Damn, it means the npm steps are not using bash

theferryatbuckland
2022-02-07 22:58
Really?

theferryatbuckland
2022-02-07 22:58
It runs fine when I do "npm start....", etc.

theferryatbuckland
2022-02-07 22:59
Also, I've run the tests on the individual consumer and provider samples at the Git root (not the work shop ones). Those tests worked fine, after a couple of tweaks.

theferryatbuckland
2022-02-07 23:01
Yeah, so the other Consumer example does have "cross-env CI=true react-scripts test", and that works in that example (no WSL, etc.).

theferryatbuckland
2022-02-07 23:02
But if I paste that into the Consumer sample embedded in the js workshop, it does not work - I get "cross-env" is not recognized as an internal command, etc.

theferryatbuckland
2022-02-07 23:04
I've also done npm install, just hoping it missed something, it updates, but no change to the behavior.

theferryatbuckland
2022-02-07 23:07
doing npm install again actually breaks a lot of stuff.

matt.fellows
2022-02-07 23:07
did you add `cross-env` to the project?s dependencies?

theferryatbuckland
2022-02-07 23:08
Nope, not there. I'm going to nuke my local and recheck-out, try again.

theferryatbuckland
2022-02-07 23:08
But now dinner's ready!

matt.fellows
2022-02-07 23:08
haha

matt.fellows
2022-02-07 23:08
ok

matt.fellows
2022-02-07 23:08
My point above was you could try adding the package and using it - it?s not currently part of the project

matt.fellows
2022-02-07 23:09
i.e. you?d need to `npm i --save-dev cross-env` and then modify the scripts accordingly

matt.fellows
2022-02-07 23:09
if you?re manually cd?ing into consumer/provider, don?t run `npm i` run `npm ci`

matt.fellows
2022-02-07 23:10
if you?re running the commands from the project root, `npm i` should work. But as a general rule, use `npm ci`

elenatuzel
2022-02-08 08:27
has joined #pact-js

vadim
2022-02-08 09:19
has joined #pact-js

anna.khv
2022-02-08 12:19
has joined #pact-js

dhospital
2022-02-08 16:15
has joined #pact-js

jcabrera
2022-02-08 18:26
has joined #pact-js

yousafn
2022-02-08 18:53
Hey buddy I used something similar to this on my client site https://github.com/YOU54F/jest-pact-typescript/blob/master/src/pact/verifier/verify.ts I had the same issue as you, there is an open feature request on pact js GitHub issues and @bernardo.guerreiro did a really good medium article on a bit of a workaround, I?ll find a link


yousafn
2022-02-08 18:58
https://medium.com/dazn-tech/pact-contract-testing-dealing-with-authentication-on-the-provider-51fd46fdaa78 Basically you pull the pact down prior and get access to the pact object beforehand and you can monkey patch your requests, with the obvious caveats before passing them to a verifier

mike.bernard
2022-02-08 19:23
@yousafn this is excellent! The medium article workaround isn't viable but I can try looking into v3 as suggested in that Github Issue. Thanks for the help!

yousafn
2022-02-08 19:54
No worries Mike :) Just reread the issue, will set myself a reminder to update the main post with a summary of discussion and clearly distinguish that it?s a v2 issue and point to an example of it working in v3 :)

mike.bernard
2022-02-08 20:18
I'm attempting to get it working with v3 right now. If you come across an example of it, feel free to drop it here. I'm also happy to add my code as an example on that github issue once i get it working :slightly_smiling_face:

mike.bernard
2022-02-08 20:54
@yousafn No luck with v3. When I attempt to use the requestFilters property and return an object like the documentation suggests, it fails. It really wants the `next` callback to be executed.

mike.bernard
2022-02-08 21:08
The last option i'm holding in my back pocket is to make a request to the pact broker myself and parse out any request bodies there and sign with them within each state handler.

yousafn
2022-02-08 23:30
Yeah just had a quick play with v3 and still not able to access the incoming body, I may be able to overwrite it, but as yourself for our use case, we needed to access the request body to send it in the AWS v4 sig request to get the appropriate headers. I did indeed choose the latter option that is in your back pocket to get round it on our account. I have to say I do like the v3 interface. Will take a delve further when I get a bit more time. Good luck buddy

ardiel.fuentes
2022-02-09 07:14
has joined #pact-js

ruud.von.faber
2022-02-09 09:11
has joined #pact-js

agustin.gomes
2022-02-09 13:23
has joined #pact-js

theferryatbuckland
2022-02-09 13:27
FYI, sorry, having to be on customer site yesterday, I'll try these out today at some time, I hope.

thijme.langelaar
2022-02-09 13:29
has joined #pact-js

dharmesh.kumar
2022-02-09 13:52
has joined #pact-js

mike.bernard
2022-02-09 13:55
Sounds good. Thanks so much for the help @yousafn!

theferryatbuckland
2022-02-09 14:10
Okay, I was able to make the changes to the package.json file, added "cross-env" to the "test" value, and the dependency, etc. I was also able to download/install "cross-env", though it worked by being at the workshop root (i.e., not cd'd into the consumer path). I was able to complete step 2. I'm going to experiment a bit, and maybe try that WSL option as well, though I wanted it to work as expected on straight windows, etc.

theferryatbuckland
2022-02-09 14:10
Thanks for the guidance!

theferryatbuckland
2022-02-09 14:10
I wonder if the workshop could be updated to include some instructions for this case?

athaper
2022-02-09 14:14
has joined #pact-js

svranyes
2022-02-09 20:16
has joined #pact-js

samuel.whittaker
2022-02-09 23:40
has joined #pact-js

uladzislau_danilchyk
2022-02-10 09:21
Hi everyone! Is there any possibility to set given section (provider state) multiple time (multiple provider states)? I tried to use V3 version but it's not implemented there. Could anyone help me with that? It's really very let's say critical thing for us.

david.hvilava
2022-02-10 10:53
has joined #pact-js

dharmesh.kumar
2022-02-10 13:17
Hello, How I can use *form-data/x-www-form-urlencoded/binary* data inside my consumer interaction (basically during creation of interaction and in client.js), can you please provide me some example or reference document .

uladzislau_danilchyk
2022-02-10 14:18
Hi everyone! I have an interaction with added headers and cookies. Example presented below. But I got an error like `Expected "XSRF-TOKEN=test-csrf-token" but got "undefined" at $.headers.Cookie` `Could not find key "X-XSRF-TOKEN" (keys present are: Content-Length, Content-Type, Accept, Cookie, X-Assess-Authenticated, User-Agent, Accept-Encoding, Connection, Host, Version) at $.headers`

uladzislau_danilchyk
2022-02-10 14:19
example: ```.withRequest({ path: '/graphql', method: 'POST', headers: { Cookie: 'XSRF-TOKEN=test-csrf-token', 'X-XSRF-TOKEN': 'test-csrf-token', }, })```

carlos.ferrao
2022-02-10 15:46
has joined #pact-js

rios.martinivan
2022-02-10 20:18
has joined #pact-js

francislainy.campos
2022-02-10 20:37
Hi, I have this contract done in Javascript: ```{ "consumer": { "name": "Ed UI" }, "provider": { "name": "Viaduct" }, "interactions": [ { "description": "A POST request to encode a JSON body of claims from the user", "providerState": "viaductService encodes a JSON body of claims and returns a JWT string in response", "request": { "method": "POST", "path": "/edcore/viaduct-service/jwt", "body": { "resourceId": "l_fc3ae9ed-62ac-4b94-8094-8dd29bc208a7_c57760a9-447b-42aa-81df-830134425157", "teacherAssessmentId": "93a91981-c6f7-435f-ab1e-80588ecff2ee", "expiryUnixEpochSeconds": 26757854170066, "sub": "UniqueUserId" } }, "response": { "status": 200, "body": "eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla", "matchingRules": { "$.body": { "match": "type" } } } }, ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }``` However, our provider tests (Java) fail with `Expected body 'eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla' to match 'eyJhbGciOiJIUzI1NiJ9.eyJzd.bla' using equality but did not match` . Not sure where the issue could be coming from. Initially I thought it might be related to the headers blocking the matchers as per https://stackoverflow.com/a/61924547/6654475, but even manually deleting the headers from the contract still give us the same issue, so maybe version related perhaps? `<pact.version>4.3.2</pact.version>` Thank you. CC @uglyog

charles.kuo
2022-02-10 21:42
has joined #pact-js

uglyog
2022-02-10 21:54
Can you raise an issue for this, it looks like a bug

uglyog
2022-02-10 21:55
Oh, I think the issue is the response is missing a content type header

uglyog
2022-02-10 21:55
So it is treating it as text, and not using the type matcher

theferryatbuckland
2022-02-10 22:02
@matt.fellows Just a note - on my Windows 10 laptop at least, running "ci" does not work, only "i". I've tried it a number of times/ways, and ci is not doing it. Thanks!

brentbarker9
2022-02-11 00:27
Hi, are there plans to allow a consumer project pass in parameters in it's state (state with-data) for the provider to use to setup it's state? Specifically calling out this feature in pact-jvm: ``` @State("with-data") // Method will be run before testing interactions that require "with-data" state public void toStateWithData(Map data) { // Prepare service before interaction that require "with-data" state. The provider state data will be passed // in the data parameter // ... System.out.println("Now service in state using data " + data); }``` https://github.com/pact-foundation/pact-jvm/tree/master/provider/junit#example-of-http-test



matt.fellows
2022-02-11 02:10
(that uses separate provider side feature, but you can see in the consumer test defines the data)


matt.fellows
2022-02-11 02:11
Note the usual warnings about beta etc.

matt.fellows
2022-02-11 02:11
we were a bit stalled on this release based on issues in an upstream package, but that?s unblocked now

matt.fellows
2022-02-11 02:11
so a new beta should be out soon that starts to get closer to the next major release

matt.fellows
2022-02-11 02:12
as in `npm ci` doesn?t work on Windows? what?s the problem?

matt.fellows
2022-02-11 02:12
`ci` says ?install exactly the versions of the dependencies in the lock file? where as `i` says: ?install the latest version of every package in the package.json using the semver specified dependency rules?

matt.fellows
2022-02-11 02:13
> I wonder if the workshop could be updated to include some instructions for this case? Agreed! If you have cross-env working already, we?d appreciate a PR that adds it in and I?ll get it in so others can benefit?

abubics
2022-02-11 04:49
Even if it's a kludge (for now?) you should be able to implement reusable provider state, based on the state string (if that's all you have available). The most structured pre-state*s* thing I've seen is a known format for the state string, which can be parsed out on the provider side, e.g. `"state A, state B, state C"` which becomes `['state A', 'state B', 'state C']` , then you can manually trigger those states. Not ideal, but the closest I've seen if you don't have library support.

francislainy.campos
2022-02-11 05:04
Sorry, I have this but still: ```"request": { "method": "POST", "path": "/edcore/viaduct-service/jwt", "headers": { "Content-Type": "application/json", "accept": "application/json" }, "body": { "resourceId": "l_fc3ae9ed-62ac-4b94-8094-8dd29bc208a7_c57760a9-447b-42aa-81df-830134425157", "teacherAssessmentId": "93a91981-c6f7-435f-ab1e-80588ecff2ee", "expiryUnixEpochSeconds": 26757854170066, "sub": "UniqueUserId" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJWaWFkdWN0U2Vydm.blabla", "matchingRules": { "$.body": { "match": "type" } } }```

uglyog
2022-02-11 05:05
Let me see if I can reproduce it

sudhanshu.testing
2022-02-11 05:12
has joined #pact-js

uglyog
2022-02-11 05:34
Works fine for me. I can see ```16:33:29.216 [DEBUG] [au.com.dius.pact.core.matchers.JsonBodyMatcher] compareValues: Matcher defined for path [$] 16:33:29.216 [DEBUG] [au.com.dius.pact.core.matchers.MatcherExecutor] comparing type of "eyJhbGciOiJIUzI1NiJ9.eyJzd.bla" to "eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla" at [$]```

uglyog
2022-02-11 05:35
That is with version 4.1.34, let me try 4.3.x

uglyog
2022-02-11 06:14
4.3.5 works fine for me. I can't reproduce this. I did have to change the response to ```"body": "\"eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla\"",```

uglyog
2022-02-11 06:14
But I did not get your error. Can you confirm the version of Pact-JVM?

francislainy.campos
2022-02-11 06:20
```<pact.version>4.3.2</pact.version>```

akke.luukkonen
2022-02-11 07:10
I've used simply the word `and` myself to split my V2 state string into multiple separate states, which are applied simultaneously. Not ideal as well, but at least it has worked great. I also added a separate `clean` (default: `true`) option in the request to specify whether the database is dropped before the requested state is applied. So I can sequentially apply states in non-Pact tests (integration, e2e).

francislainy.campos
2022-02-11 11:03
We may try to change the backend to return a json with the {} , but I think we may have got into a limitation for pact here, so it may be interesting to know if that?s really the case.

alessandro.polidori
2022-02-11 15:02
has joined #pact-js

theferryatbuckland
2022-02-11 15:42
I've never done a pull request. Should I do that at the pact-foundation level, or on my fork?

theferryatbuckland
2022-02-11 15:55
So, I made the change only to Step 2, and pushed to my fork. Now, I can see "This branch is 1 step ahead of pact-foundation:step 2". And under "Contribute", I see the option to "Open pull request".

theferryatbuckland
2022-02-11 15:59
Just looking for the steps to take from that point....

theferryatbuckland
2022-02-11 16:07
Also, just to clarify - the four files updated were the root "package.json" and "package-lock.json" and the "consumer/package.json" and "consumer/package-lock.json". They are all dependency references, etc.

theferryatbuckland
2022-02-11 16:08
Let me know if you want me to proceed. And if so, is there a way to do this all at once for each of the Step branches, etc.? Or would I have to do that for each of them?

theferryatbuckland
2022-02-11 18:36
I did a test pull request for Step 3, had to add cross-env to two locations in package. I'll hold off on any more till I hear back from you.

theferryatbuckland
2022-02-11 18:50
Yeah, and so with Step 4, I tried the "npm ci...." 2x, did not add cross-env. Did it with "npm c...." and it loaded fine. Odd.

theferryatbuckland
2022-02-11 19:29
For Step 4, when running test on the Provider, I'm getting this error:

theferryatbuckland
2022-02-11 19:29
"E:/Training/Pact.io/Pacit.io Demos/pact-workshop-js/provider/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.63/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.35.1/lib/pact/provider_verifier/app.rb:3:in `require': cannot load such file -- pact/provider_verifier/provider_states/add_provider_states_header (LoadError)"


theferryatbuckland
2022-02-11 19:55
Implementing the expanded path length in Windows did not work, but I was able to move to a shallower path, and that is working.

theferryatbuckland
2022-02-11 19:56
I did notice your comment from May 24, 2021, that the v3 branch would resolve this. Is that available yet, or merged into master, etc.?

theferryatbuckland
2022-02-11 23:08
Actually, is there a way to undo my pull request? I'd like to submit it a different way. I've read something about reverting from an already committed branch, or rebasing, etc. That's one reason I wanted someone from Pact to do the update, I'm still too new at this. Thanks!

krisakins
2022-02-12 20:19
has joined #pact-js

ian.cervantez
2022-02-13 03:32
has joined #pact-js

matt.fellows
2022-02-13 07:53
I'll review tomorrow and come back to you. The main thing was to get you the commit/contribution credit, but all good if you'd like us to address it!

matt.fellows
2022-02-13 07:54
(the change committed to one step won't automatically work in another step, you'll need to merge the code into all steps. Again, we can do if easier)

matt.fellows
2022-02-14 01:04
The current workshop is designed for the main/stable release. If you want to use the V3 release you can, it?s back under active development after being blocked by some upstream issues.

matt.fellows
2022-02-14 01:05
https://github.com/pact-foundation/pact-js#pact-js-v3 The workshop will be helpful in understanding the concepts, but there will be some minor differences in APIs.

matt.fellows
2022-02-14 01:06
> Let me know if you want me to proceed. And if so, is there a way to do this all at once for each of the Step branches, etc.? Or would I have to do that for each of them? Ah, yes. We?ll need them in all steps. It?s a bit of a pain in the butt. I tend to get a single branch working first, and then cherry-pick each commit into separate branches (see e.g. https://github.com/pact-foundation/pact-workshop-js/blob/master/consumer/scripts/update-branches.sh to do so)

antonio.gamiz
2022-02-14 06:51
has joined #pact-js

theferryatbuckland
2022-02-14 13:20
I'm thinking the best thing is to reject the Step 3 pull request, and I should have just updated the ReadMe file (near the beginning) on the main page, just instructions for anyone that has that error. Should not have updated the code.

zish.gatrad
2022-02-14 16:01
has joined #pact-js

james.troughton
2022-02-14 16:08
has joined #pact-js

brentbarker9
2022-02-14 20:39
Thank you Matt!

manuelam20
2022-02-15 00:41
has joined #pact-js

dchen
2022-02-15 08:03
has joined #pact-js

aristides.suarez
2022-02-15 08:14
has joined #pact-js

marcelino.garcia
2022-02-15 08:22
has joined #pact-js

varnika.singh
2022-02-15 09:11
has joined #pact-js

edouard.lopez
2022-02-15 10:59
In the README I see interaction declare using a literal object `provider.addInteraction({state:?, uponReceiving:?})` and in the typescript example you use an instance of `new Interaction()` . Do you have recommendation for each approach?

matt.fellows
2022-02-15 11:20
Some people prefer the OO based and some prefer passing JSON. They are the same thing, so it comes down to personal preference

dharmesh.kumar
2022-02-15 14:25
@matt.fellows I am using matcher to match one properties that can have value null most of the time or any string so how I can write the expected response body of consumer `"description":term(` `generate: null,` `matcher: /([a-z])|null/),` I have written this it throwing error. can you please help me to resolve it.

bernard
2022-02-15 16:22
has joined #pact-js

david.uzumaki
2022-02-15 16:33
has joined #pact-js

abhishekc.jh
2022-02-15 17:21
has joined #pact-js

nuno.frias
2022-02-15 19:28
has joined #pact-js

matt.fellows
2022-02-15 21:28
You can?t do that

matt.fellows
2022-02-15 21:29
`null` is a type, not a string. So you can?t apply a regex to it


matt.fellows
2022-02-15 21:29
you need to create two scenarios - one for each

matt.fellows
2022-02-15 21:30
Also, for future reference, please don?t `@` people directly unless requested. We already monitor most channels and if we?re not responding it?s usually because we?re asleep :slightly_smiling_face:

faran
2022-02-15 22:31
has joined #pact-js

andy
2022-02-16 00:35
has joined #pact-js

fushinoryuu
2022-02-16 01:40
has joined #pact-js

dharmesh.kumar
2022-02-16 05:23
Thanks

abdelior
2022-02-16 08:48
has joined #pact-js

misterjkl
2022-02-16 13:12
has joined #pact-js

brian.azizi
2022-02-16 14:05
has joined #pact-js

richelle.raaphorst
2022-02-16 15:17
has joined #pact-js

tjones
2022-02-17 13:30
@tjones has left the channel

guillermo.aguirre
2022-02-17 20:06
has joined #pact-js

tati.shep
2022-02-18 06:52
has joined #pact-js

adamslack
2022-02-18 15:55
has joined #pact-js

darwin.cahyadi
2022-02-18 18:00
has joined #pact-js

jkdihenkar
2022-02-19 10:50
@jkdihenkar has left the channel

rishi.speets
2022-02-19 14:43
has joined #pact-js

ybergstrom
2022-02-21 03:24
has joined #pact-js

gyuvaraj10
2022-02-21 08:03
has joined #pact-js

athissen
2022-02-21 08:09
has joined #pact-js

mike.geeves064
2022-02-21 09:36
More of a general JS question than Pact specifically. I'm pretty new to JS so pretty much zero experience testing with it. Are there any general preferences of Jest vs Mocha? (or anything else?). With a focus on nice with Pact ofc, if there are any preferences of working with one over the other. I'm currently working with Vue3+Quasar, bdd makes me happy :grinning:

matt.fellows
2022-02-21 09:36
I think jest is the current most used due primarily to react

matt.fellows
2022-02-21 09:37
Tim recently released a mocha interface for Pact which matches the jest pact functionality

mike.geeves064
2022-02-21 09:37
Yeah, I saw mocha examples in there :thinking_face:

mike.geeves064
2022-02-21 09:37
React, Jest, FB eugh

matt.fellows
2022-02-21 09:38
I don't know if they use the new mocha specific library or just mocha directly

mike.geeves064
2022-02-21 09:50
Do you know if that was because fun or much demand? :thinking_face:

matt.fellows
2022-02-21 09:53
Mocha is pretty popular (by downloads) but I?d say the majority start with Jest.

yousafn
2022-02-21 10:17
Mocha is an incredibly popular and powerful testing framework and has been around for many many years. Jest has been gaining in popularity and traction for many reasons, but part of its explosion was around it being bundled with create react app out of the box. I remember when it first came onto the scene, we have cheat sheets between mocha and jest examples to help people transition. Also Mocha/chai is used as the assertion engine in several bigger tools aswell, such as Cypress. So I wouldn?t discount support for one of the other.

matt.fellows
2022-02-21 10:18
FWIW I use mocha by default - it goes nice with Chai :slightly_smiling_face:

matt.fellows
2022-02-21 10:18
(personally, I like the combination of chai+mocha, the fluent assertions are really nice). I found Jest awkward, but have accepted it?s the most used

andrefcsousa
2022-02-21 10:19
has joined #pact-js

katharina.pavic
2022-02-21 12:37
has joined #pact-js

mike.geeves064
2022-02-21 12:53
Mocha sounds like maybe better, especially if going towards cypress as well then?

mike.geeves064
2022-02-21 12:53
Sounds good, I will give mocha a try then, thanks! :grinning:

mike.geeves064
2022-02-21 12:54
I do prefer the names but it didn't seem like a good reason for choice in itself :joy:

mike.geeves064
2022-02-21 13:43
I do like a chai steamer from AMT

mike.geeves064
2022-02-21 13:43
:coffee::coffee::coffee:

mike.geeves064
2022-02-21 13:44
@yousafn Need to pick one or the other, at least with which to try out first :slightly_smiling_face: so much to read. Also I'm behind schedule, this was needed to measure when I need to water my plants as in away this week but it wasn't quite ready in time :joy::joy:

ipoe
2022-02-21 14:54
has joined #pact-js

abatan.k
2022-02-21 15:47
Hello all :) is there a binding for deno ?

jeroen.vandijk
2022-02-21 16:40
has joined #pact-js

yousafn
2022-02-21 16:43
These are some decent cheat sheets out there https://gist.github.com/yoavniran/1e3b0162e1545055429e So mocha is a test runner chai is an assertion engine sinon is used for mocking lolex for date/time mocking everyone used mocha as the test runner and then plugged in whatever they needed. Jest provides a runner, with an assertion engine built in. They are nearly the same with some caveats. the cheat sheets will help massively If you were using a create-react-app I would suggest jest-pact as jest ships out the box with cra. both have good support, Mocha has been around for like eons compared to Jest, so is very robust by now. I switch projects to jest now, unless they are deeply embedded, because it keeps the backend and front end unit testing frameworks the same :thumbsup:

yousafn
2022-02-21 16:44
mocha+chai or jest. Personally just go for jest, it will have everything you need out the box, need to reduce that cognitive load hehe

mike.geeves064
2022-02-21 17:20
Nod. I ofc have to go for something a little less mainstream so skipped react :grinning:

mike.geeves064
2022-02-21 17:22
Ahh names. My BE is going to be python You wouldn't mocha for the BE? I did not see that :thinking_face:

mike.geeves064
2022-02-21 17:27
Hmm interesting about switching projects :thinking_face: that would make sense if you have two different and could have two the same though

yousafn
2022-02-21 17:30
last project where I got introduced to Jest, it was TypeScript across the board. Mocha is JS land, so you would pick a suitable testing framework for Python. I think https://docs.pytest.org/en/7.0.x/ is most peoples go to. We wrote a few python scripts and used https://github.com/spulec/moto to mock out aws services

mike.geeves064
2022-02-21 17:32
Yeah I've got python covered, JS is the new land :grinning:

mike.geeves064
2022-02-21 17:35
Can you folk do BDD yet? :grinning:

mike.geeves064
2022-02-21 17:35
Moto is insane. Mock an ec2 instance. What does that even mean :open_mouth::open_mouth:

yousafn
2022-02-21 17:36
Hello Carere! Very cool that you are asking, I have really enjoyed Deno and watching its journey I don?t believe so, I started messing about with deno a while back, and setup and consumer/provider example to start testing out pact, but didn?t as got distracted by other things https://github.com/YOU54F/deno-examples/blob/main/README.md Just did a quick google and this looks interesting https://deno.land/x/tribles@v0.6.2 the readme mentions pact, which is curious, not looked in any detail yet > So far the following components have been implemented. > ? PACT js implementation. > ? TribleDB js immutable trible database. > ? TribleKB js immutable trible knowledge-base. >

abatan.k
2022-02-21 19:20
Hello, thks for your reply, i checked the deno repo , but it is not about pact :slightly_smiling_face:

abatan.k
2022-02-21 19:21
I will look the implementation for nodejs and try to provide one for deno :slightly_smiling_face:

abatan.k
2022-02-21 20:00
@matt.fellows Hello :slightly_smiling_face: What should it takes to be able to do contract testing in deno ?? It seems that i can just call the binary in my code, instead of doing `new Verifier(...).verify()` ? Is there a proper way to implement a deno version of pact ??

ondikumana
2022-02-21 22:13
has joined #pact-js

ian.cervantez
2022-02-22 03:02
the auto-mock feature of jest is pretty awesome - but for pact testing basically useless.

nithyag.ganesan
2022-02-22 10:01
has joined #pact-js

ntiwari
2022-02-22 11:48
has joined #pact-js

phil.vint
2022-02-23 11:01
has joined #pact-js

phongthornk
2022-02-23 11:04
has joined #pact-js

lukasz
2022-02-23 14:55
has joined #pact-js

matt.fellows
2022-02-23 20:46
I haven't looked at deno for a while

matt.fellows
2022-02-23 20:48
You could call those binaries directly, yes, but we're moving to a rust core via shared libraries . The new v3 pact uses a C++ wrapper but I'm hopeful given deno is rust we'd be able to use rust directly to interface to JS

dharmesh.kumar
2022-02-24 10:31
Hi, How we can compare only schema of response in contract testing ?

athaper
2022-02-24 11:01
Hello! I?m having an issue with pact jest where my tests are passing but the pact isn?t being generated in the directory I?ve tried several possible solutions that we could find on google but nothing worked , can someone here help please ? attaching the spec file below

athaper
2022-02-24 11:01
```"use strict" const { Pact } = require("@pact-foundation/pact") const path = require('path'); const {eachLike} = require("@pact-foundation/pact/src/dsl/matchers"); const Constant = require("../src/Constant"); const API_HOST = "http://localhost:7000/dev/" const provider = new Pact({ consumer: 'portal-ui', provider: 'portal', port: 7000, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: path.resolve(process.cwd(), 'pacts'), logLevel: 'DEBUG', }); describe('SiteSpeed Details Service', () => { describe('Wanted to get SiteSpeed Details', () => { beforeAll(() => provider.setup().then(() => { provider.addInteraction({ uponReceiving: 'a request to list sitespeed details', withRequest: { method: 'GET', path: API_HOST+'portal/v1/sitespeed/pages?executionId=4660', }, willRespondWith: { status: 200, body: eachLike( { execution_id: 4660, execution_page_id: 8207, first_contentful_paint_median: 6791, }, { min: 1 } ), }, }); }) ); it('should return the correct data', async() => { const sitespeed = await fetch(API_HOST+'sitespeed/pages?executionId=4660'); const response = await sitespeed.json(); expect(response[0].execution_id).toBe(4660); expect(response[0].execution_page_id).toBe(8207); }); afterEach(() => provider.verify()); afterAll(() => provider.finalize()); }); });```

abubics
2022-02-24 11:02
Like, flexible matching of the shape, or you have a schema defined and you want to verify it?

matt.fellows
2022-02-24 11:05
can you please share the `pact.log` and terminal output? It should show us there why it?s not working

matt.fellows
2022-02-24 11:06
btw the path looks incorrect to me, the query string should be moved into `query`

matt.fellows
2022-02-24 11:06
we could probably detect that case and warn

dharmesh.kumar
2022-02-24 11:07
yes Right, I have defined expected response and I want to verify only schema.

dharmesh.kumar
2022-02-24 11:08
I have also used the matcher but it does not full fill my requirement as it have some limitation with null value check.

athaper
2022-02-24 11:10
Here?s the pact.log file ```I, [2022-02-24T16:27:48.550621 #29652] INFO -- : Verifying - interactions matched I, [2022-02-24T16:27:48.552026 #29652] INFO -- : Registered expected interaction GET http://localhost:7000/dev/sitespeed/pages?executionId=4660 D, [2022-02-24T16:27:48.552434 #29652] DEBUG -- : { "description": "a request to list sitespeed details", "request": { "method": "GET", "path": "http://localhost:7000/dev/sitespeed/pages?executionId=4660" }, "response": { "status": 200, "headers": { }, "body": { "json_class": "Pact::ArrayLike", "contents": { "execution_id": 4660, "execution_page_id": 8207, "first_contentful_paint_median": 6791, }, "min": 1 } }, "metadata": null } I, [2022-02-24T16:27:48.558270 #29652] INFO -- : Cleared interactions```

matt.fellows
2022-02-24 11:13
notice how there are no logs indicating it received a request from your client before the interactions are cleared? I suspect there is a promise mishandling going on

matt.fellows
2022-02-24 11:14
Is it possible something else is running on port 7000? ALso, the terminal output would be helpful please

athaper
2022-02-24 11:19
yes there was something else running on port 7000 , i closed it and reran the test but still no pact got generated Here?s the console output ```[2022-02-24 11:17:53.297 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Creating Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"} [2022-02-24 11:17:54.873 +0000] INFO (32372 on C02YQC2LLVCG): pact@9.17.2: Setting up Pact with Consumer "qe-portal-ui" and Provider "qe-portal" using mock service on Port: "7000" [2022-02-24 11:17:54.901 +0000] INFO (32372 on C02YQC2LLVCG): pact@9.17.2: Pact File Written [2022-02-24 11:17:54.902 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Removing Pact process with PID: 32539 [2022-02-24 11:17:54.910 +0000] INFO (32372 on C02YQC2LLVCG): pact-node@10.17.1: Deleting Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}```

athaper
2022-02-24 11:25
and here?s the console output with debug log level ```/Users/athaper/.asdf/shims/node --require /Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-stdin-fix.js /Users/athaper/Repo/qe-portal-ui/node_modules/jest/bin/jest.js --colors --reporters /Applications/WebStorm.app/Contents/plugins/JavaScriptLanguage/helpers/jest-intellij/lib/jest-intellij-reporter.js --verbose --testNamePattern=^SiteSpeed Details Service --runTestsByPath /Users/athaper/Repo/qe-portal-ui/contract_tests/sitespeed_execution.spec.js [2022-02-24 11:20:16.971 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Creating Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"} [2022-02-24 11:20:16.993 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: Starting pact binary '/Users/athaper/Repo/qe-portal-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.81/pact/bin/pact-mock-service', with arguments [service --consumer qe-portal-ui --cors false --pact_dir /Users/athaper/Repo/qe-portal-ui/pacts --host 127.0.0.1 --log /Users/athaper/Repo/qe-portal-ui/logs/pact.log --log-level DEBUG --provider qe-portal --pact_specification_version 2 --ssl false --port 7000 --pact-file-write-mode overwrite] [2022-02-24 11:20:17.002 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: Created '/Users/athaper/Repo/qe-portal-ui/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.81/pact/bin/pact-mock-service' process with PID: 32945 [2022-02-24 11:20:17.803 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2022-02-24 11:20:17.803 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO WEBrick::HTTPServer#start: pid=32945 port=7000 [2022-02-24 11:20:18.049 +0000] INFO (32777 on C02YQC2LLVCG): pact@9.17.2: Setting up Pact with Consumer "qe-portal-ui" and Provider "qe-portal" using mock service on Port: "7000" [2022-02-24 11:20:18.078 +0000] INFO (32777 on C02YQC2LLVCG): pact@9.17.2: Pact File Written [2022-02-24 11:20:18.078 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Removing Pact process with PID: 32945 [2022-02-24 11:20:18.083 +0000] DEBUG (32777 on C02YQC2LLVCG): pact-node@10.17.1: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2022-02-24 11:20:18.084 +0000] INFO (32777 on C02YQC2LLVCG): pact-node@10.17.1: Deleting Pact Server with options: {"timeout":30000,"consumer":"qe-portal-ui","cors":false,"dir":"/Users/athaper/Repo/qe-portal-ui/pacts","host":"127.0.0.1","log":"/Users/athaper/Repo/qe-portal-ui/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"qe-portal","spec":2,"ssl":false,"port":7000,"pactFileWriteMode":"overwrite"}```

matt.fellows
2022-02-24 11:38
and `/Users/athaper/Repo/qe-portal-ui/pacts` is empty?

athaper
2022-02-24 11:39
Yep!

matt.fellows
2022-02-24 11:40
strange

matt.fellows
2022-02-24 11:40
definitely no Ruby processes hanging about ```ps -ef | grep ruby```

athaper
2022-02-24 11:44
only seeing this one

athaper
2022-02-24 11:59
We?re using jest already for UTs and installed pact jest , is it possible that something might be conflicting ? Here are the dependencies in our package.json ``` "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^12.0.0", "autoprefixer": "^6.7.2", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^23.4.2", "babel-loader": "^8.0.0", "c3": "^0.4.23", "css-loader": "^0.26.1", "file-loader": "^0.10.1", "group-array": "^0.3.3", "history": "^5.0.0", "immutable": "^4.0.0-rc.12", "jest": "^27.0.6", "jest-pact": "^0.9.1",```

abubics
2022-02-25 00:42
The FAQ, especially https://docs.pact.io/faq/#why-is-there-no-support-for-specifying-optional-attributes addresses some of these concerns (and others).

abubics
2022-02-25 00:42
Pact is contract-by-example, not schema-by-spec, but I'm not sure if you're trying to do something Pact isn't meant for, or if it's just a vocabulary issue.

abubics
2022-02-25 00:43
If you genuinely want to do only schema validation, there are other tools, and you will lose a significant amount of reasoning power.

dharmesh.kumar
2022-02-25 05:29
Thanks

ezequiel.uhrig
2022-02-25 13:46
has joined #pact-js

emin.sahin
2022-02-26 13:53
has joined #pact-js

ihassin
2022-02-27 21:20
has joined #pact-js

yumiihuang
2022-02-28 09:55
has joined #pact-js

yousaf
2022-02-28 11:57
has joined #pact-js

gerry
2022-02-28 12:56
has joined #pact-js

agustina.bosso
2022-02-28 16:04
has joined #pact-js

deactivateduser320370
2022-03-01 11:41
has joined #pact-js

luke.bickell
2022-03-01 14:46
has joined #pact-js

james.williams
2022-03-01 16:29
has joined #pact-js

qluck
2022-03-01 22:15
has joined #pact-js

qluck
2022-03-01 22:18
Hi everyone, I'm having an issue running a test that should be passing (and does on 10.0.0.beta54) after I've upgraded to 10.0.0.beta56. The issue is around the content-type header, and the error is `Expected body with content type application/json but was image/jpeg` . Can anyone please help?

qluck
2022-03-01 22:18
here's my code: ```const { pactWith } = require("jest-pact/v3"); const { MatchersV3 } = require("@pact-foundation/pact/v3"); const mockPactServerClient = require("../../utility/mockPactServer"); const fs = require("fs"); const { string } = MatchersV3; pactWith( { consumer: "bulk-upload", provider: "upload-provider", logLevel: 'INFO', port: 8081, }, (interaction) => { const fileBody = Buffer.from(fs.readFileSync("pikachu.png")).toString("base64"); interaction("initiateUpload", ({provider, execute}) => { beforeEach(() => provider .uponReceiving("Initiate Upload") .withRequest({ method: "PUT", path: '/bar/foo', headers: { Authorization: string("headerbar"), Accept: 'image/jpeg', 'Content-Type': 'image/jpeg', }, body: fileBody }) .willRespondWith({ status: 201 }) ); execute("Content-type bug test", () => { return mockPactServerClient.put( '/bar/foo', fileBody, { headers: { Authorization: "Bearer Auth", Accept: 'image/jpeg', "Content-Type": "image/jpeg", }, } ); }); } ) } );```

qluck
2022-03-01 22:19
what doesn't make sense is that I'm specifying the content type as `"image/jpeg"` everywhere, but it's still looking for `application/json`?

qluck
2022-03-01 22:29
here's the error

qluck
2022-03-01 22:29
```? Pact between bulk-upload and upload-provider ? with 30000 ms timeout for Pact ? initiateUpload ? Content-type bug test Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was incorrect: PUT /bar/foo 1.0 Expected body with content type application/json but was image/jpeg```

matt.fellows
2022-03-01 23:27
try setting the `contentType` property on the request and response bodies. That is part of the API I?m still looking at addressing. We?re in an awkward state where I?d like to continue support the JSON-like setup above, but it means certain options aren?t forced to be set. I?d prefer a type-state builder style API, but that won?t play nice with Jest Pact etc.

peter.pinda
2022-03-01 23:37
has joined #pact-js

peter.pinda
2022-03-02 00:22
Hi guys, Just wandering if anyone encounter the scenario, when multiple contacts on provider are fetched from broker (based on selector like tag:main, and deployed:true ). We need to reset our SQLite DB for each contract. Do you guys have any ideas how to do it:pray: ? `beforeEach` is triggered before each contract interaction so I probably cant use that one...

matt.fellows
2022-03-02 00:25
i?m not sure what the problem is you?re having Peter, could you please elaborate?

matt.fellows
2022-03-02 00:25
Provider states are usually how you handle different scenario data needs

peter.pinda
2022-03-02 00:45
Thanks @matt.fellows jumping into my issue... when we run:pact test on provider site, we spin the nextjs app module, create SQLighte db with data.Than Provider gets 2 contracts from PactFlow (based on selectors), first contract finds and deletes record in DB which passes ok, but for second which has same interactions, record is not found because first contact deleted it... If there is a way I can reset a DB between first and second contract I will probably solve my problem... PS: sorry tricky to explain

matt.fellows
2022-03-02 00:48
yes, you use provider states to specify ?thing exists? or ?thing does not exist? which triggers a provider state hook to fire. In htat hook (a JS function) you can manipulate the state of the interaction

matt.fellows
2022-03-02 00:48
see the e2e example in the Pact JS repository for a good example, or the JS workshop step :point_down: (howtolearn)

2022-03-02 00:48
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

peter.pinda
2022-03-02 01:11
hmm, for now we are using states for 2 users... like: ``` stateHandlers: { 'Agent login': async () => { token = getToken(jwtAgentData); }, 'Vendor login': async () => { token = getToken(jwtVendorData); }, },``` and on the consumer `given('Agent login')` ... Is there any way we can pass multiple states...lie `given(['Agent login', 'Clear some data'])` ?

matt.fellows
2022-03-02 01:22
Have a look at the docks there's a pre hook and post test hook. Personally I would just clear out the state for every provider state anyway so you always have a clean slate to begin with

peter.pinda
2022-03-02 02:02
@matt.fellows Appreciate you advice, thank you!

matt.fellows
2022-03-02 02:06
:+1:

omer.bilgin
2022-03-02 15:51
has joined #pact-js

qluck
2022-03-02 18:05
that helped!

qluck
2022-03-02 18:05
However, I'm running into another issue now with another test

qluck
2022-03-02 18:08
I have a custom contentType that I need to match, and whenever it's used i get the same error as above. The contentType is like this: `application/foo.bar.bulk-transfer+json` . Interestingly, if I don't use the "+" and change it to a "-", It will match. Something may be going on with matching "+" signs? A similar contentType is used in my company that I cannot change. Do you have any ideas on this? @matt.fellows

qluck
2022-03-02 18:09
here's an updated test: ```const { pactWith } = require("jest-pact/v3"); const { MatchersV3 } = require("@pact-foundation/pact/v3"); const mockPactServerClient = require("../../utility/mockPactServer"); const { string } = MatchersV3; pactWith( { consumer: "bulk-upload", provider: "upload-provider", logLevel: "INFO", port: 8081, }, (interaction) => { interaction("initiateUpload", ({ provider, execute }) => { beforeEach(() => provider .given("An experiance user") //These can share a state handler. However because we don't actually need to do anything, it's not needed in this case. .uponReceiving("A disallowed but allowed asset name") .withRequest({ method: "POST", path: "/bar/foo", headers: { Authorization: string("headerbar"), }, body: { "dc:format": "image/jpeg", }, contentType: 'application/foo.bar.bulk-transfer+json', }) .willRespondWith({ status: 200, headers: {}, body: { "dc:format": string("image/jpeg"), }, contentType: 'application/foo.bar.bulk-transfer+json', }) ); execute("Create Disallowed Asset", () => { return http://mockPactServerClient.post( "/bar/foo", { "dc:format": "image/jpeg", }, { headers: { Authorization: "Bearer Auth", "Content-Type": 'application/foo.bar.bulk-transfer+json', }, } ); }); }); } );```

banolik
2022-03-02 18:35
has joined #pact-js

thanuxxxx
2022-03-02 19:21
Hi, When we do a POST or PUT request for consumer tests, Is that possible to use temples to wrap the request body like this ```{ key1: string('value'), key2: number(1234) }```

matt.fellows
2022-03-02 21:23
What are you trying to do? You can probably just wrap what whole payload in a `like` matcher if you just want to check the shape

qluck
2022-03-02 21:52
if anyone has a similar issue as I've described above, I got it to work using regex

qluck
2022-03-02 21:52
remove the contentType property, and throw it back into the header.

qluck
2022-03-02 21:53
```"Content-Type": regex( /application\/vfoo.bar.bulk-transfer\+json/, "application/foo.bar.bulk-transfer+json"),``` This is what the regex will look like, and it will match on the incoming header from a request

qluck
2022-03-02 21:54
Note: the regex only needs to be put in the .withRequest,

ancyaziz
2022-03-02 22:26
has joined #pact-js

timothyg
2022-03-02 23:40
has joined #pact-js

timothyg
2022-03-02 23:56
Hello everyone, my team updated to version `10.0.0-beta.56` to get the timeout fix https://github.com/pact-foundation/pact-js/issues/761 We are running into an issue were the state handlers teardown is no longer being called. I don't see any change in the signature of the state handlers between `10.0.0-beta.54` and the version we are using now. Anyone have any ideas why the teardown isn't be executed? I'll include an example of the code in the thread.

timothyg
2022-03-02 23:57
Code Example: ```"State Handler": { resourceId: undefined, setup: async () => { console.log("Setup") resourceId = await setupState(); return Promise.resolve({ queryId: resourceId }); }, teardown: async () => { console.log('Teardown') await teardownState(resourceId); }, }```

mike.geeves064
2022-03-03 00:38
Not sure timelines of versions but there was a bug whereby the flag to tear down wasn't being used and *always* did a tear down, on the rust side during a verify: https://github.com/pact-foundation/pact-reference/pull/167 Iirc there's just a flag when calling the verifier to use them

mike.geeves064
2022-03-03 00:39
--state-change-teardown

harihararaj.lk
2022-03-03 09:44
has joined #pact-js

harihararaj.lk
2022-03-03 09:51
Hello people, Trying to do equality matching of the response body , but using Matcher doesn't provide any equality matching ability. Is there any workaround or am i missing something on the matcher ?? ```"matchingRules": { "$.body": { "match": "equality" } }```

matt.fellows
2022-03-03 10:57
can you please share your test details? If you just want to match the exact body, you don?t need to use a matcher - it?s effectively ?equality? by default

matt.fellows
2022-03-03 10:57
why do you want to do a strict match, may I ask?

harihararaj.lk
2022-03-03 11:06
@matt.fellows, we are using strict match because we are using the same set of data at both provider and consumer ends, and data matching is somewhat a requirement .

harihararaj.lk
2022-03-03 11:07
"interactions": [ { "description": "Request to save theme", "providerState": "Request to save themes", "request": { "method": "POST", "path": "/themes-service/save", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "results": [ { "name": "abc", "result": true } ] }, "matchingRules": { "$.body.: { "match": "type" } } } ]

harihararaj.lk
2022-03-03 11:09
we are using jest library to generate pact contract json files , which is not including the equality matching rule by default

matt.fellows
2022-03-03 11:10
I need to see your test please

matt.fellows
2022-03-03 11:10
my guess is you?re wrapping the body in a matcher such as `like`

matt.fellows
2022-03-03 11:10
just don?t use the matcher

harihararaj.lk
2022-03-03 11:13
```import { HTTPMethod } from "@pact-foundation/pact/src/common/request"; import { Matchers } from "@pact-foundation/pact"; import { pactWith } from "jest-pact"; import fetch from "node-fetch"; import { URL } from "url"; jest.setTimeout(30000); pactWith( { consumer: "aggregator", provider: "theme_provider" }, (provider) => { describe("Theme related end points", () => { it("Request to save themes", async () => { const url = new URL( `${provider.mockService.baseUrl}/themes-service/themes` ); const { validateExample } = Matchers; const interaction = { state: "Request to save themes", uponReceiving: "Request to save themes", withRequest: { method: http://HTTPMethod.POST, path: url.pathname, headers: { Accept: "application/json" }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json" }, body: { results: [{ handle: "abc", result: "Created" }], }, }, }; await provider.addInteraction(interaction); const result = await fetch( `${provider.mockService.baseUrl}/themes-service/themes`, { method: http://HTTPMethod.POST, headers: { Accept: "application/json", "Content-Type": "application/json", }, } ); expect(await result.json()).toEqual({ results: [ { handle: "abc", result: "Created", }, ], }); }); }); } );```

harihararaj.lk
2022-03-03 11:14
Yeah I had wrapped the entire body with *like* matcher because the generated pact json didn't have any matching rules when using the above

matt.fellows
2022-03-03 11:38
matching rules aren?t needed for exact match. Did that work?

harihararaj.lk
2022-03-03 11:43
@matt.fellows, No it didn't work. The generated pact json was as given below. It is passing at the consumer test , but when json is used by a provider (Spring boot application), it basically ignores the validation, as there are no matching rules condition. When manually the equality matching rule is added it is passing though

harihararaj.lk
2022-03-03 11:43
```{ "consumer": { "name": "aggregator" }, "provider": { "name": "theme_provider" }, "interactions": [ { "description": "Request to save themes", "providerState": "Request to save themes", "request": { "method": "POST", "path": "/themes-service/themes", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "results": [ { "handle": "abc", "result": "Created" } ] } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

matt.fellows
2022-03-03 11:51
> , but when json is used by a provider (Spring boot application), it basically ignores the validation, as there are no matching rules condition. When manually the equality matching rule is added it is passing though That?s not how it works, something else must be wrong. Can you please share the actual problem you?re having?

matt.fellows
2022-03-03 11:53
hm interesting

matt.fellows
2022-03-03 11:53
> , if I don?t use the ?+? and change it to a ?-?, It will match. Something may be going on with matching ?+? signs? smells of escaping or something doesn?t it.

matt.fellows
2022-03-03 11:54
If you could please set the log level to debug and provide an output dump, that would be helpful in seeing what the engine thinks is goinsg on

matt.fellows
2022-03-03 12:08
Hi Timothy! hmm, it should support them. Any chance you could please share a debug log for us to take a look at?

matt.fellows
2022-03-03 12:11
The change Mike contributed should be in the latest JS though

mike.geeves064
2022-03-03 12:11
The bug I looked at was it always sent them even without the flag, the logic meant it was always true, so maybe some backwards compatibility issue introduced

matt.fellows
2022-03-03 12:11
ah

mike.geeves064
2022-03-03 12:11
If it is related to that, I forgot to check this morning

mike.geeves064
2022-03-03 12:12
On mobile again :) the default was don't send, but the default didn't work

matt.fellows
2022-03-03 12:13
Actually, that handler definition looks incorrect to me

matt.fellows
2022-03-03 12:15
nvm, I?m tired.

matt.fellows
2022-03-03 12:15
I mean, there is a superfluous key there (`resourceId`) but that shouldn?t break things

mike.geeves064
2022-03-03 12:21
I think just calling pact-verifier with --state-change-teardown should do it, if it is related to that

matt.fellows
2022-03-03 12:22
That might be it. We moved the core from the CLI version of the verifier to the handle based on. It could be missed in that change

matt.fellows
2022-03-03 12:37
just realised you?re not on the latest. Can you please check out `10.0.0-beta.58` ?

matt.fellows
2022-03-03 12:37
Just ran it locally and can see setup/teardown running OK

toyamarinyon
2022-03-03 13:25
has joined #pact-js

david342
2022-03-03 13:26
has joined #pact-js

david342
2022-03-03 13:33
Hi could anyone help me with what seems like a simple question I want to match a value that can be 0 or 1 After much trying I arrive at trial: term({ matcher: "\\[0 - 1]", generate: 0 }), No luck - Example '0' does not match provided regular expression '\[0 - 1]' What am I doing wrong please ?

david342
2022-03-03 13:41
It looks like

david342
2022-03-03 13:42
trial: regex({ matcher: "[0 - 1]", generate: "0" }),

david342
2022-03-03 13:42
is what I need

timothyg
2022-03-03 16:02
I'll try the `--state-change-teardown` and if that doesn't work I'll see about bumping the version to the latest.

yesilmenadil
2022-03-03 16:14
has joined #pact-js

timothyg
2022-03-03 16:31
The `--state-change-teardown` arg didn't have any effect. But bumping to version to `10.0.0-beta.58` did work. The teardowns are now being executed.

mike.geeves064
2022-03-03 16:33
Glad to hear it's working, and also glad it wasn't broken as a result of my fix :grinning:

dajaman1
2022-03-03 20:30
has joined #pact-js

dajaman1
2022-03-03 20:36
Hi anyone can help me. I?m using pact in a debian container. When we use mocha as test framework everything works fine, our project uses jasmine as main test framework, when I switch to jasmine I got this error: `Unhandled promise rejection: Error: Pact startup failed; tried calling service 10 times with no result.` Nothing else is changed.

matt.fellows
2022-03-03 21:26
Are there any other logs?

matt.fellows
2022-03-03 21:26
You can?t apply regexes to numbers

matt.fellows
2022-03-03 21:26
they only work on strings

matt.fellows
2022-03-03 21:27
in this case, your only option is to do exact match on value (not ideal) or use the `like` matcher

dajaman1
2022-03-03 21:40
@matt.fellows these are the complete logs `NODE_ENV=test npx jasmine spec/contract/bsapi.spec.js` `Running tests with 'NODE_ENV=test'` `Started` `[2022-03-03 20:44:30.699 +0000] INFO (133 on 7d526b155d90): pact-node@10.17.1: Creating Pact Server with options:` `{"timeout":100000,"consumer":"ares-integration-services","cors":false,"dir":"/app/pacts","host":"0.0.0.0","log":"/app/logs/mockserver-integration.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"BSAPI","spec":2,"ssl":false,"port":1234,"pactFileWriteMode":"overwrite"}` `[2022-03-03 20:44:30.713 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: Starting pact binary '/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.81/pact/bin/pact-mock-service', with arguments [service --consumer ares-integration-services --cors false --pact_dir /app/pacts --host 0.0.0.0 --log /app/logs/mockserver-integration.log --log-level DEBUG --provider BSAPI --pact_specification_version 2 --ssl false --port 1234 --pact-file-write-mode overwrite]` `[2022-03-03 20:44:30.719 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: Created '/app/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.81/pact/bin/pact-mock-service' process with PID: 144` `[2022-03-03 20:44:36.922 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: INFO WEBrick 1.3.1` `INFO ruby 2.2.2 (2015-04-13) [x86_64-linux]` `[2022-03-03 20:44:36.922 +0000] DEBUG (133 on 7d526b155d90): pact-node@10.17.1: INFO WEBrick::HTTPServer#start: pid=144 port=1234` `[2022-03-03 20:46:10.641 +0000] ERROR (133 on 7d526b155d90): pact@9.17.2: The pact mock service doesn't appear to be running` `- Please check the logs above to ensure that there are no pact service startup failures` `- Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method)` `- Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one` `- To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG'` `F[2022-03-03 20:46:10.649 +0000] ERROR (133 on 7d526b155d90): pact@9.17.2: The pact mock service doesn't appear to be running` `- Please check the logs above to ensure that there are no pact service startup failures` `- Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method)` `- Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one` `- To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG'` `Failures:` `1) BSAPI /bsapi/api/v1c/monitoring-series?baseline-id=ORD-2109329-02 when request is not authenticated should fail requiring authentication` `Message:` `Error: The pact mock service wasn't running when verify was called` `Stack:` `Error: The pact mock service wasn't running when verify was called` `at Pact.verify (/app/node_modules/@pact-foundation/pact/src/httpPact.js:108:35)` `at UserContext.<anonymous> (/app/spec/contract/bsapi.spec.js:59:28)` `at <Jasmine>` `Suite error: BSAPI` `Message:` `Unhandled promise rejection: Error: Pact startup failed; tried calling service 10 times with no result.` `Stack:` `Error: Pact startup failed; tried calling service 10 times with no result.` `at Server.retry (/app/node_modules/@pact-foundation/pact-node/src/service.js:177:33)` `at _rejected (/app/node_modules/q/q.js:864:24)` `at /app/node_modules/q/q.js:890:30` `at Promise.when (/app/node_modules/q/q.js:1142:31)` `at Promise.promise.promiseDispatch (/app/node_modules/q/q.js:808:41)` `at /app/node_modules/q/q.js:624:44` `at runSingle (/app/node_modules/q/q.js:137:13)` `at flush (/app/node_modules/q/q.js:125:13)` `at processTicksAndRejections (node:internal/process/task_queues:78:11)` `Message:` `Error: Timeout - Async function did not complete within 100000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)` `Stack:` `Error: Timeout - Async function did not complete within 100000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)` `at <Jasmine>` `at listOnTimeout (node:internal/timers:557:17)` `at processTimers (node:internal/timers:500:7)` `Message:` `Error: The pact mock service wasn't running when finalize was called` `Stack:` `Error: The pact mock service wasn't running when finalize was called` `at Pact.finalize (/app/node_modules/@pact-foundation/pact/src/httpPact.js:141:35)` `at UserContext.<anonymous> (/app/spec/contract/bsapi.spec.js:61:27)` `at <Jasmine>` `at processImmediate (node:internal/timers:464:21)` `1 spec, 2 failures` `Finished in 99.957 seconds`

matt.fellows
2022-03-03 21:42
can you please share your test setup? The error message has some helpful guides on what to do - are you sure `setup()` is called in the correct place etc.?

matt.fellows
2022-03-03 21:44
Awesome, thanks for confirming Timothy.

matt.fellows
2022-03-03 21:45
We?re back on track with the JS release now - so there will likely be a bunch of more beta updates before we cut over

matt.fellows
2022-03-03 21:45
The main thing left to do is plumb in message pact into the new core and then stabilise the public API

matt.fellows
2022-03-03 21:45
thanks for the feedback!

waqif
2022-03-03 23:32
has joined #pact-js

dmitry.matveev
2022-03-03 23:44
has joined #pact-js

tomas.sakinis
2022-03-04 06:38
has joined #pact-js

matt.fellows
2022-03-04 07:39
For those looking to level up their knowledge of contract testing @mcruzdrake is running a (paid) workshop at https://www.linkedin.com/company/thetesttribe/ on - ?Contract Testing with Pact JS ? Learn the basics of contract testing and implement it into your projects.?:test_tube: Use the promo code MARIEWQF for a nice little incentive:shushing_face: Learn more here :point_right: https://bit.ly/3tffW5a

david342
2022-03-04 09:19
Thanks didn't realise that . OK thats a pity

matt.fellows
2022-03-04 09:39
I'd suggest raising a matcher for a range of integer values here: https://github.com/pact-foundation/pact-specification/issues

david342
2022-03-04 10:43
Thanks I don't mind digging into the code and doing a PR , I'll see how to go about that

matt.fellows
2022-03-04 10:46
It?ll be rust code where that matcher will go, btw :wink:

david342
2022-03-04 10:50
Oh great I want to learn Rust where is the repo for all that


matt.fellows
2022-03-04 10:59
You should raise the suggestion first before issuing a PR, because it has ecosystem wide consequences and we would want to get a consensus that it?s a good idea

yousafn
2022-03-04 12:25
Would also be good to see your test setup files for Mocha and the equivalent for Jasmine. It looks like the pact mock service hasn't started, which may have been in a mocha specific setup file which you haven't got for jasmine. we have a mocha and jasmine example but as part of `karma` https://github.com/pact-foundation/pact-js/tree/master/examples/karma which uses pact-web which probably isn't what you are after

dajaman1
2022-03-04 12:59
@yousafn I don?t have any setup for mocha nor jasmine. I call both like this in the package.json: ?test:contract?: ?NODE_ENV=test jasmine spec/contract/*.spec.js? and for mocha ?test:contract?: ?NODE_ENV=test mocha --exit --recursive -R spec spec/contract/*.spec.js --timeout 10000"

yousafn
2022-03-04 13:04
Ahh thanks that is useful, so I assume your setup is in the test file(s) hook itself. what is the in the contents of the log file `app/logs/mockserver-integration.log` Also if you put three backticks before your code output in slack, you will get a nice formatted code block which is much easier to read :slightly_smiling_face: ````your code text`

dajaman1
2022-03-04 13:04
@matt.fellows I believe it is correctly setup, because the same code(just framework changes) is working in mocha That is the test setup `const path = require('path')` `const { Pact } = require('@pact-foundation/pact')` `describe('API', () => {` `let provider` `jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000` `provider = new Pact({` `consumer: 'ares-integration-services',` `provider: 'BSAPI',` `port: 1234,` `log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),` `dir: path.resolve(process.cwd(), 'pacts'),` `logLevel: 'DEBUG',` `timeout: 100000` `})` `beforeAll(async () => {` `await provider.setup()` `provider.addInteraction({` `state: 'the request is not authenticated',` `uponReceiving: 'a request for monitoring series',` `withRequest: {` `method: 'GET',` `path: '/api'` `},` `willRespondWith: {` `status: 401,` `headers: {` `'Content-Type': 'application/problem+json; charset=utf-8'` `}` `}` `})` `})` `describe('/api', () => {` `describe('when request is not authenticated', () => {` `it('should fail requiring authentication', async () => {` `expect(true).toBe(true)` `})` `})` `})` `afterEach(() => provider.verify())` `afterAll(() => provider.finalize())` `})`

yousafn
2022-03-04 13:06
I'll take a look and try and put some examples against a pact-js branch buddy

dajaman1
2022-03-04 13:12
In the log file there is nothing, when run with jasmine With mocha i got this, I know there is an error but the connection is working properly ```I, [2022-03-04T13:11:11.827524 #29] INFO -- : Registered expected interaction GET /api W, [2022-03-04T13:11:11.830281 #29] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /api D, [2022-03-04T13:11:11.830585 #29] DEBUG -- : { "description": "a request for monitoring series", "providerState": "the request is not authenticated", "request": { "method": "GET", "path": "/api" }, "response": { "status": 401, "headers": { "Content-Type": "application/problem+json; charset=utf-8" } }, "metadata": null } W, [2022-03-04T13:11:11.831952 #29] WARN -- : Missing requests: GET /api I, [2022-03-04T13:11:11.845377 #29] INFO -- : Cleared interactions```

yousafn
2022-03-04 13:26
so to switch between `jasmine` and `mocha` I need to change the `beforeAll` / `afterAll` to `before`/`after` . In your script, you are using `expect` are you getting that from `chai` globally?

dajaman1
2022-03-04 13:27
you are right, and comment the jasmine.DEFAULT_?..

yousafn
2022-03-04 13:29
So this is a run in jasmine, with your code snippet above ```?? npm run test:jasmine ?? > mochajs-pact-example@1.0.0 test:jasmine > NODE_ENV=test rimraf pacts && jasmine test/*.jasmine.spec.js [2022-03-04 13:28:40.017 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Creating Pact Server with options: {"consumer":"ares-integration-services","cors":false,"dir":"/Users/saf/dev/pactoss/pact-js/examples/mocha/pacts","host":"127.0.0.1","log":"/Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":1234,"provider":"BSAPI","spec":2,"ssl":false} Randomized with seed 44043 Started [2022-03-04 13:28:40.025 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Starting pact binary 'standalone/darwin-1.88.63/pact/bin/pact-mock-service', with arguments [service --consumer ares-integration-services --pact_dir /Users/saf/dev/pactoss/pact-js/examples/mocha/pacts --host 127.0.0.1 --log /Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log --pact-file-write-mode overwrite --port 1234 --provider BSAPI --pact_specification_version 2] [2022-03-04 13:28:40.029 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Created 'standalone/darwin-1.88.63/pact/bin/pact-mock-service' process with PID: 59113 [2022-03-04 13:28:40.428 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2022-03-04 13:28:40.428 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO WEBrick::HTTPServer#start: pid=59113 port=1234 [2022-03-04 13:28:40.550 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact@9.16.0: Setting up Pact with Consumer "ares-integration-services" and Provider "BSAPI" using mock service on Port: "1234" Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /api See /Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log for details. F[2022-03-04 13:28:40.570 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact@9.16.0: Pact File Written [2022-03-04 13:28:40.570 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Removing Pact process with PID: 59113 [2022-03-04 13:28:40.571 +0000] INFO (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: Deleting Pact Server with options: {"consumer":"ares-integration-services","cors":false,"dir":"/Users/saf/dev/pactoss/pact-js/examples/mocha/pacts","host":"127.0.0.1","log":"/Users/saf/dev/pactoss/pact-js/examples/mocha/logs/mockserver-integration.log","pactFileWriteMode":"overwrite","port":1234,"provider":"BSAPI","spec":2,"ssl":false} [2022-03-04 13:28:40.572 +0000] DEBUG (59112 on Yousafs-MacBook-Pro.local): pact-node@10.13.3: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. Failures: 1) API /api when request is not authenticated should fail requiring authentication Message: Error: Pact verification failed - expected interactions did not match actual. Stack: at new VerificationError (/Users/saf/dev/pactoss/pact-js/examples/mocha/node_modules/@pact-foundation/pact/src/errors/verificationError.js:19:42) at /Users/saf/dev/pactoss/pact-js/examples/mocha/node_modules/@pact-foundation/pact/src/httpPact.js:108:23 at processTicksAndRejections (node:internal/process/task_queues:96:5) 1 spec, 1 failure Finished in 0.554 seconds Randomized with seed 44043 (jasmine --random=true --seed=44043)```

yousafn
2022-03-04 13:30
This is my command to start `"test:jasmine": "rimraf pacts && jasmine test/*.jasmine.spec.js"` so it looks like the mock provider started ok here. You mentioned this was also running inside a docker container?

dajaman1
2022-03-04 13:32
Yes, I?m using a debian stretch image as a container

yousafn
2022-03-04 13:32
I'll try the same versions of pact as you and then can stick this in a container and see what happens. `pact-node@10.17.1` `pact@9.17.2`

yousafn
2022-03-04 13:33
got a dockerfile handy?

dajaman1
2022-03-04 13:36
I have it, but it has some sensitive information in it(it would take some time to clear), I?m kinda afraid to share it, sorry

yousafn
2022-03-04 13:39
No that is absolutely fine my friend, appreciate that, I can setup a debian image easily enough :slightly_smiling_face: I have an example here in fork https://github.com/YOU54F/pact-js/commit/404e83ab4dadbf505711055410aba80a683b1b80 under the https://github.com/YOU54F/pact-js/compare/jasmineExamples branch. If you go to `examples/mocha` and run `npm i` and then `npm test:jasmine` that is working for me. The mocha version is complaining that `expect(...).toBe is not a function` you can run that with `npm:test`

yousafn
2022-03-04 13:45
There is a docker example file in pact-js so I will switch that out for debian and see how we go :slightly_smiling_face: https://github.com/pact-foundation/pact-js/tree/feat/docker-example/docker

reuben.tonna
2022-03-04 14:32
has joined #pact-js

dajaman1
2022-03-04 14:46
@yousafn I was able to solve the issue, there was a ?hidden? nock configuration that was blocking any connection :upside_down_face:, I really appreciate your help, thank you so much.

yousafn
2022-03-04 14:54
Oh fantastic dude! And no problem

negrolyze
2022-03-04 15:34
has joined #pact-js

alanbos
2022-03-04 17:49
Hi - does anyone have a simple example of using `GraphQLInteraction` with PactV3? I'm struggling with how to use it in the following approach as I'm not sure PactV3 has an `addInteraction()` method: ```const provider = new PactV3(...); describe('query', () => { beforeEach(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('a query') .withQuery('...') .withVariables({}) .withRequest({ path: '/graphql', method: 'POST', }) .willRespondWith({ status: 200, headers: { ... }, body: { ... } }); return provider.addInteraction(graphqlQuery); <-- IS THIS VALID? )}; )}; ```

42amehmeto
2022-03-04 19:17
has joined #pact-js

rawatankit90
2022-03-04 22:33
has joined #pact-js

matt.fellows
2022-03-04 23:35
V3 doesn't have a graphql API at the moment

alanbos
2022-03-05 00:03
Thanks Matt

matt.fellows
2022-03-05 01:05
If you take a look at the current graphql interface you could see how it's done. It's a very simple facade

matt.fellows
2022-03-05 01:05
Or a PR into the v3.x.x branch would be great too

alanbos
2022-03-05 07:01
I'll take a look - thanks again.

alanbos
2022-03-05 09:39
@matt.fellows for the PactV3 class, would the correct approach here be to subclass that class with the additional Graphql dsl methods (e.g. withVariables()) - just want to make sure I understand the intention behind the new design.

matt.fellows
2022-03-06 10:52
I think for now that?s probably the best idea

artur
2022-03-07 04:04
I'm back to trying to update 10.0.0-beta.36 to 10.0.0-beta.58 found that I need to set `contentType:` now if the requests are not json but now I'm getting `PactffiGivenWithParam(arg 2) expected a string` I cannot see what can be wrong in that `uponReceiving` request ``` 183 | }) 184 | return provider > 185 | .uponReceiving(`as ${sharer}, a GET request to get single share of '${resource}' ${requestName}`) | ^ 186 | .withRequest({ 187 | method: 'GET', 188 | path: fromProviderState( at givenWithParam (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:139:22) at Object.givenWithParam (node_modules/@pact-foundation/pact-core/src/consumer/checkErrors.ts:9:21) at node_modules/@pact-foundation/src/v3/pact.ts:238:28 at forEachObjIndexed (node_modules/ramda/src/forEachObjIndexed.js:34:5) at f2 (node_modules/ramda/src/internal/_curry2.js:29:14) at node_modules/@pact-foundation/src/v3/pact.ts:237:26 at Array.forEach (<anonymous>) at PactV3.uponReceiving (node_modules/@pact-foundation/src/v3/pact.ts:235:17) at getShareInteraction (tests/sharingTest.js:185:8) at Object.<anonymous> (tests/sharingTest.js:701:11)```

matt.fellows
2022-03-07 04:11
I've just popped out Artur but will look when back. This has the new core in it so could be a few teething issues/arts mapped incorrectly

matt.fellows
2022-03-07 04:12
I've got a plan to not make contentType mandatory soon. I'd like to introduce a new builder API but leave the existing one for compatibility. The reason is there are a lot more options/code paths and it's not obvious by looking at the API. I'd like to make that clearer and to prevent state issues by a proper builder API


matt.fellows
2022-03-07 04:22
But should be calling the other branch

matt.fellows
2022-03-07 04:22
I'm guessing there is a logic flaw in that code

matt.fellows
2022-03-07 04:35
Oh, what does you given look like?

artur
2022-03-07 05:02
```provider.given('the user is recreated', { username: user, password: password })```

artur
2022-03-07 05:02
I see that given only accepts a string now `given(providerState: string): this;`


artur
2022-03-07 05:41
we are using multiple functions to create the provider object, maybe this is the issue `// TODO: this currently must be called before other methods, else it won't work`

matt.fellows
2022-03-07 05:56
ah, maybe!

matt.fellows
2022-03-07 05:59
> I see that given only accepts a string now `given(providerState: string): this;` Where are you seeing this?

artur
2022-03-07 06:31
my IDE takes me to node_modules/@pact-foundation/pact/src/dsl/interaction.d.ts but that is wrong, because I need to look into the V3 code

artur
2022-03-07 06:43
getting rid of all givens makes it pass

matt.fellows
2022-03-07 06:44
Thanks Artur.

matt.fellows
2022-03-07 06:44
What does your current `given` look like?

matt.fellows
2022-03-07 06:45
This, by the way, is exactly the kind of state related problem I?d like to solve with a type-state builder API

artur
2022-03-07 06:51
the issue is `optionalParams` in this part ```provider .given('resource is shared', { username, userPassword, path, shareType: SHARE_TYPE.group, shareWith, ...optionalParams }``` where optionalParams = {permissions: undefined, expireDate: undefined, attributes: undefined}

artur
2022-03-07 06:53
the issue are the undefined values ` ```given('resource is shared', { x: 'some value' })``` works but ` ```.given('resource is shared', { x: undefined })``` crashes

artur
2022-03-07 06:54
bug or feature?

matt.fellows
2022-03-07 06:54
bug, I think

matt.fellows
2022-03-07 06:55
You want `undefined` to come through, I?m assuming? No reason I can think of that we shouldn?t allow that to happen

matt.fellows
2022-03-07 06:57
I think it?s because we `JSON.stringify(value)` but `undefined` doesn?t stringify

artur
2022-03-07 07:01
cannot reproduce in examples

artur
2022-03-07 07:02
old version of pact-js, trying again

matt.fellows
2022-03-07 07:05
Ah. So `undefined` is not actually valid JSON. It can be passed around in JS, but it?s not JSON itself. This could be the cause of the interop issue here

matt.fellows
2022-03-07 07:05
can you use `null`?

matt.fellows
2022-03-07 07:05
(or omit the property altogether?)


matt.fellows
2022-03-07 07:09
I think I should update the Typescript type to prevent the use of undefined in the parameters - that?s the first step

matt.fellows
2022-03-07 07:09
but it won?t fix JS users, so it will need some validation also

matt.fellows
2022-03-07 07:10
I think we should explictly error if we find `undefined` because it may lead to unintended consequences

matt.fellows
2022-03-07 07:11
In your case, I?m not sure what works best - replacing `undefined` with `null` or some alternative?

artur
2022-03-07 07:12
I'm trying now ``` optionalParams = JSON.stringify(optionalParams) optionalParams = JSON.parse(optionalParams)```

artur
2022-03-07 07:12
that should delete all keys with undefined values


matt.fellows
2022-03-07 07:41
Excellent! Thanks for letting me know. I'll fix the above in the next release (next few days)

tom.daley
2022-03-07 09:09
has joined #pact-js

leon.brown
2022-03-07 09:26
has joined #pact-js

matt.fellows
2022-03-07 10:14
I?ve made a patch locally for this. It?s not my ideal solution, but having it will prevent a regression and provide a target for addressing later.

matt.fellows
2022-03-07 10:14
I?ll push it up in the next couple of days

aurelia.rochat
2022-03-07 10:16
has joined #pact-js

kabhatiya
2022-03-08 00:51
has joined #pact-js

luis.garelli
2022-03-08 09:29
has joined #pact-js

andrevdrodrigues
2022-03-08 12:50
has joined #pact-js

tobias
2022-03-08 13:11
has joined #pact-js

mutharaju.kk
2022-03-08 14:34
has joined #pact-js

gerry
2022-03-08 14:48
@gerry has left the channel

will.robinson
2022-03-08 14:54
has joined #pact-js

nathan.deamer
2022-03-08 15:00
has joined #pact-js

fragonib
2022-03-08 16:22
has joined #pact-js

jason.wang
2022-03-08 19:05
has joined #pact-js

sam680
2022-03-09 05:12
has joined #pact-js

artur
2022-03-09 05:37
my matching rules for response end up in the request in the JSON ```provider .given('the user is recreated', { username: user, password: password }) .uponReceiving(`as '${user}', a GET to get current user information`) .withRequest({ method: 'GET', path: MatchersV3.regex( /.*\/ocs\/v1\.php\/cloud\/user$/, '/ocs/v1.php/cloud/user' ), headers: { authorization: getAuthHeaders(user, password) } }) .willRespondWith({ status: 200, headers: applicationXmlContentType, body: new XmlBuilder('1.0', '', 'ocs').build(ocs => { ocs.appendElement('meta', '', (meta) => { meta.appendElement('status', '', MatchersV3.equal('ok')) .appendElement('statuscode', '', MatchersV3.equal('100')) .appendElement('message', '', MatchersV3.equal('OK')) }).appendElement('data', '', (data) => { data.appendElement('id', '', MatchersV3.equal(user)) data.appendElement('display-name', '', MatchersV3.regex(`(${user}|${displayName})`, user)) data.appendElement('email', '', MatchersV3.regex(`(${user}@example\\..*)?`, '')) }) }) })``` gives me: ``` "request": { "headers": { "authorization": "Basic dGVzdDEyMzp0ZXN0MTIz" }, "matchingRules": { "body": { "$.ocs.data.display-name.#text": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "(test123|Test123)" } ] }, "$.ocs.data.email.#text": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "(test123@example\\..*)?" } ] }, "$.ocs.data.id.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] }, "$.ocs.meta.message.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] }, "$.ocs.meta.status.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] }, "$.ocs.meta.statuscode.#text": { "combine": "AND", "matchers": [ { "match": "equality" } ] } }, "header": {}, "path": { "combine": "AND", "matchers": [ { "match": "regex", "regex": ".*\\/ocs\\/v1\\.php\\/cloud\\/user$" } ] } }, "method": "GET", "path": "/ocs/v1.php/cloud/user" }, "response": { "body": "<?xml version='1.0'?><ocs><meta><status>ok</status><statuscode>100</statuscode><message>OK</message></meta><data><id>test123</id><display-name>test123</display-name><email></email></data></ocs>", "headers": { "Content-Type": "application/xml; charset=utf-8" }, "status": 200 }``` all the matches are there but in the wrong place

matt.fellows
2022-03-09 05:49
:scream:

matt.fellows
2022-03-09 05:49
let me take a look. Only happening with XML ones?

artur
2022-03-09 05:52
trying to confirm

artur
2022-03-09 05:54
at least in my tests JSON works fine

matt.fellows
2022-03-09 06:02
(checking now locally)

matt.fellows
2022-03-09 06:03
Yes, I also get this. I?ll find the source of the problem now

matt.fellows
2022-03-09 06:07
found it, I?ll submit a PR now


artur
2022-03-09 06:13
thx for the quick fix

matt.fellows
2022-03-09 06:14
Np. Might take a little bit to release and propagate into the libs, but will tap Ron on the shoulder tomorrow at standup.

annette.reid
2022-03-09 07:43
has joined #pact-js


sebastianman45
2022-03-09 15:51
has joined #pact-js

victor.lau
2022-03-09 20:46
has joined #pact-js

qluck
2022-03-09 21:41
Hi all! I'm trying to find a good way to debug my tests in Intellij. Does anyone have a run configuration or any general tips of how to set this up? I haven't been able to hit a single breakpoint in any of my tests. Thanks in advance!

uglyog
2022-03-09 22:18
Might be easier to use Visual Studio Code. It is very easy to setup debugging with that.

qluck
2022-03-09 22:47
ok, thanks

kenneth.krause
2022-03-10 16:41
has joined #pact-js

caiquedpfc
2022-03-10 19:14
Hello everyone, how are you? I have generated a contract using pact-js in my consumer for a GraphQL API, but I?m getting an error when I try to verify this contract with pact-very or with pact-python in my provider, I believe this is an error with my contract the error I?m getting when I try to verify this contract is `GraphQL operations must contain a non-empty query or a persistedQuery` anyone knows how to solve this? I?m sharing my contract bellow and the code I?m using to generate the contract

caiquedpfc
2022-03-10 19:14
follow my contract bellow: ```{ "consumer": { "name": "courier-phoenix" }, "provider": { "name": "courier-api" }, "interactions": [ { "description": "A request with a new show case", "request": { "method": "POST", "path": "/public-api", "headers": { "content-type": "application/json" }, "body": { "operationName": "loadNewShowCase", "query": "query loadNewShowCase($filter: ShowCaseFilter) {\n loadNewShowCase(filter: $filter) {\n messages {\n category\n target\n key\n message\n }\n showCase {\n images\n shelves {\n id\n type\n displayName\n hasNextItems\n items {\n id\n type\n images\n displayName\n applicableDiscount {\n presentedDiscountValue\n discountType\n finalValue\n }\n category {\n id\n displayName\n }\n brand {\n id\n displayName\n }\n price {\n min\n max\n }\n }\n }\n }\n }\n}\n", "variables": { } }, "matchingRules": { "$.body.query": { "match": "regex", "regex": "query\\s*loadNewShowCase\\(\\$filter:\\s*ShowCaseFilter\\)\\s*\\{\\s*loadNewShowCase\\(filter:\\s*\\$filter\\)\\s*\\{\\s*messages\\s*\\{\\s*category\\s*target\\s*key\\s*message\\s*\\}\\s*showCase\\s*\\{\\s*images\\s*shelves\\s*\\{\\s*id\\s*type\\s*displayName\\s*hasNextItems\\s*items\\s*\\{\\s*id\\s*type\\s*images\\s*displayName\\s*applicableDiscount\\s*\\{\\s*presentedDiscountValue\\s*discountType\\s*finalValue\\s*\\}\\s*category\\s*\\{\\s*id\\s*displayName\\s*\\}\\s*brand\\s*\\{\\s*id\\s*displayName\\s*\\}\\s*price\\s*\\{\\s*min\\s*max\\s*\\}\\s*\\}\\s*\\}\\s*\\}\\s*\\}\\s*\\}\\s*" } } }, "response": { "status": 200, "headers": { "Content-Type": "application/json; charset=utf-8" }, "body": { "data": { "loadNewShowCase": { "messages": null, "showCase": { "images": [ ], "shelves": [ { "id": "31239bf8-e8d8-4893-a3de-7e5316a8e6fd", "type": "BILLBOARD", "displayName": "Destaques", "hasNextItems": false, "items": [ { "id": "b7566f41-db87-4b03-bef2-4531a5b6de50", "type": "BANNER", "images": [ "https://courier-images-frontrelease.imgix.net/banner/b7566f41-db87-4b03-bef2-4531a5b6de50_180cab5b-ae61-4b28-9b6e-2124815cf974.jpg" ], "displayName": "TESTEQA10", "applicableDiscount": null, "category": null, "brand": null, "price": null } ] } ] } } }, "default": { "data": { "loadNewShowCase": { "messages": null, "showCase": { "images": [ ], "shelves": [ { "id": "31239bf8-e8d8-4893-a3de-7e5316a8e6fd", "type": "BILLBOARD", "displayName": "Destaques", "hasNextItems": false, "items": [ { "id": "b7566f41-db87-4b03-bef2-4531a5b6de50", "type": "BANNER", "images": [ "https://courier-images-frontrelease.imgix.net/banner/b7566f41-db87-4b03-bef2-4531a5b6de50_180cab5b-ae61-4b28-9b6e-2124815cf974.jpg" ], "displayName": "TESTEQA10", "applicableDiscount": null, "category": null, "brand": null, "price": null } ] } ] } } } } }, "matchingRules": { "$.body": { "match": "type" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

caiquedpfc
2022-03-10 19:17
And the code to generate the contract is: ```import { ApolloGraphQLInteraction, Matchers, Pact } from '@pact-foundation/pact' import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client' import * as loadNewShowCaseExpectedResponse from './mocks/loadNewShowCase.json'; import { showCase } from '../../../src/services/api/showcase'; import { print } from 'graphql' import fetch from 'cross-fetch' import path from 'path'; jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000; const PORT = 20002; describe("Show Case", () => { const provider = new Pact({ port: PORT, log: path.resolve(process.cwd(), "aut-tests/contract/logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "aut-tests/contract/pacts"), spec: 2, logLevel: 'DEBUG', pactfileWriteMode: "overwrite", consumer: "courier-phoenix", provider: "courier-api", }) beforeAll(() => provider.setup()); afterAll(() => provider.finalize()); describe("Load New Show Case", () => { beforeEach(() => { const graphqlQueryInteraction = new ApolloGraphQLInteraction() .uponReceiving("A request with a new show case") .withRequest({ path: "/public-api", method: "POST", }) .withOperation("loadNewShowCase") .withQuery(print(gql`query loadNewShowCase($filter: ShowCaseFilter) {${showCase}}`)) .withVariables({}) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: Matchers.like(loadNewShowCaseExpectedResponse) }); return provider.addInteraction(graphqlQueryInteraction) }) test("returns correct body, header and statusCode", async() => { const client = new ApolloClient({ cache: new InMemoryCache({ addTypename: false }), link: new HttpLink({ uri: `${provider.mockService.baseUrl}/public-api`, fetch }), }) let response = client .query({ query: gql`query loadNewShowCase($filter: ShowCaseFilter) { ${showCase} }` }) response = await response.then((result: any) => { result.data expect(result.data).toEqual(loadNewShowCaseExpectedResponse) }) .catch( error => { return error }) }) afterEach(() => provider.verify()) }) })```

bergner
2022-03-11 06:19
has joined #pact-js

harwin1494
2022-03-11 06:24
Hello all! I am working on writing test for 'register user' scenario, whose request takes parameters as firstname, lastname, emailaddress. I created a consumer test with specific request parameter values for example: firstname - 'Testfirstname' lastname - 'Testlastname' emailaddress - '' In the interaction file that was generated, the above values get hardcoded. Hence while running the test at Provider side, the test passes for first time but fails later , because the user with same emailaddress cannot be created due to conflict. Is there any way to avoid hardcoding of user details in pact file or make these values unique each time it is run at Provider end?

matt.fellows
2022-03-11 06:25
Are you running your tests against a live provider?

harwin1494
2022-03-11 06:25
eventually they would be

matt.fellows
2022-03-11 06:25
oh, don?t do that. That?s not ideal

matt.fellows
2022-03-11 06:26
You want to be able to run the provider tests against a locally spun up version of the provider that can control its own data

harwin1494
2022-03-11 06:26
like a virtualization server?

matt.fellows
2022-03-11 06:26
no, like in a dev environment

matt.fellows
2022-03-11 06:26
e.g. `npm start` with dependencies mocked

matt.fellows
2022-03-11 06:27
1. Start dev server 2. Run pact tests 3. shutdown dev server 4. [if on CI] publish verification results 5. [if on CI] run can-i-deploy 6. [if on CI and 5 passes] deploy

matt.fellows
2022-03-11 06:27
general workflow for a pact project

harwin1494
2022-03-11 06:27
okay, but is there any way to achieve the uniqueness in case of email-ids getting generated everytime we run the consumer?

harwin1494
2022-03-11 06:28
any randomized function or something like that?

matt.fellows
2022-03-11 06:53
Why is it a problem though? If you run it in a unit-test like context, the data is clean so there shouldn?t be conflicts

matt.fellows
2022-03-11 06:53
also, there are hooks (see the docs) that can fire pre/post test you can use to clear out any state in the database (if necessary) to achieve the same thing

matt.fellows
2022-03-11 06:54
If I said you needed to randomise an email address in your unit test email validation procedure because the email address already existed, you would likely tell me that something is wrong with my unit test. That?s essentially the mindset to bring to this problem

gotax80534
2022-03-11 06:55
has joined #pact-js

mathias
2022-03-11 10:17
has joined #pact-js

harwin1494
2022-03-11 10:57
This sounds right, thanks for clarifying Matt.

jtcsek
2022-03-11 13:02
has joined #pact-js

alanbos
2022-03-12 15:24
Hi I'm running the latest Pactv3 beta pact-js consumer and the mocked server is returning null for a response body property based on `arrayContaining` - there are other properties using that matcher which are working fine. Is this a known issue, or is there something in the logs I should be looking for to give me a clue?

matt.fellows
2022-03-12 21:22
If you could please set log level to debug and share we could take a look

alanbos
2022-03-12 23:08
Thanks Matt I'll simplify the pact as much as possible and post the debug on Monday. Incidentally hit an issue with the date(pattern, value) matcher in Pactv3 js beta where the mock server always returns todays date rather the value I specify as the 2nd arg.

matt.fellows
2022-03-13 02:27
Thanks. I'll take a look at the date matcher next time I'm in there

joachim005
2022-03-14 08:16
has joined #pact-js

alexstout009
2022-03-14 14:32
has joined #pact-js

paul.richards
2022-03-14 14:38
has joined #pact-js

akif.tahir
2022-03-14 15:00
has joined #pact-js

lramos
2022-03-14 16:29
has joined #pact-js

michael036
2022-03-14 18:31
has joined #pact-js

lauren.coggin
2022-03-14 19:27
has joined #pact-js

mkanika1811
2022-03-15 09:22
has joined #pact-js

ian.pringle
2022-03-15 11:02
has joined #pact-js

karl.wagner
2022-03-15 12:25
has joined #pact-js

chaitasi.patel988
2022-03-16 04:04
has joined #pact-js

mathias
2022-03-16 08:05
@mathias has left the channel

jose.iglesias
2022-03-16 09:23
has joined #pact-js

alanbos
2022-03-16 10:12
Hi Matt - having narrowed things down a bit I think the issue might be due to nested arrayContaining. This is the query: ```query badQuery($id: ID!) { foo(id: $id) { bar { results { __typename } } } }``` This is the expectation: ```foo: { bar: arrayContaining( { results: arrayContaining({ __typename: equal('Result') }) } ) }``` This is the debug level log: ```[2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.variables [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.variables.id [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $ [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.__typename [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results[*] [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.results[*].__typename [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Skipping the matching rule (skip_matchers == true) [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar[*] [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Configuring a normal object [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Path = $.data.foo.bar[*].results [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] detected pact:matcher:type, will configure a matcher [2022-03-16T10:07:04Z DEBUG pact_ffi::mock_server::bodies] Skipping the matching rule (skip_matchers == true) [2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Updated catalogue entries: core/interaction/http core/interaction/https [2022-03-16T10:07:04Z DEBUG 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 [2022-03-16T10:07:04Z DEBUG 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 [2022-03-16T10:07:04Z DEBUG pact_mock_server::mock_server] Started mock server on 127.0.0.1:65384 [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::io] parsed 7 headers [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::conn] incoming body is content-length (178 bytes) [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::conn] incoming body completed [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Creating pact request from hyper request [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Extracting query from uri /graphql [2022-03-16T10:07:04Z INFO pact_mock_server::hyper_server] Received request HTTP Request ( method: POST, path: /graphql, query: None, headers: Some({"host": ["127.0.0.1:65384"], "content-type": ["application/json"], "content-length": ["178"], "user-agent": ["node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"], "accept": ["*/*"], "connection": ["close"], "accept-encoding": ["gzip", "deflate"]}), body: Present(178 bytes, application/json) ) [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] body: '{"operationName":"badQuery","variables":{"id":"1"},"query":"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"}' [2022-03-16T10:07:04Z INFO pact_matching] comparing to expected HTTP Request ( method: POST, path: /graphql, query: None, headers: Some({"Content-Type": ["application/json"]}), body: Present(178 bytes, application/json) ) [2022-03-16T10:07:04Z DEBUG pact_matching] body: '{"operationName":"badQuery","query":"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}","variables":{"id":"1"}}' [2022-03-16T10:07:04Z DEBUG pact_matching] matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {DocPath { path_tokens: [Root, Field("variables"), Field("id")], expr: "$.variables.id" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }, PATH: MatchingRuleCategory { name: PATH, rules: {} }} } [2022-03-16T10:07:04Z DEBUG pact_matching] generators: Generators { categories: {} } [2022-03-16T10:07:04Z DEBUG pact_matching::matchers] String -> String: comparing '/graphql' to '/graphql' using Equality (false) [2022-03-16T10:07:04Z DEBUG pact_matching] expected content type = 'application/json', actual content type = 'application/json' [2022-03-16T10:07:04Z DEBUG pact_matching] content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }' [2022-03-16T10:07:04Z DEBUG pact_plugin_driver::catalogue_manager] Looking for a content matcher for application/json [2022-03-16T10:07:04Z DEBUG pact_matching] No content matcher defined for content type 'application/json', using core matcher implementation [2022-03-16T10:07:04Z DEBUG pact_matching] Using body matcher for content type 'application/json' [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $ [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_maps: Comparing maps at $: {"operationName": String("badQuery"), "query": String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"), "variables": Object({"id": String("1")})} -> {"operationName": String("badQuery"), "query": String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"), "variables": Object({"id": String("1")})} [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.operationName [2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"badQuery"' to '"badQuery"' using Equality -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("badQuery")' to 'String("badQuery")' at path '$.operationName' -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.query [2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"' to '"query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}"' using Equality -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}")' to 'String("query badQuery($id: ID!) {\n foo(id: $id) {\n bar {\n results {\n __typename\n }\n }\n }\n}")' at path '$.query' -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.variables [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_maps: Comparing maps at $.variables: {"id": String("1")} -> {"id": String("1")} [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare: Comparing path $.variables.id [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Calling match_values for path $.variables.id [2022-03-16T10:07:04Z DEBUG pact_matching::json] JSON -> JSON: Comparing '"1"' to '"1"' using Type -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching::json] compare_values: Comparing 'String("1")' to 'String("1")' at path '$.variables.id' -> Ok(()) [2022-03-16T10:07:04Z DEBUG pact_matching] --> Mismatches: [] [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] Test context = {"mockServer": Object({"href": String("http://127.0.0.1:65384"), "port": Number(65384)})} [2022-03-16T10:07:04Z INFO pact_mock_server::hyper_server] Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(43 bytes, application/json) ) [2022-03-16T10:07:04Z DEBUG pact_mock_server::hyper_server] body: '{"data":{"foo":{"bar":[{"results":null}]}}}' [2022-03-16T10:07:04Z DEBUG hyper::proto::h1::io] flushed 355 bytes [2022-03-16T10:07:04Z INFO pact_mock_server::mock_server] Writing pact out to 'C:\Dev\git_repos\apps\case_notes_on_the_go\pacts\ena-app-apigateway.json' [2022-03-16T10:07:04Z DEBUG pact_models::pact] Merging pact with file "C:\\Dev\\git_repos\\apps\\case_notes_on_the_go\\pacts\\ena-app-apigateway.json" [2022-03-16T10:07:04Z WARN pact_models::pact] Note: Existing pact is an older specification version (V3), and will be upgraded [2022-03-16T10:07:04Z DEBUG pact_mock_server::server_manager] Shutting down mock server with port 65384 [2022-03-16T10:07:04Z DEBUG pact_mock_server::server_manager] Shutting down mock server with port 65384 - MockServerMetrics { requests: 1 } [2022-03-16T10:07:04Z DEBUG pact_mock_server::mock_server] Mock server cf98a3b4-4aa0-4836-8bcb-9f144d34a04b shutdown - MockServerMetrics { requests: 1 } [2022-03-16T10:07:04Z DEBUG hyper::server::shutdown] signal received, starting graceful shutdown Error: expect(received).resolves.toEqual(expected) // deep equality - Expected - 5 + Received + 1 Object { "foo": Object { "bar": Array [ Object { - "results": Array [ - Object { - "__typename": "Result", - }, - ], + "results": null, }, ], }, }```

alegab0710
2022-03-16 10:20
has joined #pact-js

matt.fellows
2022-03-16 10:24
Thanks. It looks to be returning `{"data":{"foo":{"bar":[{"results":null}]}}}` despite the nested `arrayContaining`

matt.fellows
2022-03-16 10:25
Could you please raise the bug at https://github.com/pact-foundation/pact-js/issues/ and we?ll get it looked into? I can?t tell from here if the issue is in Pact JS or the (rust) core.

matt.fellows
2022-03-16 10:25
Suspect core, at this stage

alanbos
2022-03-16 10:48
OK thanks - will do


matt.fellows
2022-03-16 11:16
Awesome, thanks

serghei.pogodin
2022-03-16 12:31
has joined #pact-js

jeremy.vincent
2022-03-16 14:29
has joined #pact-js

1.g10squad
2022-03-16 16:01
has joined #pact-js

alistair.c.kung
2022-03-16 18:44
has joined #pact-js

adam.howard
2022-03-17 02:05
has joined #pact-js

jonatan.jaworski
2022-03-17 02:32
has joined #pact-js

lewis.greenway-jones
2022-03-17 08:52
has joined #pact-js

pierre.gerard
2022-03-17 11:59
has joined #pact-js

viswanathan.sarma
2022-03-17 22:39
has joined #pact-js

madhulika.mitra
2022-03-18 15:56
has joined #pact-js

peter.pinda
2022-03-21 02:56
Hey guys, I am getting these response from API: This response going to be always like this (much more items). Notice certain slug wont have subfields(null)... looking into the matchers knowing Pact is not supporting optional fields.... is there any recommended way I can follow ? Thanks ```[ { "slug": "with-fields", "subFields":[ { "name":"name", "required":true } ] }, { "slug":"without-fields", "subFields":null } ]``` PS: I know based on slug which item has fields and which doesn't

matt.fellows
2022-03-21 05:43
You need to write two separate tests: one with the optional fields set and another without

matt.fellows
2022-03-21 05:43
You could also consider the use of the `arrayContaining` matcher in the v3 beta release

peter.pinda
2022-03-21 06:44
Thanks @matt.fellows

rupam.saha
2022-03-21 09:26
has joined #pact-js

christian.jeppesen
2022-03-21 10:10
has joined #pact-js

anand.kannan
2022-03-21 10:10
has joined #pact-js

mikhail.yartsev
2022-03-21 10:10
has joined #pact-js

mircea.ungureanu
2022-03-21 13:29
Good afternoon, I?m getting this error and not sure how to get past it `: Timeout - Async callback was not invoked within the 15000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 15000 ms timeout specified by jest.setTimeout.Error:` I tried increasing the jest timeout but no luck, it?s failing on the `return await p.verify();` as it?s an open handle and keeping jest from exiting. Has anyone encountered this before? I?ve sent my access token and url env vars.

mircea.ungureanu
2022-03-21 14:53
This is now resolved, it was a timeout problem.

bblechman
2022-03-21 16:36
has joined #pact-js

jeffrey2011998
2022-03-22 09:22
has joined #pact-js

xavier.arque
2022-03-22 11:33
has joined #pact-js

bernard
2022-03-22 13:40
Hi I'm running my Pact tests inside a docker container. And I'm having trouble running a basic Pact test. ```test(`makes a request`, async () => { jest.setTimeout(30000); // Arrange const expectedResult = `Hello World`; await mockProvider.addInteraction({ state: `foo exists`, uponReceiving: `a request to get foo`, withRequest: { method: `GET`, path: `/foo` }, willRespondWith: { status: 200, headers: { "Content-Type": regex({ generate: `text/plain`, matcher: `text/plain;?.*` }) }, body: like(expectedResult) } }); const request = await http://axios.post( `${mockProvider.mockService.baseUrl}/foo` ); console.log(request); });``` My Pact logs are: ```I, [2022-03-22T13:37:53.003897 #348] INFO -- : Registered expected interaction GET /foo W, [2022-03-22T13:38:22.980712 #348] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /foo W, [2022-03-22T13:38:22.980965 #348] WARN -- : Missing requests: GET /foo I, [2022-03-22T13:38:23.015926 #348] INFO -- : Cleared interactions``` Any ideas?? Do I need to expose a port on my container???

yousafn
2022-03-22 14:21
You are making a post request to your mock server but have registered an expectation of a GET request. You should be testing your client in your application which inside it, would call out to the providing service. You would traditionally set up your api interface so that you can pass in the provider service base url, and with pact you would pass in the mock providers base url to the api client. Hope that makes sense!

aubrey
2022-03-22 14:32
has joined #pact-js

balazs
2022-03-22 15:51
has joined #pact-js

agustin.gomes
2022-03-22 17:23
Hello everyone, I'm trying to setup a small Typescript project to use Pact, The test is setup as follows: ? a Docker container with the app and the test ? a separate Docker container where the mock server is running It seems that PactJS assumes I want to setup the mock server in the same place as the app, which is not possible since Ruby is not installed. Is there a way around it? If I do cURL from the app container, I get this: ```docker-compose run --rm node-cli curl -X GET pact-mock-provider:1234 Creating rover_node-cli_run ... done {"message":"No interaction found for GET /","interaction_diffs":[]} ``` But if I run the tests, I get the following: ```docker-compose run --rm node-cli npm run test:mocha:consumer Creating rover_node-cli_run ... done > test:mocha:consumer > mocha src/consumer.spec.ts [2022-03-22 17:21:28.234 +0000] INFO (18 on node-cli): pact-node@10.17.2: Creating Pact Server with options: {"timeout":30000,"consumer":"testingConsumer","cors":false,"dir":"/opt/project/roverctl/pacts","host":"pact-mock-provider","log":"/opt/project/roverctl/stderr","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"testingProvider","spec":2,"ssl":false,"port":1234,"pactFileWriteMode":"overwrite"} (node:18) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) GraphQL example 1) "before all" hook in "GraphQL example" [2022-03-22 17:21:28.248 +0000] ERROR (18 on node-cli): pact@9.17.3: The pact mock service doesn't appear to be running - Please check the logs above to ensure that there are no pact service startup failures - Please check that pact lifecycle methods are called in the correct order (setup() needs to be called before this method) - Please check that your test code waits for the promises returned from lifecycle methods to complete before calling the next one - To learn more about what is happening during your pact run, try setting logLevel: 'DEBUG' 2) "after all" hook in "GraphQL example" 0 passing (11ms) 2 failing 1) GraphQL example "before all" hook in "GraphQL example": Error: listen EADDRNOTAVAIL: address not available 172.28.0.4:1234 at Server.setupListenHandle [as _listen2] (node:net:1355:21) at listenInCluster (node:net:1420:12) at GetAddrInfoReqWrap.doListen (node:net:1559:7) at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:74:8) 2) GraphQL example "after all" hook in "GraphQL example": Error: The pact mock service wasn't running when finalize was called at Pact.finalize (node_modules/@pact-foundation/src/httpPact.ts:183:9) at Context.<anonymous> (src/consumer.spec.ts:33:26) at processImmediate (node:internal/timers:466:21)```

agustin.gomes
2022-03-22 17:25
I must mention that I'm fairly new to the JS ecosystem, so apologies in advance if I missed anything seemingly obvious. Also, I used the graphql example to set up the node app part: https://github.com/pact-foundation/pact-js/tree/master/examples/graphql

seasharp37
2022-03-22 22:17
has joined #pact-js

matt.fellows
2022-03-23 02:24
You don?t need Ruby to run Pact. It?s bundled in the npm package and should be invisible to you

matt.fellows
2022-03-23 02:24
I wouldn?t recommend this setup

matt.fellows
2022-03-23 02:24
Why did you think you needed ruby?

saritacutinha
2022-03-23 07:09
has joined #pact-js

agustin.gomes
2022-03-23 08:43
The errors I was getting hinted me in that direction. In any case, I'm happy to report I managed to make it work, but instead the `new Pact` used in the graphQL example I linked, I used `new PactWeb` and it worked nicely with the rest of the example. Thank you for your feedback so far @matt.fellows

matt.fellows
2022-03-23 08:48
hmm that?s strange

matt.fellows
2022-03-23 08:48
you shouldn?t need to use PactWeb, and we?re currently planning on decommissioning/stop support for it going forward

matt.fellows
2022-03-23 08:49
That would indicate there are issues starting the mock server - it could even be a port conflict

matt.fellows
2022-03-23 08:49
setting log level to debug and sharinsg the output might be helpful

rachelb
2022-03-23 10:16
has joined #pact-js

agustin.gomes
2022-03-23 14:01
> it could even be a port conflict I think it's unlikely. The mock server is brought up outside the node ecosystem. From this part of the message I posted above: ```Error: listen EADDRNOTAVAIL: address not available 172.28.0.4:1234``` I get the feeling Node is trying to start the server without checking if the server is already reachable.

agustin.gomes
2022-03-23 14:02
> setting log level to debug and sharinsg the output might be helpful I'll try to recreate the situation further.

agustin.gomes
2022-03-23 14:04
> you shouldn?t need to use PactWeb, and we?re currently planning on decommissioning/stop support for it going forward The `PactWeb` I'm refering still part of the `@pact-foundation/pact` package, not the `@pact-foundation/pact-web`

edouard.lopez
2022-03-23 16:51
Could you elaborate on the use case for using matcher in the request definition (e.g. `withRequest`). We are in the process of deploying Pact internally and people are this for the wrong reason (e.g. copy/pasting code) https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js#L180

david.uzumaki
2022-03-23 19:32
hi @caiquedpfc for your graphql api provider, is the actual query string being sent when you try to verify the pact? I wrote a consumer test and I?m trying to setup a provider for graphql queries but when investigating the response to my local provider endpoint, It seems pact doesn?t actually send the graphql query string? not sure if it?s me or that?s intended behaviour

david.uzumaki
2022-03-23 19:33
At the end of the day it?s just a post request with data but the data doesn?t seem to contain the actual query string from the pact file

david.uzumaki
2022-03-23 19:34
an example interaction in the pact file: ```"interactions": [ { "description": "blah blah", "providerState": "blah blah", "request": { "method": "post", "path": "/v1/graphql/", "headers": { "Content-Type": "application/json", "Authorization": "eyJ..." }, "body": { "query": "some query" <--- this isn't being sent to the provider when attempting to verify with provider } },```

david.uzumaki
2022-03-23 19:35
did you ever encounter this issue? @caiquedpfc

matt.fellows
2022-03-23 21:27
> The mock server is brought up outside the node ecosystem. the port conflict has nothing to do with where the conflict happens - in or out or node

matt.fellows
2022-03-23 21:27
I?d like to see your configuration for Pact vs how you are starting the mock server yourself

matt.fellows
2022-03-23 21:28
This looks like a different internal network. Are you hard coding the port to `1234` ? If so, you need to make sure you can a) bind to that port b) it?s free and c) the address you want to bind is corrrect. `172.28.0.4:1234` Looks like you?re not using dynamic port allocation (i.e. you?re hard coding `1234` as the port). Drop the hard coding and it should pick a random free one for you

matt.fellows
2022-03-23 21:29
It?s rarely needed IRL

matt.fellows
2022-03-23 21:29
I?d not use it unless you must

matt.fellows
2022-03-23 21:29
I think it?s there, because in this e2e it shows most of the ways you can use all of the things

shaheen
2022-03-23 23:11
has joined #pact-js

edouard.lopez
2022-03-24 10:28
Thanks, that remove the doubts I had

bernard
2022-03-24 11:52
:wave: Hi, I'm seeing this on a passing test. ```pact-node@10.17.2: Pact Binary Error: WARN: No content type found, performing text diff on body``` Any ideas? After a google search I wasn't able to work out how to remove this error from the output of the test run.

sentyaev
2022-03-24 12:36
has joined #pact-js

altan.demirkiran
2022-03-24 14:06
has joined #pact-js

matt.fellows
2022-03-24 20:45
You should explicitly set the `content-type` header

matt.fellows
2022-03-24 20:45
(on the request/response, whichever is not being set on)

jonathan.fortunati
2022-03-24 21:53
has joined #pact-js

simon.dicola
2022-03-25 10:25
has joined #pact-js

mrooschuz
2022-03-25 14:52
has joined #pact-js

ashok.pathak
2022-03-25 15:17
has joined #pact-js

rdanthuluri
2022-03-27 03:28
has joined #pact-js

rdanthuluri
2022-03-27 04:09
Hi Team . i am trying to implement pact test with type script. i am facing below issue . could u please help me to resolve the issue

matt.fellows
2022-03-27 04:14
Based on that, it looks like you're not sending the request to the actual mock service. It's probably still sending requests to the real service

rdanthuluri
2022-03-27 04:20
this is my spec.ts file

rdanthuluri
2022-03-27 04:21
can you please give me some details on mock service

matt.fellows
2022-03-27 04:32
Please review and then provide the log file

rdanthuluri
2022-03-27 04:35
Sure Matt. thank you

cudi.unal
2022-03-28 11:25
has joined #pact-js

ashraf.anwar.iw
2022-03-28 13:12
has joined #pact-js

b.costa
2022-03-28 13:15
has joined #pact-js

mark.hopper
2022-03-28 14:53
has joined #pact-js

mark.hopper
2022-03-28 14:57
~Good afternoon all, I was wondering if someone could help me? I?m trying to get the angular side of our pact tests running in a Gitlab CI/CD Docker Container based off the Node Alpine image (node:17-alpine). I?ve already followed the various threads and ensured that relevant dependencies (such as bash) are installed as part of the pipeline. When it runs, I?m seeing this error Error: Error: connect ECONNREFUSED ::1:2754 ? I?ve ran it in Trace Logging mode and it would appear that the mock service is running ? is there any hints or tips someone could give me to try and diagnose this?~ I ended up changing it from http://localhost:2754 to http://127.0.0.1:2574 and this is now working

ashraf.anwar
2022-03-28 15:08
has joined #pact-js

agustin.gomes
2022-03-28 15:51
Hi Matt, here is the docker-compose I'm using: ```services: app: build: context: /home/agustingomes/pact-project-poc dockerfile: ./.docker/Dockerfile.node.alpine container_name: contract-test environment: PACT_CONSUMER_NAME: instapro-client PACT_MOCK_SERVER_HOST: 127.0.0.1 PACT_MOCK_SERVER_PORT: '1234' PACT_PROVIDER_NAME: pocProvider hostname: contract-test network_mode: host volumes: - /home/agustingomes/pact-project-poc/contract-tests-poc:/var/www/html:rw working_dir: /var/www/html pact-mock-provider: command: > mock-service --port 1234 --host 0.0.0.0 --pact-dir=/tmp/pacts --consumer=pocConsumer --provider=pocProvider --log=/tmp/pacts/mock-provider.log --log-level=debug --pact-specification-version=2.0.0 --pact-file-write-mode=overwrite container_name: pact-mock-provider expose: - '1234' hostname: pact-mock-provider image: pactfoundation/pact-cli:0.50.0.19 ports: - published: 1234 target: 1234 volumes: - /home/agustingomes/pact-project-poc/pacts:/tmp/pacts:rw working_dir: /pact version: '3.8'``` I start the Mock provider with: ```docker-compose up -d pact-mock-provider``` And then, I run the test via the `app` service I defined in my docker-compose: ```docker-compose run --rm app npm run test:contract``` And finally, this is how the provider in the test is set up: ```import { PactWeb } from "@pact-foundation/pact/src/pact-web" . . . const provider = new PactWeb({ host: process.env.PACT_MOCK_SERVER_HOST || "", port: parseInt(process.env.PACT_MOCK_SERVER_PORT || ""), log: "stderr", logLevel: "debug", }) . . .``` With this setup, I am able to generate the contract: ``` > mocha src/consumer.spec.ts Setting up Pact using mock service on port: "1234" (node:18) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) GraphQL login login via /graphql ? returns a valid token 1 passing (27ms)``` Let me know if I can provide you more details

damianruizdev
2022-03-28 18:44
has joined #pact-js

david.uzumaki
2022-03-28 19:32
update: I realised it sends a second request to the real provider endpoint with the body in that data there in addition I?ve opted to have my pact tests completely ignore my authorization middleware those are handled by other integration tests

damianruizdev
2022-03-28 19:35
Hey everyone, our company is currently trying to integrate Pact into our nx monorepo and we keep running into errors when trying to run the tests. Was curious if anyone has ever integrated Pact into an nx monorepo that uses angular, jest, and cypress. The initial error we're running into is jest and cypress types clashing when running the Pact test. Our monorepo is configured to support both jest/cypress and we have jest tests in other libs that run fine so not sure what about Pact is causing this behavior. (edited)

yousafn
2022-03-28 19:40
Hey @damianruizdev, I've not used nx before but I also maintain a couple of cypress packages and have had people with nx monorepos having various issues raised on my projects I know there is at least one user with nx in pact-js https://github.com/pact-foundation/pact-js/issues/731#issuecomment-900786756, they are on our v3 version, but haven't seen much else If you have some time to setup a repro project, it would be interesting to identify if the test run fine in `nx` without cypress, if so, then it may just be a typescript config issue,

sebastianman45
2022-03-28 19:59
Hello Team :wave::sunglasses:, a question, I am trying to run my pact project on a mac machine with big sur 11.6.2 operating system, and I am having problems on the provider side, pact throws a generic error, I have not found the possible cause; the log is the following, Do you know why it could have this behavior?:

sebastianman45
2022-03-28 19:59
the complete log is above: ```[2022-03-28 19:31:45.402 +0000] INFO (96647 on WM-C02DX5CZMD6T): pact@10.0.0-beta.56: Verifying provider [2022-03-28 19:31:45.409 +0000] INFO (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Verifying Pacts. [2022-03-28 19:31:45.410 +0000] INFO (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Verifying Pact Files [2022-03-28 19:31:45.410 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Initalising native core at log level 'debug' [2022-03-28 19:31:45.412 +0000] WARN (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Ignoring option 'consumerVersionTags' because it is invalid without 'pactBrokerUrl' also being set. This may indicate an error in your configuration [2022-03-28 19:31:45.412 +0000] WARN (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: Ignoring option 'publishVerificationResult' because it is invalid without 'pactBrokerUrl' also being set. This may indicate an error in your configuration [2022-03-28 19:31:45.414 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: sending arguments to FFI: [2022-03-28 19:31:45.415 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: --request-timeout 30000 --loglevel debug --state-change-url http://localhost:60534/_pactSetup --provider-tags QA --provider-version 1.0.0 --port 60534 --hostname localhost --provider-name getidentityProvider --file /Users/jsuarezp/tr/__tests__/contract/pacts/getidentityConsumer-getidentityProvider.json RUNS __tests__/contract/provider/identity/get.identity.provider.spec.js [2022-03-28T19:31:45Z DEBUG pact_ffi::verifier::verifier] Pact source to verify = File(/Users/jsuarezp/tr/__tests__/contract/pacts/getidentityConsumer-getidentityProvider.json) [2022-03-28T19:31:45Z DEBUG 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 [2022-03-28T19:31:45Z DEBUG 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 RUNS __tests__/contract/provider/identity/get.identity.provider.spec.js thread '<unnamed>' panicked at 'Client::new(): reqwest::Error { kind: Builder, source: MissingOrMalformedExtensions }', /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/reqwest-0.11.9/src/async_impl/client.rs:1263:38 [2022-03-28 19:31:46.106 +0000] DEBUG (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: response from verifier: null, 3 [2022-03-28 19:31:46.107 +0000] ERROR (96647 on WM-C02DX5CZMD6T): pact-core@13.4.1-beta.13: !!!!!!!!! PACT CRASHED !!!!!!!!! The underlying pact core crashed in an unexpected way. This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it. There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the full output. SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world. We're sorry about this! FAIL __tests__/contract/provider/identity/get.identity.provider.spec.js Validate pact of identity ? validate the pact of an identity get (706 ms) ? Validate pact of identity ? validate the pact of an identity get Pact Verification FAIL!: Get identity 22 | console.log('Pact Verification Complete!: Get identity ', res); 23 | }).catch((res) => { > 24 | throw new Error('Pact Verification FAIL!: Get identity ', res); | ^ 25 | }); 26 | }) 27 | at __tests__/contract/provider/identity/get.identity.provider.spec.js:24:23```

damianruizdev
2022-03-28 20:31
Awesome, thanks yousaf! I'll look into this tomorrow and get back to you :slightly_smiling_face:

matt.fellows
2022-03-28 21:54
Look, you can do it that way, but as I said, we?re going to be removing the `PactWeb` interface going forward, and it?s a clumsy setup. I?d like to know why you need to manually run the mock service and you can?t just run the tests

matt.fellows
2022-03-28 21:54
if you could share a reproducible code base, I could run it to see why it doesn?t work

matt.fellows
2022-03-28 21:55
You can do what you?re doing above, I?m just giving you the forewarning that it means you will unlikely be able to upgrade to the next major release without rework

matt.fellows
2022-03-28 21:59
Ah, I think this is related to an invalid certificate in your chain


matt.fellows
2022-03-28 22:01
It looks like it?s still not released yet, but when it is it will resolve this issue

matt.fellows
2022-03-28 22:02
for now, there is a certificate in your chain somewhere that is invalid, you?ll need to find which one it is and remove/fix it

agustin.gomes
2022-03-29 08:06
> if you could share a reproducible code base, I could run it to see why it doesn?t work I will put together the example I have. Will do it in 2 commits. the first one with `PactWeb`, and the second with `Pact`.

matthew.churcher
2022-03-29 08:48
has joined #pact-js

matt.fellows
2022-03-29 09:28
Thanks!

matt.fellows
2022-03-29 09:28
note I?m off for a few days, but if you raise an issue at the pact-js repo I can take a look when back (or another maintainer might be able to check also)

agustin.gomes
2022-03-29 13:03
no rush. Enjoy your days off @matt.fellows and thanks for bearing with me :raised_hands:

ben.brugman
2022-03-29 14:32
has joined #pact-js

hassan.shaikley
2022-03-29 16:14
has joined #pact-js

oakkub.1995
2022-03-30 07:10
has joined #pact-js

adrian.ernst.lgln
2022-03-30 13:03
Hello everyone im currently writing a pact test for an endpoint that returns a file i want to download. I can't seem to find a matcher for binary data and adding binary to Matchers.somethinglike() doesnt seem to work. Is the right practice here to just not add a body to the willRespondWith Object?

sebastianman45
2022-03-30 14:34
Thank you very much, Matt :raised_hands:, checking I have several expired certificates on my machine, I will manage them and validate it again

hiqbal
2022-03-30 15:16
has joined #pact-js

sstenhouse
2022-03-30 15:16
has joined #pact-js

bmeyres
2022-03-30 17:37
has joined #pact-js

sebastianman45
2022-03-30 18:18
Hello Team :wave::sunglasses:, one question, is Pact js V3 already compatible with jest?, I am trying to use `stateHandlers` with `(setup, parameters)` but the value of these parameters is undefined, I want to do something like this: (I'm using the 10.0.0-beta.58 version of pact), thanks :raised_hands::

alejandro.velez
2022-03-30 18:42
has joined #pact-js

justin
2022-03-30 20:07
has joined #pact-js

matt.fellows
2022-03-30 21:42
Check out the latest v3 beta

matt.fellows
2022-03-30 21:42
But if you want to do a type match on binary just drop the payload and look at the headers only

rdanthuluri
2022-03-30 22:05
Hi Team

rdanthuluri
2022-03-30 22:05
my js file is having one test when i run the test to generate contract is failing at after each hook

rdanthuluri
2022-03-30 22:06
consumer@1.0.0 pacts C:\UIEN-Local\pact-test\pact-test > mocha --recursive "tests/*.pact.js" --timeout 100000 [2022-03-30T22:04:07.287Z] INFO: pact-node@10.9.4/13532 on PC0X2B10: Creating Pact Server with options: {"consumer":"React","cors":false,"dir":"C:\\UIEN-Local\\pact-test\\pact-test\\pacts","host":"127.0.0.1","log":"C:\\UIEN-Local\\pact-test\\pact-test\\logs\\pact.log","pactFileWriteMode":"overwrite","port":1234,"provider":"token","spec":2,"ssl":false} Consumer Test [2022-03-30T22:04:08.891Z] INFO: pact@9.11.0/13532 on PC0X2B10: Setting up Pact with Consumer "React" and Provider "token" using mock service on Port: "1234" ? OK response Pact verification failed! Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /modules See C:/UIEN-Local/pact-test/pact-test/logs/pact.log for details. (node:13532) UnhandledPromiseRejectionWarning: AssertionError: expected 'OK ' to equal 'OK' at C:\UIEN-Local\pact-test\pact-test\tests\consumer.pact.js:55:47 at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:13532) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:13532) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. 1) "after each" hook for "OK response" [2022-03-30T22:04:08.973Z] INFO: pact@9.11.0/13532 on PC0X2B10: Pact File Written [2022-03-30T22:04:08.973Z] INFO: pact-node@10.9.4/13532 on PC0X2B10: Removing Pact process with PID: 9936 [2022-03-30T22:04:09.152Z] INFO: pact-node@10.9.4/13532 on PC0X2B10: Deleting Pact Server with options: {"consumer":"React","cors":false,"dir":"C:\\UIEN-Local\\pact-test\\pact-test\\pacts","host":"127.0.0.1","log":"C:\\UIEN-Local\\pact-test\\pact-test\\logs\\pact.log","pactFileWriteMode":"overwrite","port":1234,"provider":"token","spec":2,"ssl":false} 1 passing (2s) 1 failing 1) Consumer Test "after each" hook for "OK response": Error: Pact verification failed - expected interactions did not match actual. at new VerificationError (node_modules\@pact-foundation\pact\errors\verificationError.js:19:42) at C:\UIEN-Local\pact-test\pact-test\node_modules\@pact-foundation\pact\httpPact.js:102:23 at processTicksAndRejections (internal/process/task_queues.js:97:5) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! consumer@1.0.0 pacts: `mocha --recursive "tests/*.pact.js" --timeout 100000` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the consumer@1.0.0 pacts script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\radha.danthuluri\AppData\Roaming\npm-cache\_logs\2022-03-30T22_04_09_197Z-debug.log

rdanthuluri
2022-03-30 22:07
please suggest how to resolve this error

matt.fellows
2022-03-30 22:48
9 times out of ten this is because you're not sending requests to the pact mock server

leo.adriano1994
2022-03-31 00:00
has joined #pact-js

hitesh.patadia
2022-03-31 04:27
has joined #pact-js

matt.cockayne
2022-03-31 11:02
has joined #pact-js

jimmy
2022-03-31 15:39
has joined #pact-js

bret.mcclory538
2022-04-01 01:10
has joined #pact-js

michael.d
2022-04-01 04:40
has joined #pact-js

yash.deole
2022-04-01 07:07
has joined #pact-js

matt.fellows
2022-04-01 07:58
@artur sorry for the delay. This should have your fixes

alan.alie
2022-04-01 08:10
has joined #pact-js

jimmy
2022-04-01 08:11
@jimmy has left the channel

alan.alie
2022-04-01 10:09
Hi all, I?ve previously written pact tests using *axios* as the http handler but the consumer app itself uses *fetch* (from node-fetch) instead. I?ve tried to switch to using fetch but hit problems. I understand that using *jest-pact* is a possible solution so I?ve implemented the following example: ```import { URL } from 'url'; import { Matchers } from '@pact-foundation/pact'; import { HTTPMethod } from '@pact-foundation/pact/src/common/request'; import { pactWith } from 'jest-pact'; import fetch from 'node-fetch'; jest.setTimeout(30000); pactWith({ consumer: 'aggregator', provider: 'theme_provider' }, (provider) => { describe('Theme related end points', () => { it('Request to save themes', async () => { const url = new URL(`${provider.mockService.baseUrl}/themes-service/themes`); const { validateExample } = Matchers; const interaction = { state: 'Request to save themes', uponReceiving: 'Request to save themes', withRequest: { method: http://HTTPMethod.POST, path: url.pathname, headers: { Accept: 'application/json' }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: { results: [{ handle: 'abc', result: 'Created' }], }, }, }; await provider.addInteraction(interaction); const result = await fetch(`${provider.mockService.baseUrl}/themes-service/themes`, { method: http://HTTPMethod.POST, headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }); expect(await result.json()).toEqual({ results: [ { handle: 'abc', result: 'Created', }, ], }); }); }); });``` Unfortunately, I get the following error: ``` FAIL __pact__/fetch2.pact.spec.ts (10.793 s) Pact between aggregator and theme_provider with 30000 ms timeout for Pact Theme related end points ? Request to save themes (59 ms) ? Pact between aggregator and theme_provider ? with 30000 ms timeout for Pact ? Theme related end points ? Request to save themes FetchError: invalid json response body at reason: Unexpected end of JSON input 42 | }); 43 | > 44 | expect(await result.json()).toEqual({ | ^ 45 | results: [ 46 | { 47 | handle: 'abc', at node_modules/cross-fetch/node_modules/node-fetch/lib/index.js:273:32 at Object.<anonymous> (__pact__/fetch2.pact.spec.ts:44:20)``` If I remove `await` from the offending line of code then the test fails because the response promise never gets fulfilled :confused: ``` FAIL __pact__/fetch2.pact.spec.ts (12.368 s) Pact between aggregator and theme_provider with 30000 ms timeout for Pact Theme related end points ? Request to save themes (65 ms) ? Pact between aggregator and theme_provider ? with 30000 ms timeout for Pact ? Theme related end points ? Request to save themes expect(received).toEqual(expected) // deep equality - Expected - 8 + Received + 1 - Object { - "results": Array [ - Object { - "handle": "abc", - "result": "Created", - }, - ], - } + Promise {} 42 | }); 43 | > 44 | expect(result.json()).toEqual({ | ^ 45 | results: [ 46 | { 47 | handle: 'abc', at Object.<anonymous> (__pact__/fetch2.pact.spec.ts:44:35)``` What am I missing or overlooking? I'd be really grateful for any assistance on this problem :slightly_smiling_face:

matt.fellows
2022-04-01 10:18
What do the mock server logs say they received?

matt.fellows
2022-04-01 10:19
It's possible cors is the issue

alan.alie
2022-04-01 10:27
Hi Matt, not sure where to find the logs for the mock server.

alan.alie
2022-04-01 10:27
Is that the `pact.log` file?

alan.alie
2022-04-01 10:46
I've added the following to the provider setup ``` log: path.resolve(process.cwd(), '__pact__/logs', 'pact-fetch.log'), logLevel: 'debug', cors: true,``` ....and the output looks like this ``` FAIL __pact__/fetch2.pact.spec.ts (10.086 s) Pact between aggregator and theme_provider with 30000 ms timeout for Pact Theme related end points ? Request to save themes (84 ms) ? Pact between aggregator and theme_provider ? with 30000 ms timeout for Pact ? Theme related end points ? Request to save themes expect(received).toEqual(expected) // deep equality - Expected - 8 + Received + 1 - Object { - "results": Array [ - Object { - "handle": "abc", - "result": "Created", - }, - ], - } + Promise {} 51 | }); 52 | > 53 | expect(result.json()).toEqual({ | ^ 54 | results: [ 55 | { 56 | handle: 'abc', at Object.<anonymous> (__pact__/fetch2.pact.spec.ts:53:39)``` ....and the `pact.log` file looks like this ```I, [2022-04-01T11:43:11.829104 #62695] INFO -- : Registered expected interaction POST /themes-service/themes D, [2022-04-01T11:43:11.829281 #62695] DEBUG -- : { "description": "Request to save themes", "providerState": "Request to save themes", "request": { "method": "POST", "path": "/themes-service/themes", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "results": [ { "handle": "abc", "result": "Created" } ] } }, "metadata": null } W, [2022-04-01T11:43:11.844186 #62695] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /themes-service/themes W, [2022-04-01T11:43:11.844236 #62695] WARN -- : Missing requests: POST /themes-service/themes I, [2022-04-01T11:43:11.895725 #62695] INFO -- : Cleared interactions```

alan.alie
2022-04-01 10:54
I've located the mock server log aggregator-theme_provider-mockserver-interaction.log and it has the following ```W, [2022-04-01T11:03:36.800180 #58467] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /themes-service/themes W, [2022-04-01T11:03:36.800294 #58467] WARN -- : Missing requests: POST /themes-service/themes```

alan.alie
2022-04-01 11:25
I've set `cors` to both *true* and *false* with no effect :confused:


alan.alie
2022-04-01 11:28
@matt.fellows is it possible that the json response data isn't being extracted from the promise correctly?

rdanthuluri
2022-04-01 11:53
Thanks Matt for the response

ricardo.cruz
2022-04-01 11:54
has joined #pact-js

thomas.fisher
2022-04-01 12:15
has joined #pact-js

lauren.corderoy
2022-04-01 12:24
has joined #pact-js

jiayao.xu
2022-04-01 12:24
has joined #pact-js

bret.mcclory538
2022-04-01 14:36
@bret.mcclory538 has left the channel

shiva.velde0413
2022-04-01 14:44
has joined #pact-js

damianruizdev
2022-04-01 17:54
Hey everyone, happy Friday! Do we know if anyone has ever integrated Pact testing into an NX monorepo with Cypress and Jest?

matt.fellows
2022-04-01 22:07
That error is pretty clear - the fetch call didn't send the request to the expected path. My guess is it's something to do with running fetching in a node process

artur
2022-04-04 04:05
thank you that unblocks me

npc1222
2022-04-04 04:37
has joined #pact-js

artur
2022-04-04 05:45
with https://github.com/pact-foundation/pact-js/releases/tag/v10.0.0-beta.59 it seems not to be possible to have in one interaction multiple provider states with the same name. That was possible in .36. Is that a bug or a feature? My use-case is to create multiple files. So I call multiple times ` ```provider.given('file exists', { username, password, fileName: resource })``` but in the JSON I only have one providerstate with that name ``` "providerStates": [ { "name": "the user is recreated", "params":... }, { "name": "file exists", "params": { "fileName": "testFolder/??.txt", "password": "test123", "username": "test123" } }, { "name": "resource is shared", "params": ... } ]``` Making the names of provider states individual makes them appear in the JSON, but that would mean I would also have to have an individual state definition in the provider tests (stateHandlers)

matt.fellows
2022-04-04 05:47
hmmm it seems like that would have been a bug in the core that has been resolved (I don?t know why/where just yet). The name of the state I think needs to be unique

matt.fellows
2022-04-04 05:47
@uglyog is my assumption correct? If not, I?ll see if I can track down where that assumption is built in code (whether JS or somewhere else)

uglyog
2022-04-04 05:49
It may have been an accidental feature, I don't recall doing that by design

matt.fellows
2022-04-04 05:49
Should it be possible to have multiple provider states with the same description (but different params?)

uglyog
2022-04-04 05:50
But then it has been a while, and maybe I just don't recall what I was doing back then

matt.fellows
2022-04-04 05:50
I assume not

artur
2022-04-04 05:51
if the same description is not allowed, then my tests cannot have just arbitrary filenames, but the names have to be part of the description, or some kind of counter is needed

uglyog
2022-04-04 05:51
The provider states are not keyed, so you could have multiple in the Pact file with the same description. I don't know what the effect will be. But I assume it will just loop though the list and call the handler based on the name

artur
2022-04-04 05:52
that would be my expectation

uglyog
2022-04-04 05:52
Just checked Pact-JVM, uniqueness is description + parameters

matt.fellows
2022-04-04 05:53
Cool. I'll see if I can track down where the issue is

matt.fellows
2022-04-04 05:53
It might be there is a keyed state somewhere so it's overridden

matt.fellows
2022-04-04 05:53
Your use case makes sense actually

artur
2022-04-04 05:55
the stateHandler on the provider side is happy with the same names, just loops. So the issue is on the side of writing to the JSON

bernard
2022-04-04 08:38
Looking at the output below... Is this because there are no verification tests for the provider? So the can-i-deploy says no. ``` View the published pact at https://grabyo-test.pactflow.io/pacts/provider/studio-backend/consumer/studio-frontend/version/b5309ddca0%2B1648824839 Events detected: contract_published (pact content is the same as previous version with tag PLAT-1697-pact-demo and no new tags were applied), contract_requiring_verification_published (pact content is the same as previous version with tag PLAT-1697-pact-demo and no new tags were applied) Next steps: * Add Pact verification tests to the studio-backend build. See https://docs.pact.io/go/provider_verification * Configure separate studio-backend pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks ========== STAGE: can-i-deploy? ========== Computer says no ¯_(?)_/¯ No pacts or verifications have been published for version b5309ddca0+1648824845 of studio-frontend```

alan.alie
2022-04-04 08:48
Hi @matt.fellows, is this a known issue between pact-js and fetch? Any other advice on how to proceed with this issue?

bernard
2022-04-04 09:18
Thanks!

matt.fellows
2022-04-04 09:24
I'm not aware of any issues

matt.fellows
2022-04-04 09:24
If you could pls create a repro we can take a look

matt.fellows
2022-04-04 09:27
The version is different between publish and deploy

matt.fellows
2022-04-04 09:29
You're asking to deploy a version of the consumer Pactflow doesn't know about

bernard
2022-04-04 09:30
How can I get Pactflow to know about it?

matt.fellows
2022-04-04 09:31
By publishing a pact for it!

bernard
2022-04-04 09:31
I can see this in the output... ```Pact successfully published for studio-frontend version b5309ddca0+1649064121 and provider studio-backend.```

matt.fellows
2022-04-04 09:31
I think you have a flaw in your pipeline the version is not deterministic

matt.fellows
2022-04-04 09:32
Yes, but look at the version. It's different when you call can I deploy

bernard
2022-04-04 09:32
Ah I see, I'll take a look at that.

matt.fellows
2022-04-04 09:32
So you publish for one version and then ask to deploy another. Hence the output

matt.fellows
2022-04-04 09:32
:+1:

bernard
2022-04-04 09:39
Do you have any idea why the commit would change? I'm using a Makefile and the command I'm running to get the Git commit is: ```GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s````

bernard
2022-04-04 09:47
Thanks @matt.fellows I've fixed it.

alan.alie
2022-04-04 09:56
Hi @matt.fellows Looks like we got to the bottom of our problem with using fetch and pact-js.

alan.alie
2022-04-04 09:59
It turns out that, in the unit tests, we're using *jest-fetch-mock* so our pact tests were calling a mocked fetch to begin with.

alan.alie
2022-04-04 10:00
In our pact tests we've added the following lines to disable *fetchMock*: ```import fetchMock from 'jest-fetch-mock'; ... ... beforeAll(async () => { fetchMock.disableMocks(); }); afterAll(async () => { fetchMock.enableMocks(); });```

matt.fellows
2022-04-04 10:10
Yeah it's not the commit, it's the datetime format

matt.fellows
2022-04-04 10:10
Glad to hear

matt.fellows
2022-04-04 10:10
Ha, yes that'll do it :rolling_on_the_floor_laughing:

arthur
2022-04-04 14:28
has joined #pact-js

arthur
2022-04-04 14:33
hi, i have a few questions / thoughts regarding GraphQL contract testing with Pact (JS), and was wondering whether this would be a good place to put them, or whether another channel might be preferred?

yousafn
2022-04-04 15:50
Here is good @arthur

yousafn
2022-04-04 15:50
and welcome

arthur
2022-04-04 15:52
thanks

arthur
2022-04-04 16:00
we're looking at using Pact to give us nice test separation between our front-end clients and our back-end, which provides a GraphQL API for them to use. at the moment, from having experimented with the GraphQLInteraction class in the Pact JS library, it appears as if fairly complete GraphQL query strings need to be provided in order for the Pact mock API server to return the correct response. i have managed to get this working by formatting the query in precisely the right way (e.g. `... on` rather than `...on`, etc.), according to the GraphQL client library we are using (urql), but i feel that this approach seems a little brittle currently. IMO, with GraphQL, the 'contract' is the strongly-typed schema the technology provides, rather than the precise way in which a client interacts with it. putting this another way, if i make a small change to the query a given client makes, i don't feel that should be regarded as a change of contract, yet so far as i can see, this is how the Pact GraphQLInteraction stuff is currently set up. i was wondering whether, rather than providing a full GraphQL query string, it would be possible to build some sort of strongly-typed schema-based resolver for providing the mock API functionality? this could leverage existing tools (e.g. https://www.graphql-code-generator.com), and still capture interactions for playback against the server logic (in the spirit of Pact), but the developer experience might be somewhat nicer and more idiomatic.

arthur
2022-04-04 16:01
we use TS, and the technology for providing strongly-typed GraphQL resolver functions based on the API schema exists, so i think it would be 'possible', however i'm not sure whether this really fits with the philosophy of Pact.

arthur
2022-04-04 16:02
i would be very interested in hearing any thoughts about this.

agastiya.mohammad
2022-04-05 01:19
has joined #pact-js

matt.fellows
2022-04-05 02:07
Yes

matt.fellows
2022-04-05 02:07
Pact is a specification by example testing framework

matt.fellows
2022-04-05 02:08
I don?t see Pact ever supporting the kind of proposal you have, but I do see that as a viable approach for the bi-directional contract testing feature of Pactflow

matt.fellows
2022-04-05 02:08
What you?re proposing is more of a schema comparison approach, which is different to the way Pact works and will likely ever work

paul.stapleton
2022-04-05 07:33
has joined #pact-js

arthur
2022-04-05 08:09
thanks for your thoughts. given what you say, it sounds like Pact might not be quite the right tool for testing GraphlQL APIs in this way.

arthur
2022-04-05 08:10
i may look into building something more well-suited to its features.

matt.fellows
2022-04-05 08:17
no problems

matt.fellows
2022-04-05 08:17
It?s something we?ll explore for sure in Pactflow

matt.fellows
2022-04-05 08:17
I?d also suggest having a read of https://pactflow.io/blog/schemas-are-not-contracts/ so you can understand the challenges in your approach

matt.fellows
2022-04-05 08:18
(It?s not to say you shouldn?t do it, but just be aware of the elements of contract testing you?ll miss out on)

arthur
2022-04-05 08:21
i will, thanks. i think the main issue i can see with regarding a specific example as canonical is that in GraphQL, it's possible for a client to request things such as field name mappings (e.g. 'firstName' from 'name'), and i see these as not fundamentally changing the contract between the two systems; they're really just metadata of a request.

arthur
2022-04-05 08:22
in practical terms, these sorts of things would normally be handled by the GraphQL server library in use (e.g. Apollo), so application code would not be affected by a change of field name mapping, ergo regarding it as a different example would seem wrong.

matt.fellows
2022-04-05 09:12
Can you please elaborate on this? How does the evolution of this happen? So a provider can rename a field and old referencew are resolved by Apollo?


arthur
2022-04-05 09:49
when consuming a GraphQL API, consumers can describe the 'shape' of the data they want to be returned

arthur
2022-04-05 09:49
this includes the selection and names of fields, as well as more complex things

arthur
2022-04-05 09:51
if, for some reason, a given consumer wants to change the name of a field it receives from the API (as with the name->firstName example i gave earlier), this is something which would be transparent to the provider implementation

arthur
2022-04-05 09:51
as typically it would be handled entirely by GraphQL server libraries such as Apollo

arthur
2022-04-05 09:53
my point is that this sort of consumer-specific change is not a change of contract, IMO, but the string-matching approach taken by GraphQLInteraction in Pact JS currently regards it as such.

iurisoares1012
2022-04-05 09:53
has joined #pact-js

gocool9996
2022-04-05 10:04
has joined #pact-js

matt.fellows
2022-04-05 10:22
> if, for some reason, a given consumer wants to change the name of a field it receives from the API (as with the name->firstName example i gave earlier), this is something which would be transparent to the provider implementation I don?t see how this wouldn?t break any type of contract. Either, the provider has the field or it doesn?t. If it gets renamed in the process by the consumer, sure, that?s up to them and is outside the scope of any contract test (Pact included)

matt.fellows
2022-04-05 10:23
But I think you?re saying, in GraphQL you can change the query which affects the client side (e.g. a field alias). That?s an unfortunate side effect of Pact?s approach, yes

arthur
2022-04-05 10:25
yes; in practical terms, if i write a test that causes a client to make a GraphQL API call which is subsequently mocked / stubbed / recorded by Pact, this is effectively a snapshot of the actual text of the query, which feels brittle to me for the reasons i've outlined.

arthur
2022-04-05 10:25
a subsequent change to that query which has no practical impact on any other system should not then be regarded as a change of contract, IMO.

matt.fellows
2022-04-05 10:26
I think that?s fair, but it?s hard to make Pact perfect in this case to suit all types of APIs

arthur
2022-04-05 10:26
or more accurately, i think that currently Pact does not support GraphQL in an idiomatic way

matt.fellows
2022-04-05 10:26
I think this is an edge case that is more of a theoretical issue than a real one.

matt.fellows
2022-04-05 10:26
> or more accurately, i think that currently Pact does not support GraphQL in an idiomatic way this is definitely true

matt.fellows
2022-04-05 10:27
I would prefer to see us properly handle the AST rather than the current string based approach

matt.fellows
2022-04-05 10:27
https://github.com/pact-foundation/pact-plugins will be where this gets properly solved

matt.fellows
2022-04-05 10:27
This will be a content type plugin

arthur
2022-04-05 10:28
interesting - i think we already have the tooling required to support this sort of behaviour, though i'm not 100% sure how well this would fit with the recording of a given interaction.

arthur
2022-04-05 10:28
there's a slight tension between the requirement to mock a GraphQL API in an elegant way, and the recording of a specific interaction for playback against a provider

matt.fellows
2022-04-05 10:29
Yes, we?re not a general ?take a schema, make a mock server? tool

arthur
2022-04-05 10:29
no, i understand that

matt.fellows
2022-04-05 10:29
Oh, totally, just agreeing with you :stuck_out_tongue:

arthur
2022-04-05 10:30
i've built something which pretty much does exactly that with our schema, but i was particularly interested in using Pact to avoid the horror of full-stack / 'E2E' tests (and for a few other reasons)

arthur
2022-04-05 10:32
i'll have a think about whether i want to separate out the concerns of automated front-end testing and 'pure' API testing, as i think this may go some way towards solving this slight messiness

arthur
2022-04-05 10:33
my main concern with the former being conciseness, elegance and expressiveness for developers, and with the latter being precision / correctness, i think.

arthur
2022-04-05 10:33
anyway, thanks for your thoughts, i'll stop taking up your time now!

matt.fellows
2022-04-05 10:33
not at all - anytime!

matt.fellows
2022-04-05 10:33
this is helpful for me/us as we look to solving GraphQL better going forward

arthur
2022-04-05 10:34
well, we do quite a bit of automated testing with TS and a GraphQL API from various clients, so by all means yell if you want to chat about anything. I'm no expert in GraphQL (which is a *deep* technology), but i've encountered quite a lot of the common 'gotchas', i think

bernard
2022-04-05 15:22
Hi, I'm testing against the latest stubs after my provider has published a contract. And I'm seeing this in the logs. Stub URL: ```https://<our domain>.http://pactflow.io/pacts/provider/<provider>/consumer/<consumer>/latest/stub/``` Logs: ```I, [2022-04-05T15:18:42.151021 #53] INFO -- : Registered expected interaction POST /api/v2/login W, [2022-04-05T15:18:43.517983 #53] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /api/v2/login``` The tests fail on: ```await mockProvider.verify();```

simrat.sidhu
2022-04-05 16:07
has joined #pact-js

gabriel.brazao
2022-04-05 17:42
has joined #pact-js

jhonataok01
2022-04-05 17:43
has joined #pact-js

andre.mariano
2022-04-05 19:10
has joined #pact-js

alex.zuliqiaer
2022-04-05 20:31
has joined #pact-js

lflores
2022-04-05 20:33
has joined #pact-js

matt.fellows
2022-04-05 21:02
the stubs aren?t for use during your contract tests, you use the local mock server for that

keoma4
2022-04-05 21:17
has joined #pact-js

matt.fellows
2022-04-05 21:36
stubs are for use cases outside of Pact directly (e.g. cypress browser tests)

erick.belf
2022-04-05 21:46
has joined #pact-js

michaele
2022-04-06 03:40
has joined #pact-js

brendan.j.donegan
2022-04-06 07:42
I've just found out one of our teams went off and used Spring Cloud Contract without asking, is there an easy way to get them converted to Pact I can point them to?

matt.fellows
2022-04-06 07:44
I don?t think so, but that?s an interesting question

matt.fellows
2022-04-06 07:45
are they writing it in groovy?

brendan.j.donegan
2022-04-06 07:45
Haven't looked yet :see_no_evil:

brendan.j.donegan
2022-04-06 07:46
Also any easy blurb I can give them as to why they shouldn't be using SCC :grinning:

brendan.j.donegan
2022-04-06 07:47
Realizing this is in the wrong channel too, should have been in #pact-jvm

matt.fellows
2022-04-06 07:52
ah, that?s why I was asking about Groovy - I think if you do use SCC outside of JVM, it?s a bit different

brendan.j.donegan
2022-04-06 07:53
No it's a Springboot project

bernard
2022-04-06 09:54
Oh, I see.

matt.fellows
2022-04-06 10:13
May I ask what gave you the impression they were for use in Pact unit tests?

matt.fellows
2022-04-06 10:13
We might need to address our documentation

artur
2022-04-06 10:44
any news on this? Should I create an issue to track it?

matt.fellows
2022-04-06 11:05
yes please!

guillaume.camus
2022-04-06 12:47
has joined #pact-js

danielglazer123
2022-04-06 19:06
has joined #pact-js

ashish.goyal
2022-04-06 23:14
has joined #pact-js

pennellbeth
2022-04-07 08:04
has joined #pact-js

dominic.gara
2022-04-07 08:57
has joined #pact-js

ivan.cheung
2022-04-07 08:58
has joined #pact-js

omrieyal
2022-04-07 08:58
has joined #pact-js

drakulavich
2022-04-07 08:58
has joined #pact-js

jonoar22
2022-04-07 09:06
has joined #pact-js

josh.king
2022-04-07 09:06
has joined #pact-js

pitas01_lope
2022-04-07 09:35
has joined #pact-js

rarestomos
2022-04-07 09:40
has joined #pact-js

shuba.paripoornam
2022-04-07 09:59
has joined #pact-js

shivam.kumar
2022-04-07 11:00
has joined #pact-js

bernard
2022-04-07 12:39
It just wasn't clear that they shouldn't be used for them.

bernard
2022-04-07 12:39
This was helpful: stubs are for use cases outside of Pact directly (e.g. cypress browser tests)

matt.fellows
2022-04-07 12:58
Thanks Bernard - I think we?ll clarify that on the page. Apologies for the confusion (and also - thanks for coming along and I hope the webinar was helpful!)

dgupta2
2022-04-07 13:26
has joined #pact-js

pankajarora512
2022-04-07 22:50
has joined #pact-js

aruncontacts
2022-04-07 22:54
has joined #pact-js

mira.kim
2022-04-07 23:59
has joined #pact-js

bernard
2022-04-08 10:22
It was helpful, really informative and much simpler to understand and convey to other colleagues afterwards.

bernard
2022-04-08 10:32
:wave: I'm having some issues with an interceptor in Cypress. Route matcher ```POST **/api/v2/login (stubbed) Yes (alias) login (count) -``` The request ```POST https://<our domain>.http://pactflow.io/pacts/provider/<our provider>/consumer/<our consumer>/latest/stub/api/v2/login``` The Cypress test ```const loginResponse = require(`../../../fixtures/login.json`); describe(`Login API`, () => { Cypress.config({ defaultCommandTimeout: 120000 }); beforeEach(() => { cy.intercept( { method: `POST`, url: `**/api/v2/login` }, { statusCode: 200, body: { ...loginResponse }, headers: { "access-control-allow-origin": `*` } } ).as(`login`); <----- The alias cy.visit(`/`); cy.setupPact(`<our consumer>`, Cypress.env(`PACT_PROVIDER`)); }); it(`should log into Studio Frontend`, () => { cy.login( `/api/v2/login`, `user`, `password` ); }); after(() => { cy.usePactWait(`login`); <---- This doesn't match the route }); });``` The error ```Error: CypressError: Timed out retrying after 5000ms: `cy.wait()` timed out waiting `5000ms` for the 1st request to the route: `login`. No request ever occurred.```

alphonse.bendt
2022-04-08 11:44
has joined #pact-js

wim.dupont
2022-04-08 11:49
has joined #pact-js

yousafn
2022-04-08 13:02
Hey @bernard! Thanks for trying out the adapter. What does your `cy.login` method look like? Are you making a a `cy.request` call via your customer `cy.login` method? If so, you would wish to use `cy.usePactRequest` https://github.com/pactflow/pact-cypress-adapter#cyusepactrequestoption-alias-and-cyusepactgetalias--alias

bernard
2022-04-08 13:25
@yousafn My `login` command looks like... ```Cypress.Commands.add(`login`, (api, user, passphrase) => { cy.request({ method: `POST`, url: `${Cypress.env(`PACT_PROVIDER_STUB_URL`)}${api}`, body: { user, passphrase }, headers: { Authorization: `Bearer ${Cypress.env(`PACT_PROVIDER_TOKEN`)}`, Accept: `application/json, text/plain, */*` } }); });```

wilsonmar
2022-04-08 13:41
has joined #pact-js

bernard
2022-04-08 14:05
@yousafn refactored it based on the document you sent over. It's working now. The Pact file is being written. Thanks :pray:

henit.laxmicant
2022-04-08 14:19
has joined #pact-js

yousafn
2022-04-08 14:37
Saweeeeet!

yousafn
2022-04-08 14:38
Props to the author @slin and her documentation :chefkiss:

mateustalles
2022-04-08 17:35
has joined #pact-js

bioflash1
2022-04-11 09:21
has joined #pact-js

artur
2022-04-11 10:27
I'm sometimes getting this error `[2022-04-11T10:08:01Z ERROR pact_js_v3::verify] Verify process failed with a panic: failed printing to stdout: Resource temporarily unavailable (os error 11)` This is with 10.0.0-beta.36 (cannot update currently because of other issues) Any idea what resource could not be availiable?

bernard
2022-04-11 10:41
Hi @yousafn apologies for wrangling your handle. But I have a question. In Cypress can I make a request to the latest stub URL of my integration? And get the OAS schema example for the path back in my response?

yousafn
2022-04-11 12:09
Is there 2 separate questions there? ? In Cypress can I make a request to the latest stub URL of my integration? ? Yes, @lewis.prescott079 made a post recently https://www.pactman.co.uk/post/end-to-end-testing-in-microservices-with-api-contracts ? You can read in also read in a Pact file directly, and strip off the matchers and feed into to cy.route https://gist.github.com/bethesque/a4b117ebb09488c101f88320cac678a4 ? And get the OAS schema example for the path back in my response? ? Not sure I fully understand this? As a response from what?

yousafn
2022-04-11 12:10
Some more info on the first point in our docs https://docs.pact.io/consumer/using_pact_to_support_ui_testing

francislainy.campos
2022-04-11 12:41
Hi, do we have any example on how to use dynamic ids for V3?


matt.fellows
2022-04-11 13:13
hmm that is strange indeed


matt.fellows
2022-04-11 13:14
It seems strange that it would start occurring now though. Perhaps there is an internal inefficiency somewhere in the library

matt.fellows
2022-04-11 13:14
Are you seeing it in CI or locally?

stambolaolya
2022-04-11 13:20
has joined #pact-js

bernard
2022-04-11 13:53
If the provider uses an OAS document which has examples, is it possible to use the latest stub URL as my consumers endpoint. And not have to write Cypress interceptors that make use of fixtures? Instead of using the fixture, I'd like to assert that the response fits the pattern of the OAS response example.

yousafn
2022-04-11 14:03
I don't believe we allow for generating stubs from OAS/Provider Contracts. Sounds like a cool idea though!

bernard
2022-04-11 14:05
It would be helpful. SmartBear through their Swagger Editor provide a stub URL which sends back examples, which I previously used to assert against in my responses.

yousafn
2022-04-11 14:08
Ahh yeah, I can see here https://github.com/OpenAPITools/openapi-generator available in all kinds of flavours of languages > Ada, C# (http://ASP.NET Core, Azure Functions), C++ (Pistache, Restbed, Qt5 QHTTPEngine), Erlang, F# (Giraffe), Go (net/http, Gin, Echo), Haskell (Servant, Yesod), Java (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, Jersey, RestEasy, Play Framework, https://github.com/ProKarma-Inc/pkmst-getting-started-examples, https://vertx.io/, https://camel.apache.org/), Kotlin (Spring Boot, Ktor, Vertx), PHP (Laravel, Lumen, https://github.com/mezzio/mezzio, Slim, Silex, https://symfony.com/), Python (FastAPI, Flask), NodeJS, Ruby (Sinatra, Rails5), Rust (rust-server), Scala (Akka, https://github.com/finagle/finch, https://github.com/lagom/lagom, https://www.playframework.com/, Scalatra) I previously created one for https://github.com/pact-foundation/serverless-offline-pact that you could feed a pact file into and spin up a stub server, and have also hosted stub servers in ECS via a docker container.

yousafn
2022-04-11 14:09
where would this fit on the consumer side, in terms of their testing pyramid/pipeline?

yousafn
2022-04-11 14:10
Feel free to raise an issue on the Pactflow Roadmap buddy https://github.com/pactflow/roadmap#contributing-to-the-roadmap

bernard
2022-04-11 15:28
Sorry for the late reply....

bernard
2022-04-11 15:28
More questions, sorry.....

bernard
2022-04-11 15:29
The interactions in a Pact that I just queried using CURL responded with the responses crafted by interactions created during Unit Tests.

bernard
2022-04-11 15:30
Would you recommend that the responses to an interaction be crafted based on the OAS in Pactflow?

bernard
2022-04-11 15:31
So I create interactions in my unit tests. And in my e2e Cypress tests use the stubs?

souravmalhotra007
2022-04-11 15:56
has joined #pact-js

akshay.nm92
2022-04-11 17:48
has joined #pact-js

yousafn
2022-04-11 18:14
An OAS is just a design spec, so doesn't represent the subset of interactions any one consumer may have with it. I think the stubs made from Pact servers work fine for the _most_ part, however for some e2e cases, I needed more granular control over my mocks, which tools like Wiremock etc provide (response templating). We also used our stubs in a hosted environment (basically a dev environment where our main services lived, but third party dependencies were mocked out) so the PO's could play around with it, without being reliant on everything being up an integrated test env

yousafn
2022-04-11 18:15
I could see value in standing up a OAS stub server from a spec, especially in Pactflow land as you would have confidence that it was tied to a particular build, or environment. Good for for thought anyway

yousafn
2022-04-11 18:18
I used to create pacts in my consumer code, and prior to uploading them, I would run swagger-mock-validator to ensure we didn't upload any Pacts that were garbage. If consumers or providers wanted to make API changes, they would propose it on a feature branch for the docs, and then when a Pact was generated on the same feature branch, it would pull the corresponding openapi spec, and if not one on the branch it would fall back to master. Our providers used the API specs in their AWS API gateways as request/response validators as well, and we weren't overly confident on their test coverage, but testing it against the spec which they used for the validator made sense to us

luxfactaest
2022-04-11 18:25
has joined #pact-js

cameron.allan
2022-04-12 00:15
has joined #pact-js

artur
2022-04-12 03:21
in CI only so far. I guess it could be also some weird issue with the CI worker.

artur
2022-04-12 03:22
But if that is not an error pact is really throwing I guess there is not much that can be done for now

matt.fellows
2022-04-12 03:23
maybe, it seems strange it?s only showing up for you now. If we can prove it?s Pact JS we can definitely look at it.

artur
2022-04-12 03:27
I will keep an eye on it, I had now 7 runs without that issue

kendrickbong1996
2022-04-12 04:12
has joined #pact-js

timothy.osm
2022-04-12 05:16
has joined #pact-js

pact270
2022-04-12 08:53
has joined #pact-js

francislainy.campos
2022-04-12 12:13
Thank you. I?ll have a look. How long till the v3 version goes past beta, do you know? Also, is it safe to start using it now?

oytun
2022-04-12 13:12
has joined #pact-js

alessandrovermeulen
2022-04-12 14:00
has joined #pact-js

lucka
2022-04-12 15:25
has joined #pact-js

damon_walker
2022-04-12 15:26
has joined #pact-js

sebastianman45
2022-04-12 15:47
Hi guys, good morning :wave:, I want to learn how to use dynamic ids, for this create a dummy example to implement; I want to change a path param in the URL for a specific test case using a GET method; I see that it works fine on the consumer side but not on the provider side , below more details (I'm using version 10.0.0-beta.59)

sebastianman45
2022-04-12 15:50
this is my code for the consumer side: ``` "use strict" const { getRequest } = require("../../../helpers/sendRequest") const identity_data = require("../../data/identity/get.identity.data") const { PactV3, MatchersV3 } = require('@pact-foundation/pact/v3'); const { string, integer, url2, regex, datetime, fromProviderState, like } = MatchersV3; const { createOptsConsumer } = require("../../../helpers/createOpts") const provider = new PactV3(createOptsConsumer(identity_data)); describe("Validate pact of identity", () => { describe("Validate pact get identity", () => { test("Validate successful get of an identity without QR associated", async () => { provider .given('A message with a 200 OK without QR associated', { id: '45' }) .uponReceiving('I want to get a new identity without QR') .withRequest({ method: 'GET', path: fromProviderState('/public/v2/posts/${id}/comments', '/public/v2/posts/100/comments'), headers: { "Content-Type": "application/json", "authorization": `Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730` } }) .willRespondWith({ status: 200, body: [ { "id": 107, "post_id": 100, "name": "Rakesh Nair", "email": "", "body": "Sed vel ad. Ea similique tempora. In a iusto." } ] }); return provider.executeTest(async (mockserver) => { const response = await getRequest(mockserver.url, identity_data.successfulDataWithoutQR.interaction.withRequest); expect(response.status).toEqual(identity_data.successfulDataWithoutQR.interaction.willRespondWith.status) }); }) test("Validate successful get of an identity with QR associated", async () => { provider .given('A message with a 200 OK with QR associated', { id: '50' }) .uponReceiving('I want to get a new identity with QR') .withRequest({ method: 'GET', path: fromProviderState('/public/v2/posts/${id}/comments', '/public/v2/posts/101/comments'), headers: { "Content-Type": "application/json", "authorization": `Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730` } }) .willRespondWith({ status: 200, body: [] }); return provider.executeTest(async (mockserver) => { const response = await getRequest(mockserver.url, identity_data.successfulDataWithQR.interaction.withRequest); expect(response.status).toEqual(identity_data.successfulDataWithQR.interaction.willRespondWith.status) }); }) }) })``` this is the generated pact ``` { "consumer": { "name": "getidentityConsumer" }, "interactions": [ { "description": "I want to get a new identity with QR", "providerState": "A message with a 200 OK with QR associated", "request": { "generators": null, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/101/comments" }, "response": { "body": [], "headers": { "Content-Type": "application/json" }, "status": 200 } }, { "description": "I want to get a new identity without QR", "providerState": "A message with a 200 OK without QR associated", "request": { "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/100/comments" }, "response": { "body": [ { "body": "Sed vel ad. Ea similique tempora. In a iusto.", "email": "", "id": 107, "name": "Rakesh Nair", "post_id": 100 } ], "headers": { "Content-Type": "application/json" }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.0.0-beta.59" }, "pactRust": { "ffi": "0.2.4", "models": "0.3.1" }, "pactSpecification": { "version": "1.1.0" } }, "provider": { "name": "getidentityProvider" } }``` this is my code for the provider side ```"use strict" const { VerifierV3 } = require('@pact-foundation/pact/v3'); const identity_data = require("../../data/identity/get.identity.data") const { createOptsProvider } = require('../../../helpers/createOpts'); describe("Validate pact of identity", () => { it("validate the pact of an identity get", () => { let opts = { consumerVersionTags: ['QA'], providerVersionTags: ['QA'], providerVersion: '1.0.0', providerBaseUrl: 'https://gorest.co.in', changeOrigin: true, logLevel: 'TRACE', provider: 'getidentityProvider', pactUrls: [ 'C:\\pact\\transfers-be-automation-test-pact\\__tests__\\contract\\pacts\\getidentityConsumer-getidentityProvider.json' ], stateHandlers: { 'A message with a 200 OK without QR associated': { setup: (params) => { console.log("Entering to the state"); console.log(params); Promise.resolve({ id: 102 }); } } }, } return new VerifierV3(opts).verifyProvider() .then((res) => { console.log('Pact Verification Complete!: Get identity ', res); }).catch((res) => { throw new Error('Pact Verification FAIL!: Get identity ', res); }); }) })``` the problem is that i want to change (in this dummy example) the url https://gorest.co.in/public/v2/posts/100/comments to https://gorest.co.in/public/v2/posts/102/comments but it doesn't work, maybe you know what i'm doing wrong? :thinking_face:

sebastianman45
2022-04-12 15:51
the complete log:

yousafn
2022-04-12 16:19
Not sure if this is the same in v3, but in v2 you had the ability to set a value in the state handlers, and feed in via request filters https://github.com/pact-foundation/pact-js#modify-requests-prior-to-verification-request-filters see here for some context around when I was trying to access the body https://github.com/pact-foundation/pact-js/issues/304

yousafn
2022-04-12 16:22
This is the section in the docs about it, in v3


sebastianman45
2022-04-12 16:32
thanks @yousafn :grin: for the comment, yep actually I'm following the instructions of the post that you mentioned (https://github.com/pact-foundation/pact-js#request-filters), also I'm implementing something like this https://github.com/pact-foundation/pact-js/tree/feat/v3.0.0/examples/v3/provider-state-injected, but I don't know what is happening jejeje, the id doesn't change

yousafn
2022-04-12 16:35
I will have to test out that example as I haven't tried it out, or really kicked the tyres on v3, been caught up with 101 things!

sebastianman45
2022-04-12 17:12
@yousafn Thank you very much for your help :sunglasses:, I created a repository with the complete implementation of the example, it could be clearer :grin: https://github.com/athan3350/pactjs-implementation

anusha_matti
2022-04-12 18:24
has joined #pact-js

luxfactaest
2022-04-12 20:44
Hello everyone! I have a question about the mock server not starting correctly, throwing a PID: undefined error. One of the projects I'm working on has a functioning Pact suite using 9.11.0 and pact-node 10.9.7, but when I update to pact@latest, the mock server won't spin up, PID: undefined, and an exit code -2. On another project, I'm starting from scratch and have never been able to get the mock server running due to the same issue. Has anyone else had a similar experience, or know how to fix this issue? ```[2022-04-12 20:36:34.329 +0000] INFO (4003 on OF060D556SMD6MH): pact-node@10.17.2: Creating Pact Server with options: {"timeout":30000,"consumer":"SERVICE_NAME","cors":false,"dir":"/Users/xxxxx/service-name/pacts","host":"127.0.0.1","log":"/Users/xxxxx/service-name/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"SERVICE_NAME","spec":2,"ssl":false,"port":5002,"pactFileWriteMode":"overwrite"} [2022-04-12 20:36:34.357 +0000] DEBUG (4003 on OF060D556SMD6MH): pact-node@10.17.2: Starting pact binary '/Users/xxxxx/service-name/node_modules/@pact-foundation/pact/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service', with arguments [service --consumer serviceName --cors false --pact_dir /Users/xxxxx/service-name/pacts --host 127.0.0.1 --log /Users/xxxxx/service-name/logs/pact.log --log-level DEBUG --provider providerServiceName --pact_specification_version 2 --ssl false --port 5002 --pact-file-write-mode overwrite]```

luxfactaest
2022-04-12 20:48
I can provide trace, if that helps (big block of text).

matt.fellows
2022-04-12 21:33
Have you tried the debugging steps in the Pact JS Readme? It should show you how to run the underlying mock service directly, bypassing the JS codebase. If you can run the command with the arguments you can see, it points to some other issue. If it doesn?t run, we can diagnose

matt.fellows
2022-04-12 21:34
Are you on a mac with Rosetta? Have you tried in and outside of rosetta mode?

albert.pincevic
2022-04-12 21:48
has joined #pact-js

luxfactaest
2022-04-12 22:47
I'm on a mac, but no rosetta. I tried the debugging steps. On the project I'm starting Pact from scratch on, the mock server doesn't start up when running directly from the command. On the project with existing Pact that breaks upon updating >9.11.0, the mock-service does run when running from .bin/

luxfactaest
2022-04-12 22:51
We're also using Yarn and TS. Shouldn't matter, but worth mentioning

matt.fellows
2022-04-12 23:24
> I?m on a mac, but no rosetta. I tried the debugging steps. On the project I?m starting Pact from scratch on, the mock server doesn?t start up when running directly from the command. do you get any feedback at all?

matt.fellows
2022-04-12 23:25
is there a ruby runtime embedded in the node_modules directly? If you have `--ignore-scripts` set, that could be why

luxfactaest
2022-04-12 23:25
Not a thing. No error log

matt.fellows
2022-04-12 23:27
strange. I?m guessing the package didn?t install correctly

luxfactaest
2022-04-12 23:28
Does it matter having it in the dev dependencies vs dependencies?

matt.fellows
2022-04-12 23:28
no, that shouldn?t make any difference

matt.fellows
2022-04-12 23:28
I?d expect to see it in devDependencies though

matt.fellows
2022-04-12 23:29
What do you see if you run `cat ./node_modules/.bin/pact-mock-service`

matt.fellows
2022-04-12 23:30
and also `find . -name "pact-mock-service" | grep "pact/bin" | xargs cat`

luxfactaest
2022-04-12 23:32
```#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var pact_standalone_1 = require("../src/pact-standalone"); var cp = require("child_process"); var status = cp.spawnSync(pact_standalone_1.default.mockServiceFullPath, process.argv.slice(2), { stdio: 'inherit' }).status; process.exit(status);```

luxfactaest
2022-04-12 23:33
This returns nothing: ```find . -name "pact-mock-service" | grep "pact/bin" | xargs cat```

luxfactaest
2022-04-12 23:35
No other ruby in this project, and also no `--ignore-scripts`

matt.fellows
2022-04-12 23:42
ok so your install is failing for some reason

luxfactaest
2022-04-12 23:45
```"@pact-foundation/pact-node@^10.17.2": version "10.17.2" resolved "http://npm.companyName.com/@pact-foundation%2fpact-node/-/pact-node-10.17.2.tgz#9fa09cdab8a4a4b83086b174ed6d012bc24e90e7" integrity sha512-RslLuFYItB0uDfKLYXei0ZfAPK0W0nwSwp+Zt7Qyt+Stnea2H4DOucKV03uFSiv3TLVKojut5nF70wfgXyNItQ== dependencies: "@types/needle" "^2.5.1" "@types/pino" "^6.3.5" "@types/q" "1.0.7" "@types/request" "2.48.2" chalk "2.3.1" check-types "7.3.0" cross-spawn "^7.0.1" libnpmconfig "^1.2.1" mkdirp "1.0.0" needle "^2.6.0" pino "^6.11.0" pino-pretty "^4.1.0" q "1.5.1" rimraf "2.6.2" sumchecker "^2.0.2" tar "^6.1.11" underscore "1.12.1" unixify "1.0.0" unzipper "^0.10.10" url-join "^4.0.0" "@pact-foundation/pact@^9.17.3": version "9.17.3" resolved "http://npm.companyName.com/@pact-foundation%2fpact/-/pact-9.17.3.tgz#9621e23e6803385841a3ab29a4162a90b6bcac3e" integrity sha512-AVcScLZsxDDKlO1AuyN7m26Z2EqIt5AA4P8cPGEkokyHf97vbbWlHOPZsgZgzxZXQRnvjNyQnyMwHR69hQ1hew== dependencies: "@pact-foundation/pact-node" "^10.17.2" "@types/bluebird" "^3.5.20" "@types/express" "^4.17.11" bluebird "~3.5.1" body-parser "^1.18.2" cli-color "^1.1.0" es6-object-assign "^1.1.0" es6-promise "^4.1.1" express "^4.17.1" graphql "^14.0.0" graphql-tag "^2.9.1" http-proxy "^1.18.1" lodash "^4.17.21" lodash.isfunction "3.0.8" lodash.isnil "4.0.0" lodash.isundefined "3.0.1" lodash.omit "^4.5.0" lodash.omitby "4.6.0" pino "^6.5.1" pino-pretty "^4.1.0" pkginfo "^0.4.1" popsicle "^9.2.0"```

luxfactaest
2022-04-12 23:52
I did try removing and going for a fresh install `yarn add --dev @pact-foundation/pact` and had no warnings or errors in the install, but I get the same result

matt.fellows
2022-04-12 23:55
are you running a local proxy? I?m wondering if it?s causing issues downloading the CLI (it happens as a postinstall step)

matt.fellows
2022-04-12 23:57
What does this show: ```npm config get ignore-scripts```

luxfactaest
2022-04-12 23:58
That one returns false

luxfactaest
2022-04-13 00:00
We do run a proxy through Spike. Also vpn, of course, but this happens on or off vpn

luxfactaest
2022-04-13 00:02
A little more information: the project that currently runs on 9.11.0 (but not on latest) has this: ``` "config": { "pact_do_not_track": true, "pact_binary_location": "http://artifactory.companyName.com/artifactory/github-dist/pact-foundation/pact-ruby-standalone/releases/download/v1.85.0/" }```

matt.fellows
2022-04-13 00:02
is that the one that works?

luxfactaest
2022-04-13 00:02
right

matt.fellows
2022-04-13 00:03
yeah, so that tells me your proxy is messing with shit

matt.fellows
2022-04-13 00:03
you?ll need that in both projects, or to allow your proxy to fetch the actual assets

matt.fellows
2022-04-13 00:03
FYI the latest beta resolves this issue as it bundles all assets in the npm package, so the proxy issues should go away

luxfactaest
2022-04-13 00:04
Any rough eta on that release? That would help us out a ton

luxfactaest
2022-04-13 00:07
Also, is there a certain Pact version I would need to install to align with the standalone version?

luxfactaest
2022-04-13 00:07
Because...the highest we have stored in our artifactory is 1.88.2

matt.fellows
2022-04-13 00:10
probably a few months I?d say

matt.fellows
2022-04-13 00:10
you can use it now though

luxfactaest
2022-04-13 00:18
Yeah, because I tried adding the line referencing artifactory, removing and re-adding pact, and still no dice on the mock service.

matt.fellows
2022-04-13 00:24
No I'm saying the v3 beta package can be used now

matt.fellows
2022-04-13 00:25
And yes, the version of the standalone needs to match the version in Pact. It's not clearly documented I don't think, let me know the version of Pact you're on and I can let you know

luxfactaest
2022-04-13 00:26
The latest standalone we have is 1.88.2, so maybe whichever version matches that

matt.fellows
2022-04-13 00:27
Ok can do

matt.fellows
2022-04-13 00:28
Ok that's pretty recent, should work with the latest pact JS stable

luxfactaest
2022-04-13 00:32
Installing the beta now to see if that resolves the issue. Unrelated, but I noticed the path to the matchers also changed between 9.11 (whenever that was) and current versions, and I don't think it's documented, or maybe shows the old path in the docs

luxfactaest
2022-04-13 00:32
`./node_modules/.bin/pact-mock-service` spins up the mock server with the beta install :raised_hands:

luxfactaest
2022-04-13 00:35
And the mock server spins up when running the test suite :pray: So glad to see those tests run and fail instead of erroring out.

matt.fellows
2022-04-13 00:39
Argh, so I may have confused you.

matt.fellows
2022-04-13 00:39
The fact it?s working with the new beta is good, but that I think just proves your download settings are working (i.e. those package config settings)

matt.fellows
2022-04-13 00:39
there is a V3 interface is the Pact JS package (beta) that doesn?t use those underlying CLIs at all - it uses a new native rust core.

matt.fellows
2022-04-13 00:40
but the existing V2 (what you?re using now) interface is supported in that package and still uses the CLI tools.

matt.fellows
2022-04-13 00:40
in other words, the latest version of Pact should probably work also

matt.fellows
2022-04-13 00:42
but, great to hear!

luxfactaest
2022-04-13 00:44
So...any pact beta is v3 and should work, and any release version is v2 and probably will not work at all

luxfactaest
2022-04-13 01:04
Or is it that using v3 is optional in the beta release, and v2 is the default? But even if you're using v2 in the beta, it will still work because the cli tools are packaged up with the rest of the bundle?

francislainy.campos
2022-04-13 09:35
Sorry, I tried but couldn?t do. I?m a bit confused perhaps with the Javascript syntax, not sure. Tried to do this for our project with some drafts here https://github.com/francislainy/mbfrontend/blob/master/src/pact/getLocation.pact.spec.js https://github.com/francislainy/mbfrontend/blob/master/src/pact/getLocationV3.pact.spec.js but no success.

matt.fellows
2022-04-13 09:41
What's the issue - is it not being injected on the provider test (I can't see a provider test there)

francislainy.campos
2022-04-13 09:41
No, the provider is java.

francislainy.campos
2022-04-13 09:41
The contract is not generating.

matt.fellows
2022-04-13 09:42
What's the error?

francislainy.campos
2022-04-13 09:43
I think there may be different errors. I?m not a Javascript person and may be mixing up versions and getting the syntax wrong here.

matt.fellows
2022-04-13 09:44
What version of pact do you have installed?

matt.fellows
2022-04-13 09:45
`npm list @pact-foundation/pact`

francislainy.campos
2022-04-13 09:46
```"devDependencies": { "@pact-foundation/pact": "^9.17.2", "@pact-foundation/pact-node": "^10.17.1", "chai": "^4.3.6", "jest-pact": "^0.9.0-beta.v3" }```

francislainy.campos
2022-04-13 09:46
The list command gives me an error.


francislainy.campos
2022-04-13 09:47
The whole project is here.

matt.fellows
2022-04-13 09:47
Ahh, that's wrong dependency if you need V3. You'll need to be on beta (sorry I assumed you must have been on that version because you were asking about V3) https://github.com/pact-foundation/pact-js#pact-js-v3

francislainy.campos
2022-04-13 09:49
I think I had that yet, maybe it got removed once I did some reversions. I?ll add back in again and see what I get when triggering this.

francislainy.campos
2022-04-13 09:57
Did some changes. I think it?s closer now but still not there yet.

matt.fellows
2022-04-13 10:24
is there a reason why you call `getlocation` twice?

matt.fellows
2022-04-13 10:24
Also, does that function send a request with a query string? I can?t see it accepting any params, so just checking

matt.fellows
2022-04-13 10:26
I?m confused as to why the trace logs aren?t showinsg up there which would have (a lot) more detail - maybe Intellij is swallowing the output?

francislainy.campos
2022-04-13 10:26
No, I deleted the first call.

francislainy.campos
2022-04-13 10:27
I get confused with javascript so mixed up two examples together. I get the same error using only the second only though.

matt.fellows
2022-04-13 10:28
`@pact-foundation/pact` (stable) - uses those CLIs to work `@pact-foundation/pact/@beta-x.x.x` (beta) - has two APIs 1. The same as in stable, which still uses those CLIs to operate 2. A new set of APIs (`PactV3`) which uses a new rust core, and supports newer features So basically, the beta is a super set. Additionally, the beta still bundles the CLI tools because it?s a nice feature - e.g. you can then call can-i-deploy, publish etc. without having to install a separate package

francislainy.campos
2022-04-13 10:28
```return provider.executeTest(async (mockserver) => { return getLocation(mockserver.url, '100') .then((result) => { expect(result.title).to.equal('Test'); }); });```

francislainy.campos
2022-04-13 10:28
This is what I have now.

matt.fellows
2022-04-13 10:28
what does `getLocation` look like?

francislainy.campos
2022-04-13 10:28
```exports.getLocation = (basiUrl = BASE_URL, id) => { return axios.request({ method: "GET", baseURL: BASE_URL, url: `${BASE_URL}/api/mb/location/${id}`, headers: {Accept: "application/json"}, }) }```

matt.fellows
2022-04-13 10:29
where is the query string?

francislainy.campos
2022-04-13 10:29
dont? know.. Where it should be?

matt.fellows
2022-04-13 10:30
In your test setup, you?ve told pact that you expect your code to send a request with a query string - but your implementation isn?t sending a query string

francislainy.campos
2022-04-13 10:30
I only need the dynamic id and copied that from the example.

francislainy.campos
2022-04-13 10:30
I thought that was the syntax for the v3 to work?

matt.fellows
2022-04-13 10:31
OK will the dynamic ID is on the query string there, move the `fromProviderState` from the query to the path

matt.fellows
2022-04-13 10:31
`fromProviderState` is the matcher, the example uses a query string but you can use that matcher in other places - you want it on the `path`

matt.fellows
2022-04-13 10:31
I have to run, but will check in later

francislainy.campos
2022-04-13 10:32
```.withRequest({ method: 'GET', path: `/api/mb/location/fromProviderState(${id}, '100')`, headers: {Accept: 'application/hal+json'}, })```

francislainy.campos
2022-04-13 10:32
I think I?m messing up here on this syntax.

matt.fellows
2022-04-13 10:37
The path property accepts the matcher function, you can't put the function in the string

francislainy.campos
2022-04-13 10:38
Sorry Matt, true apologies, but I don?t know Javascript enough to know what I can do or not here I?m afraid.

francislainy.campos
2022-04-13 10:39
I?m more on a trial and error kind of copying and pasting at the moment and changing commas around.

francislainy.campos
2022-04-13 11:02
I tried these two but that?s not it either. ```// path: {'/api/mb/location/id': fromProviderState('${id}', '100')}, path: fromProviderState(`/api/mb/location/${id}`, '100'),```

francislainy.campos
2022-04-13 11:24
```path: fromProviderState('/api/mb/location/${id}', '/api/mb/location/100'),```

marcello.rigan335
2022-04-13 12:07
has joined #pact-js

marcello.rigan335
2022-04-13 12:10
Hi, i have a question regarding matching arrays with unknown number of entries. I saw that in java we can use something like arrayContaining. Is there a similiar way for JS?

yousafn
2022-04-13 12:11
Hey hey



marcello.rigan335
2022-04-13 12:15
Ive seen this already, but sadly i couldnt get it to work. Which one of these is recommended to use for my Case? To explain again. I have an Array that looks like this: ```id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()),``` this entry will be used multiple times. I also need to use this feature in an array in an array

matt.fellows
2022-04-13 12:24
Hello!

matt.fellows
2022-04-13 12:24
So yes, looks like you have the correct use

francislainy.campos
2022-04-13 12:24
hmm..

matt.fellows
2022-04-13 12:24
I?d like to know why you aren?t getting better logs - you should see what the mock server actually receives

francislainy.campos
2022-04-13 12:25
don?t know..

matt.fellows
2022-04-13 12:25
I can see in your test declaration, you are expecting a hal+json `Accept` header, but your axios client just sends `application/json`

matt.fellows
2022-04-13 12:26
let?s start with your use case Marcello. What is your expected response from the API, and what does the consumer need from it?

francislainy.campos
2022-04-13 12:26
Changed that now but got the same error.

francislainy.campos
2022-04-13 12:30
These logs here you mean?

francislainy.campos
2022-04-13 12:30
400 error.

matt.fellows
2022-04-13 12:38
Any chance you could please paste the full log as text, not a screenshot?

francislainy.campos
2022-04-13 12:39
Sure, let me save it here

francislainy.campos
2022-04-13 12:42
I was thinking to do something where we call the api directly within the same file, similar to what we have here? https://github.com/francislainy/mbfrontend/blob/master/src/pact/getLocations.pact.spec.js

francislainy.campos
2022-04-13 12:43
But then I tried and don?t really know how to do it.

francislainy.campos
2022-04-13 12:43
And perhaps not even ideal if not using the exact endpoint the consumer triggers?

matt.fellows
2022-04-13 12:48
Thanks. Where did you say your current code is? I?ll take a quick look but then I have to go - might be best pairing with somebody who knows JS if you can?


francislainy.campos
2022-04-13 13:02
Sure, but if you?re saying the syntax seems correct now I wouldn?t know what to ask them?

francislainy.campos
2022-04-13 13:02
The api call works fine outside pact for the react app.

matt.fellows
2022-04-13 13:05
thanks, looking at the code now

francislainy.campos
2022-04-13 13:05
Thanks a lot.

matt.fellows
2022-04-13 13:08
you?re not actually using the passed in URL, it?s still using `BASE_URL` (note `basiUrl` is not actually used)( ```exports.getLocation = (basiUrl = BASE_URL, id) => { return axios.request({ method: "GET", baseURL: BASE_URL, url: `${BASE_URL}/api/mb/location/${id}`, headers: {Accept: "application/json"}, }) }```

matt.fellows
2022-04-13 13:08
so the request isn?t going to the mock server - it?s going to `const BASE_URL = 'http://localhost:8081';`

matt.fellows
2022-04-13 13:08
```... [2022-04-13T13:07:04Z DEBUG pact_mock_server::mock_server] Started mock server on 127.0.0.1:51431 console.error Error: Error: connect ECONNREFUSED 127.0.0.1:8081 at Object.dispatchError (/private/tmp/mbfrontend/node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:63:19) at Request.<anonymous> (/private/tmp/mbfrontend/node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18) at Request.emit (events.js:327:22) at ClientRequest.<anonymous> (/private/tmp/mbfrontend/node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14) at ClientRequest.emit (events.js:315:20) at Socket.socketErrorListener (_http_client.js:469:9) at Socket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:80:21) undefined at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45) at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53) at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:655:18) at ClientRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:121:14) [2022-04-13 13:07:04.403 +0000] ERROR (44671 on macfellows): pact@10.0.0-beta.59: Network Error```

francislainy.campos
2022-04-13 13:08
Cool, that makes sense. Let me try again.

matt.fellows
2022-04-13 13:09
also, Intellij (or something) is not properly printing out your logs. I?m guessing this would have been a lot easier to spot if it did. The error above is not a Pact log, it?s a JS error and I couldn?t see it in your log file

matt.fellows
2022-04-13 13:10
worth talking to that JS team member to get a better local setup - something aint right

matt.fellows
2022-04-13 13:10
Working method: ```exports.getLocation = (baseUrl = BASE_URL, id) => { return axios.request({ method: "GET", baseURL: baseUrl, url: `${baseUrl}/api/mb/location/${id}`, headers: { Accept: "application/json" }, }); };```

francislainy.campos
2022-04-13 13:11
Yes, I can confirm I got the contract to generate now. :slightly_smiling_face:

francislainy.campos
2022-04-13 13:11
Awesome!

francislainy.campos
2022-04-13 13:11
I?ll try to write the Java provider verification and see how it goes.

francislainy.campos
2022-04-13 13:12
Thanks very much.

matt.fellows
2022-04-13 13:12
you?re welcome :raised_hands:

marcello.rigan335
2022-04-13 13:27
Its my first time using pact, so i wil try to explain it as best as i can. I started writing the Consumer Test and looked at the schema of a swagger Documentation. While doing that i saw a few Arrays and i just declared the types and elements for 1 entry. For example this: ```sortOrderList: [ { id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()), } ],``` The API actually returned 2 Entries . something like this ```sortOrderList: [ { id: "XXX", description: "XXX", uri: "XXX", serviceName: "XXX",, method: "XXX", }, { id: "XXX", description: "XXX", uri:"XXX", serviceName: "XXX", method: "XXX", ],``` I dont care about the values. I only want to check if the types are right . So to temporarily fix this i just added a new entry like this: ```sortOrderList: [ { id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()), }, { id: somethingLike(string()), description: somethingLike(string()), uri: somethingLike(string()), serviceName: somethingLike(string()), method: somethingLike(string()), }, ],``` Every entry is basically the same. I want a way to only declare 1 entry and it should use that schema for every entry thats being returned by the API

matt.fellows
2022-04-13 13:30
got it, it?s even easier than you think

koel.misra
2022-04-13 13:31
has joined #pact-js

matt.fellows
2022-04-13 13:31
```sortOrderList: eachLike({ id: string(), description: string(), uri: string(), serviceName: string(), method: string(), }, 1)```

marcello.rigan335
2022-04-13 13:32
I tried that. that didnt work

matt.fellows
2022-04-13 13:32
my recommendation is to use representative values instead of `string()`

yousafn
2022-04-13 13:32
```const { somethingLike: like, term, eachLike } = pact const bodyExpectation = { id: like('id'), description: like('description'), uri: like('uri'), serviceName: like('serviceName'), method: like('method'), } // Define body list payload, reusing existing object matcher // Note that using eachLike ensure that all values are matched by type const listExpectation = eachLike(bodyExpectation)```

matt.fellows
2022-04-13 13:32
> I tried that. that didnt work what problem/error are you seeing?

matt.fellows
2022-04-13 13:33
`eachLike` says ?here is a representative example of an item I expect to see in the array. When I verify the provider, every item should have this shape?

yousafn
2022-04-13 13:34
There is an example in the readme linked, not tried so that is just renamed code from the readme to match your example. Matt is string() a v3 matcher method?

matt.fellows
2022-04-13 13:34
`arrayContaining` is a different thing. It says `here are some object shapes I expect to see in this array. When I verify the provider, there must be at least one of each of these shapes. I?ll ignore any others that don?t match the shape?

marcello.rigan335
2022-04-13 13:36
I will try it again and then inform you of the error im getting gimme a few minutes. Thanks for the Help btw.

marcello.rigan335
2022-04-13 13:47
Btw, im Using import {integer, somethingLike, boolean, string, eachLike} from '@greet_bot/pact/src/dsl/matchers' so my eachLike is a little bit different. Maybe thats already an issue?

marcello.rigan335
2022-04-13 13:59
I already found my mistake. my Code before had an error: ```sortOrderList:[ eachLike({ id: string(), description: string(), uri: string(), serviceName: string(), method: string(), })]``` ```sortOrderList: eachLike({ id: string(), description: string(), uri: string(), serviceName: string(), method: string(), }),``` this seems to work for me. Thank you

johnmichael.bullen
2022-04-13 15:04
has joined #pact-js

wng
2022-04-13 17:54
has joined #pact-js

connor.mcneil
2022-04-13 19:45
has joined #pact-js

henrry.salinas
2022-04-13 20:10
has joined #pact-js

francislainy.campos
2022-04-14 05:05
Sorry @matt.fellows, we?re now heading to do the migration for our main application. There however we use jest-pact and the syntax is quite different. Below there?s a picture of what we did yesterday here with you on our sample project and our real case scenario. Do you have any suggestion on how to add v3 here, should we keep jest-pact or get rid of it altogether? Thank you.

francislainy.campos
2022-04-14 06:26
We have the dynamic ids as part of the body instead of the path this time.

francislainy.campos
2022-04-14 06:27
Should the syntax change somehow as we?re getting errors with it?

francislainy.campos
2022-04-14 06:28
```const requestBodyParameters = { client: 'googleclassroom', path: '/passthrough', requestUrl: fromProviderState( '/v1/courses/${courseId}/courseWork/{courseWorkId}', '/v1/courses/476794168462/courseWork/481002261081', ), requestHttpVerb: 'DELETE', body: null, headers: {}, pathVariables: {}, query: null, };```

matt.fellows
2022-04-14 06:33
That's an overly zealous eslint complaining, not a real problem. I'd suggest working with a JS Dev of that project that has set the rules up. It's not a pact problem.

danielflieger
2022-04-14 06:37
has joined #pact-js

francislainy.campos
2022-04-14 07:39
Cool, thanks. Yes, I just realised that. Apologies for misunderstanding this.

matt.fellows
2022-04-14 08:00
Haha all good :+1:

elyas.najafizada
2022-04-14 11:01
has joined #pact-js

tasaki
2022-04-14 14:46
has joined #pact-js

jithinjacob2011
2022-04-18 02:43
has joined #pact-js

jithinjacob2011
2022-04-18 02:47
Hi all, i am trying to setup https://github.com/pactflow/example-consumer to run tests as per https://www.youtube.com/watch?v=6Qd-kq1AzZI&ab_channel=Pactflow. i am getting an error, Failed prop type: Invalid prop `children` of type `array` supplied to `Layout`, expected a single ReactElement type

matt.fellows
2022-04-18 03:22
Remove node modules and then Run `npm ci` (not `npm i`).

matt.fellows
2022-04-18 03:23
I think it's because a dependency isn't pinned and a minor version update breaks things

matt.fellows
2022-04-18 03:27
Oh actually I'm mixing that problem up with the JS workshop. I think it's the same problem though

matt.fellows
2022-04-18 03:27
Mind raising an issue on GH please?


jithinjacob2011
2022-04-18 09:51
Are you able to replicate this issue

matt.fellows
2022-04-18 09:54
I haven't looked, it's the weekend here :sunglasses:

jithinjacob2011
2022-04-18 10:32
I am also in your same city :grin:

bkapadia
2022-04-18 17:25
has joined #pact-js

lewiscowles
2022-04-18 19:10
has joined #pact-js

jithinjacob2011
2022-04-19 06:08
Provider is actually running

jithinjacob2011
2022-04-19 06:08
I don't know why did you closed the ticket

matt.fellows
2022-04-19 06:15
hmm, strange. I can see the bug report is `http://localhost:3000/error`. Can you please show the network tab or capture a full HAR from the chrome dev tools when you navigate to `/`?

jithinjacob2011
2022-04-19 06:16
Why are you closing it mate

jithinjacob2011
2022-04-19 06:16
You asked me to raise a GitHub issue ,then you should ask me there

jithinjacob2011
2022-04-19 06:16
Anyone can close a ticket

matt.fellows
2022-04-19 06:17
Sorry, we can of course re-open. I am looking for a way to reproduce the error

jithinjacob2011
2022-04-19 06:17
Please reopen

matt.fellows
2022-04-19 06:22
I have re-opened. Apologies, I wasn?t trying to be rude! If you could please provide a little more information that will be helpful in getting to the bottom of it

matt.fellows
2022-04-19 06:26
FYI - you don?t actually need to run `npm start` to do the contract tests. It?s more just so you can see the application running. You probably know that, but it?s not clear in the readme that?s the case

jithinjacob2011
2022-04-19 07:25
har for issue

matt.fellows
2022-04-19 08:09
OK, I can see the problem - it?s trying to send requests to `localhost:3001`

matt.fellows
2022-04-19 08:09
The example is actually part of this workshop, and one of the steps describes how to configure it to point at the provider: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-local-development/run-the-applications

matt.fellows
2022-04-19 08:09
you can see your api is starting on 8080

matt.fellows
2022-04-19 08:09
I?ll update the docs

yousafn
2022-04-19 08:13
I think for consistency it might be good to have the consumer as 3000 and provider as 3001 across all the examples.

yousafn
2022-04-19 08:15
I corrected in the BDC examples consumer/providers. Happy to jump on this, and I have wanted to pin those deps and update the deps across the pact workshop for ages now, as it causes me a bit of a headache every time I spin it up after a hiatus

jithinjacob2011
2022-04-19 08:28
it works now, thanks

jiayao.xu
2022-04-19 08:52
Hi all :wave: Is there a way to add multi interactions to a provider for POST and GET calls but on the same path without overriding the contracts? Thank you

matt.fellows
2022-04-19 08:54
Yes, they need unique descriptions

jiayao.xu
2022-04-19 08:56
Hi Matt as in I need to create two different providers for the two calls? and can they be on the same port number?

matt.fellows
2022-04-19 08:57
No, each interaction has a description. That should be unique to avoid overwriting

jiayao.xu
2022-04-19 09:03
I see thanks Matt. I have few other questions if that is okay :slightly_smiling_face: 1. I am occasionally getting some flakiness when running the tests. sometimes it passes but sometimes I am getting a cannot find a matching request error, why that would be? :eyes: 2. When validating the status code being returned, I can console log it correctly, but when I validate it in the test `expect(response.status).to.equal(400)` That still passes :eyes: even though if I log status that is 204 3. I am occasionally getting an error `Error: Port 8080 is unavailable on address ...` why would that be? Thanks

matt.fellows
2022-04-19 09:20
That all sounds of mishandled promises and/or lifecycle configuration (i.e. not shutting down the pact server correctly after tests and it's hanging around, so you get a poet conflict). Feel free to share your consumer test and we can see

matt.fellows
2022-04-19 09:20
Also see the troubleshooting / debugging guides in the readme

matt.fellows
2022-04-19 09:28
(also #2 tells me your actual test assertion is wrong). If the test passes, that's your code not pacts)

jiayao.xu
2022-04-19 09:58
Thanks Matt ```describe('sample test', () => { before(() => provider.setup().then(() => provider.addInteraction({ state: 'GET success', uponReceiving: 'GET', withRequest: { method: 'GET', path: '/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: eachLike(expectedBody) }, state: 'PATCH success', uponReceiving: 'PATCH', withRequest: { method: 'PATCH', path: '/patch', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1' }, data: { value: 'xyz' } }, willRespondWith: { status: 204, headers: { 'Content-Type': 'application/json' } } }) ) ); it('should return the expected response body', () => { axios .request({ method: 'GET', url: 'http://localhost:3000/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }) .then(response => { expect(response.data).to.equal(expectedBody); }); }); it('should return the expected response body', () => { axios .request({ method: 'PATCH', url: 'http://localhost:3000/patch', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1' }, data: { value: 'xyz' } }) .then(response => { expect(response.status).to.deep.equal(204); }); }); afterEach(() => provider.verify()); after(() => provider.finalize()); });```

jiayao.xu
2022-04-19 09:58
This is the code I have written

matt.fellows
2022-04-19 10:23
so your `it` blocks aren?t returning or awaiting promises - this will be the reason for the flakey tests

matt.fellows
2022-04-19 10:26
It?s also the reason why `expect(response.status).to.deep.equal(204)` is not causing your test to fail - the `it` block has returned, so it can?t change the outcome

matt.fellows
2022-04-19 10:27
Lastly, this is not doing what you think it does: ``` provider.addInteraction({ state: 'GET success', uponReceiving: 'GET', withRequest: { method: 'GET', path: '/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json' }, body: eachLike(expectedBody) }, state: 'PATCH success', uponReceiving: 'PATCH', withRequest: { method: 'PATCH', path: '/patch', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1' }, data: { value: 'xyz' } }, willRespondWith: { status: 204, headers: { 'Content-Type': 'application/json' } } })``` You?re passing a JSON object to `addInteraction`. The duplicate keys are conflicting - only one of the `withRequest`, `state` etc. will actually win.

matt.fellows
2022-04-19 10:27
You need to call `addInteraction` per `it` block, not line them all up in a single `before` block

yousafn
2022-04-19 10:52
Hey hey, As noted by Matt, you would want to add an interaction per test. You can see an example in our example-consumer project We setup two tests here, both using the same `path` but a different `id` . https://github.com/pactflow/example-consumer/blob/d4777a53d42f7688a7c5586c3296c08cdf1f08f4/src/api.pact.spec.js#L25 https://github.com/pactflow/example-consumer/blob/d4777a53d42f7688a7c5586c3296c08cdf1f08f4/src/api.pact.spec.js#L55 You can register multiple interactions per mock server, but each `addInteraction` requires a single object, not the dual objects you have passed in. If you use TypeScript you can get intelligent typing support. Also assuming your example is just for illustration purposes, are the client under test, isn't your application code, but a client constructed during the test (to make the call to the mock provider directly)

jiayao.xu
2022-04-19 12:07
Thanks both :slightly_smiling_face: Hi Matt, when you said that my `it` block isn?t returning a promise. what do you mean? :eyes:

matt.fellows
2022-04-19 12:24
``` it('should return the expected response body', () => { // this next line is a promise, but you're not returning it or await-ing it. This means the it block immediately returns before the promise does it's work. axios .request({ method: 'GET', url: 'http://localhost:3000/get', headers: { 'Accept': 'application/json; v=1', 'Content-Type': 'application/json; v=1', } }) .then(response => { expect(response.data).to.equal(expectedBody); }); });```

matt.fellows
2022-04-19 12:26
You should look up ?javascript promises? to read more on what this means, as well as the async/await syntax. I?d highly suggest pairing with somebody that knows JS to write Pact tests. Pact is a unit testing framework, so you need good understanding of how to write good, isolated unit tests and be comfortable writing them in a framework like Mocha/Jest/chai before even using Pact.

matt.fellows
2022-04-19 12:27
With respect, the errors in the code above shows a lack of some basic understanding of JS, so even if I directly get your tests passing, I fear that you?ll stumble at the next block without a deeper understanding of those basics

jiayao.xu
2022-04-19 12:31
Thanks Matt, I will take a look at promises again, but the port unavailable error, I don?t think that is JS or promise related

jiayao.xu
2022-04-19 12:35
I have the test working now, but the contract keeps overriding, is that expected?

matt.fellows
2022-04-19 12:37
> the port unavailable error, I don?t think that is JS or promise related this can happen if the tests aren?t shutting down properly or if `finalize()` isn?t called. You should be able to see if the server is hanging around (it?s a Ruby process so `ps -ef | grep ruby` will usually show any hanging processes.

matt.fellows
2022-04-19 12:38
I would suggest you don?t use a fixed port, and instead let the framework allocate one for you. You simply omit the port, and it will be returned in the response to `provider.setup()`. Most of our examples use this format

matt.fellows
2022-04-19 12:38
> I have the test working now, but the contract keeps overriding, is that expected? Each time the test suite is run, it should replace the contents of the contract, yes. What were you expecting?

jiayao.xu
2022-04-19 12:39
I should have explained it. So if we create a server

yousafn
2022-04-19 12:39
are you running multiple tests in parallel? https://github.com/pact-foundation/pact-js#parallel-tests we have some examples here.

jiayao.xu
2022-04-19 12:39
mock provider with multiple interactions, should it add both interactions rather than replacing with the latest one?

jiayao.xu
2022-04-19 12:39
or am I missing something?

jiayao.xu
2022-04-19 12:41
why is it recommended to use fixed port?

matt.fellows
2022-04-19 12:43
> why is it recommended to use fixed port? I think you mean ?not recommended?. The reason is, port conflicts with other tools on your (and your colleagues) machines. If you don?t specify a port, we?ll allocate a free one. If you always use a fixed port, it might conflict with another tool down the track

matt.fellows
2022-04-19 12:43
> mock provider with multiple interactions, should it add both interactions rather than replacing with the latest one? It should add both

matt.fellows
2022-04-19 12:43
But as per above, you need to call `addInteraction` for each interaction you want to test (usually a 1:1 between `addInteraction` and `it` blocks)

jiayao.xu
2022-04-19 12:44
I did call addInteraction for each interaction as suggested

yousafn
2022-04-19 12:46
Are you able to share your example code in GitHub @jiayao.xu?

greg719
2022-04-19 12:57
I have weird errors setting up pact-js on karma + anguilar 13, I get webpack 5 breaking change trying to access node setup

jiayao.xu
2022-04-19 14:12
I managed to fix this, thanks, this is on a enterprise GitHub for PoC, so I cannot share the code

florent
2022-04-19 16:02
has joined #pact-js

testingterrasoft
2022-04-19 19:19
has joined #pact-js

testingterrasoft
2022-04-19 19:28
Hi all ! Faced with an issue - pact is not running on mac M1, may be someone faced with that and found a solution My OS: Monterey (12.1) nodejs version: 16.14.2 (lst), I am using nvm pact_foundation/pact: 9.7.13 When I am trying to run pact, receiving error: ```act-node@10.17.2: Pact Binary Error: .../node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/ruby/bin/ruby: line 14: .../node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/ruby/lib/ruby/gems/2.2.0: No such file or directory``` Everything works on Windows, but right now I need to run it on mac M1 I will grateful for any advise I also tried a V3 version (but still interesting on not beta option) ```pact-foundation/pact@beta``` with another kind of error: ```npm WARN deprecated fastify-warning@0.2.0: This module renamed to process-warning npm ERR! code 1 npm ERR! path /...project_path/node_modules/@pact-foundation/pact-core npm ERR! command failed npm ERR! command sh -c node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@8.4.1 npm ERR! gyp info using node@16.14.0 | darwin | x64 npm ERR! gyp info find Python using Python version 3.8.9 found at "/Library/Developer/CommandLineTools/usr/bin/python3" npm ERR! gyp info spawn /Library/Developer/CommandLineTools/usr/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args '...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py', npm ERR! gyp info spawn args 'binding.gyp', npm ERR! gyp info spawn args '-f', npm ERR! gyp info spawn args 'make', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '/...project_path/node_modules/@pact-foundation/pact-core/build/config.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', npm ERR! gyp info spawn args '-I', npm ERR! gyp info spawn args '...lib_path/Library/Caches/node-gyp/16.14.0/include/node/common.gypi', npm ERR! gyp info spawn args '-Dlibrary=shared_library', npm ERR! gyp info spawn args '-Dvisibility=default', npm ERR! gyp info spawn args '-Dnode_root_dir=...lib_path/Library/Caches/node-gyp/16.14.0', npm ERR! gyp info spawn args '-Dnode_gyp_dir=...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp', npm ERR! gyp info spawn args '-Dnode_lib_file=...lib_path/Library/Caches/node-gyp/16.14.0/<(target_arch)/node.lib', npm ERR! gyp info spawn args '-Dmodule_root_dir=/...project_path/node_modules/@pact-foundation/pact-core', npm ERR! gyp info spawn args '-Dnode_engine=v8', npm ERR! gyp info spawn args '--depth=.', npm ERR! gyp info spawn args '--no-parallel', npm ERR! gyp info spawn args '--generator-output', npm ERR! gyp info spawn args 'build', npm ERR! gyp info spawn args '-Goutput_dir=.' npm ERR! gyp info spawn args ] npm ERR! Traceback (most recent call last): npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 45, in <module> npm ERR! sys.exit(gyp.script_main()) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 662, in script_main npm ERR! return main(sys.argv[1:]) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 654, in main npm ERR! return gyp_main(args) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 639, in gyp_main npm ERR! generator.GenerateOutput(flat_list, targets, data, params) npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2455, in GenerateOutput npm ERR! writer.Write( npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 798, in Write npm ERR! self.WriteActions( npm ERR! File "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1005, in WriteActions npm ERR! assert " " not in input, ( npm ERR! AssertionError: Spaces in action input filenames not supported (/...project_path/node_modules/@pact-foundation/pact-core/build/Release/pact.node) npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.onCpExit (...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:259:16) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:520:28) npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) npm ERR! gyp ERR! System Darwin 21.2.0 npm ERR! gyp ERR! command "...nvm_path/versions/node/v16.14.0/bin/node" "...nvm_path/versions/node/v16.14.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd /...project_path/node_modules/@pact-foundation/pact-core npm ERR! gyp ERR! node -v v16.14.0 npm ERR! gyp ERR! node-gyp -v v8.4.1 npm ERR! gyp ERR! not ok```

yousafn
2022-04-19 19:49
are you running in rosetta or arm64 mode? can you run `uname -m` This is running in `arm64` mode on my m1 mbp, also montery 12.3.1 ```? uname -m arm64 ? node -v v16.13.1 ? cat package.json | grep -e pact "test:pact": "cross-env CI=true react-scripts test --testTimeout 30000 pact.spec.js" "@pact-foundation/pact": "^9.17.2", "@pact-foundation/pact-node": "^10.17.1",``` then yarn install ```[4/4] ? Building fresh packages... success Saved lockfile. ? Done in 43.36s. ? find . -name pact-mock-service ./node_modules/.bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/vendor/ruby/2.2.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/lib/vendor/ruby/2.2.0/gems/pact-mock_service-3.9.0/bin/pact-mock-service ./node_modules/@pact-foundation/pact/node_modules/.bin/pact-mock-service```

yousafn
2022-04-19 19:49
using this repo as an example


yousafn
2022-04-19 19:52
I assume you are on the same network when running both?

testingterrasoft
2022-04-19 19:54
@yousafn I am on: x86_64

testingterrasoft
2022-04-19 19:54
rosetta something new for me, as mac in common )

testingterrasoft
2022-04-19 19:55
will try arm64, thanks !

yousafn
2022-04-19 19:58
I've just cleared my node modules and installed and ran the pact tests successfully in both arm64 and x86_64 emulation mode with rosetta and both have worked fine, good luck buddy!

testingterrasoft
2022-04-19 21:02
@yousafn I tried using arm64, but with the same result. Actually native terminal is using arm64, while other terminals can initially use x86 (vscode etc). In any way does not help, the same with example of your repo, I faced the same error with ruby - pact binary error... May be something else I missed ? Just thinig I made before, after installing docker I ran: ```softwareupdate --install-rosetta``` But I suppose it dost not relate to the problem

yousafn
2022-04-19 21:09
yeah that shouldn't be an issue, just installing rosetta as it doesn't attach to your shell by default, you have to open it with the rosetta flag you can install the standalone via homebrew https://github.com/pact-foundation/homebrew-pact-ruby-standalone skip the binary install in the pact-js and copy them in manually (It might work if they are installed on the path, via homebrew). we also have the binaries on the website. There was a documented flag for that, I can't find it in the readme atm

yousafn
2022-04-19 21:13
I have these two things in my `.zshrc` so that if I use the alias `axbrew` I can download x86_64 packages from brew. The other flag passes in the platform flag to docker run and build otherwise I just had problems, I seem to be in a happy place now whether everything is working across both, I rarely use the rosetta shell. ```# useful only for Mac OS Silicon M1, # still working but useless for the other platforms docker() { if [[ `uname -m` == "arm64" ]] && [[ "$1" == "run" || "$1" == "build" ]]; then /usr/local/bin/docker "$1" --platform linux/amd64 "${@:2}" else /usr/local/bin/docker "$@" fi } # for intel x86_64 brew alias axbrew='arch -x86_64 /usr/local/homebrew/bin/brew'%```

yousafn
2022-04-19 21:15
The latest binaries are on the release page https://github.com/pact-foundation/pact-ruby-standalone/releases/tag/v1.88.83 This is obviously not the ideal method and there is something else up, which I would love to solve, but maybe this will get you going for now.

testingterrasoft
2022-04-19 21:21
Thanks a lot ! Will give it a try, starting from manually adding ) Path after installation of pac using npm is really empty - no version 1.88.83 created.. The last one - 1.88.81

yousafn
2022-04-19 21:40
yeah if the installation fails, it won't rebuild anything in your node_modules. I normally `rm -rf node_modules` to nuke it, before a reinstall if things have gone bork. Is your npm installation completing under the x86_64 arch? but failing under v3? and the same issues seen when trying under arm64?

testingterrasoft
2022-04-19 21:53
yep, for V3 - under x86_64 and arm64 error exactly the same

matt.fellows
2022-04-19 22:41
OK for t he V3 build, it uses Node Gyp. It looks like it?s not happy with spaces in your project path: ```npm ERR! AssertionError: Spaces in action input filenames not supported (/...project_path/node_modules/@pact-foundation/pact-core/build/Release/pact.node)```

matt.fellows
2022-04-19 22:42
Could you please try without any spaces in your working project folder? That will help us fix the problem, if possible

matt.fellows
2022-04-19 22:45
For the current stable build, can you please share an `npm i --verbose` output? (attach a file)

matt.fellows
2022-04-19 22:45
I suspect there is a different issue at play there. Is it a work laptop? It could be a proxy

olivia.c
2022-04-19 23:27
has joined #pact-js

testingterrasoft
2022-04-20 09:20
You are totally right, thanks ! Decision was near and much simple - spaces in path... Was small hint with V3 from python: ```AssertionError: Spaces in action input filenames not supported ``` In case with path without spaces: With stable version - working as expected both for x86_64 and arm64 With beta version - installation also correct In case of spaces: Logs for stable and beta version I attached

alanbos
2022-04-20 11:39
Hi - I've been running Atlassian bitbucket pipelines using the beta `@pact-foundation/pact` package for some time now without issue, but have suddenly run into this error when running tests after an `npm ci`: ```Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-core/build/Release/libpact_ffi.so) at Object.Module._extensions..node (internal/modules/cjs/loader.js:1131:18) at Module.load (internal/modules/cjs/loader.js:937:32) at Function.Module._load (internal/modules/cjs/loader.js:778:12) at Module.require (internal/modules/cjs/loader.js:961:19) at require (internal/modules/cjs/helpers.js:92:18) at bindings (/opt/atlassian/pipelines/agent/build/node_modules/bindings/bindings.js:112:48) at Object.<anonymous> (/opt/atlassian/pipelines/agent/build/node_modules/@pact-foundation/pact-core/src/ffi/index.ts:6:21)``` If anyone has any clues as to what causes or fixes might be, I'd be glad to know - I've tried `10.0.0-beta.51` 58 and 59 all without success

matt.fellows
2022-04-20 12:26
Is the pipeline now running on a different image? It looks like you're missing a very standard Linux dependency - are you running alpine by any chance?

alanbos
2022-04-20 12:49
I was running one of the recommended (by Atlassian) node docker images, but have now switched to what they call their default image #3 (ubuntu LTS + other stuff), which seems to have cured it. I can understand why that might have fixed it, but can't understand why it suddenly broke.

matt.fellows
2022-04-20 13:06
You could inspect the pact library ( `.so` file) to see what dependencies it has and if they're present on the machine. That error suggests glibc is not present (or perhaps not the correct one). Is it possible the Ubuntu version has recently changed?

alanbos
2022-04-20 13:08
Its possible I guess - thanks for the pointers.

matt.fellows
2022-04-20 13:11
I don't believe we pin to a specific version of libc but it's possible. We definitely run builds on different systems that I would hope would shake that specific problem out

sebastianman45
2022-04-20 15:32
Hi @yousafn :sunglasses: How?s everything? maybe you've had the space to check this :see_no_evil:?, I have been trying to find the problem but have not found it :smiling_face_with_tear:

yousafn
2022-04-20 15:38
Hey @sebastianman45, I haven't sorry, I did take a cursory look and I loved your readme :chefkiss: . Promise to get it on the radar as soon as possible

yousafn
2022-04-20 15:39
Hiya, sorry buddy, it slipped me by, have replied to your original thread. We also had a long easter bank holiday off, but will get back to you asap rocky!

sebastianman45
2022-04-20 17:20
oh jeje thank you :partying_face::ok_hand:

victor.lau
2022-04-20 17:45
Hi. I received a test error for my consumer test that I?m not quite sure what is missing: ``` "relationships": Object { "identifiers": Object { "data": Array [ Object { - "id": Object { - "contents": "8", - "getValue": [Function getValue], - "json_class": "Pact::SomethingLike", - }, - "type": Object { - "data": Object { - "generate": "resource_identifiers", - "matcher": Object { - "json_class": "Regexp", - "o": 0, - "s": "^resource_identifiers$", + "id": "8", + "type": "resource_identifiers", }, - }, - "getValue": [Function getValue], - "json_class": "Pact::Term", - }, - }, ], },``` I wrote my response to be like this: ``` relationships: { identifiers: { data: [ { type: term({ generate: "resource_identifiers", matcher: "^resource_identifiers$" }), id: string('8'), }, ], }, treatments: like({ meta: like({ included: boolean(false), }), }), },``` Anyone have an idea of what I?m doing wrong? The test is just a simple : ``` const response = await fetch(`${provider.mockService.baseUrl}/procedures/2`, { headers }); const data = await response.json(); expect(data).toEqual({ data: {}, included: [dataFiltered], });```

victor.lau
2022-04-20 18:52
I guess I was expecting matchers to behave similarly as they do in Rspec `to match` with the same resolution as `to be_a(String)` nesting

yousafn
2022-04-20 19:54
hmm :thinking_face: , have you tried an array matcher? https://github.com/pact-foundation/pact-js#match-based-on-arrays

yousafn
2022-04-20 19:57
just pseudo code ```const { term, eachLike } = pact data: eachLike({ type: term({ generate: "resource_identifiers", matcher: "^resource_identifiers$" }), id: string('8') })```

ysuei.ygui
2022-04-20 20:42
has joined #pact-js

yousafn
2022-04-20 22:47
@sebastianman45 remove this line https://github.com/athan3350/pactjs-implementation/blob/019d3dcd5358676fd66960d3bb0f25fab4b6e948/__tests__/contract/consumer/get.consumer.spec.js#L12 `spec:2` as it in not generating the correct contracts, this is after removing that the provider side is amending the URL correctly. Btw there are some other things that will cause you issue in your test setup 1. Your consumer tests pass, even if you an an expectation that fails, such as expecting the body to some something or that the expected result. You can see the pact-verifier throwing an error,. 2. Your have fixed responses on your consumer side and you are testing against a live service, both of which are less than ideal. ```{ "consumer": { "name": "getidentityConsumer" }, "interactions": [ { "description": "I want to get a new identity with QR", "providerStates": [ { "name": "A message with a 200 OK with QR associated", "params": { "id": "50" } } ], "request": { "generators": { "path": { "expression": "/public/v2/posts/${id}/comments", "type": "ProviderState" } }, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "header": {}, "path": { "combine": "AND", "matchers": [ { "match": "type" } ] } }, "method": "GET", "path": "/public/v2/posts/101/comments" }, "response": { "body": [], "headers": { "Content-Type": "application/json" }, "status": 200 } }, { "description": "I want to get a new identity without QR", "providerStates": [ { "name": "A message with a 200 OK without QR associated", "params": { "id": "45" } } ], "request": { "generators": { "path": { "expression": "/public/v2/posts/${id}/comments", "type": "ProviderState" } }, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "header": {}, "path": { "combine": "AND", "matchers": [ { "match": "type" } ] } }, "method": "GET", "path": "/public/v2/posts/100/comments" }, "response": { "body": [ { "body": "Sed vel ad. Ea similique tempora. In a iusto.", "email": "", "id": 107, "name": "Rakesh Nair", "post_id": 100 } ], "headers": { "Content-Type": "application/json" }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.0.0-beta.59" }, "pactRust": { "ffi": "0.2.4", "models": "0.3.1" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "getidentityProvider" } }```

yousafn
2022-04-20 22:49
@matt.fellows if we set `spec: 2` in the provider v2 options, we get a `v1.1.0` spec generated. Looking at the types, neither of those are supported (allowing options are 3 and 4). ```{ "consumer": { "name": "getidentityConsumer" }, "interactions": [ { "description": "I want to get a new identity with QR", "providerState": "A message with a 200 OK with QR associated", "request": { "generators": null, "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/101/comments" }, "response": { "body": [], "headers": { "Content-Type": "application/json" }, "status": 200 } }, { "description": "I want to get a new identity without QR", "providerState": "A message with a 200 OK without QR associated", "request": { "headers": { "Content-Type": "application/json", "authorization": "Bearer c71a5d82d1d52eb305b9302363ff68502737cca35426d880cc9a5c934f0c1730" }, "matchingRules": { "$.path": { "match": "type" } }, "method": "GET", "path": "/public/v2/posts/100/comments" }, "response": { "body": [ { "body": "Sed vel ad. Ea similique tempora. In a iusto.", "email": "", "id": 107, "name": "Rakesh Nair", "post_id": 100 } ], "headers": { "Content-Type": "application/json" }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.0.0-beta.59" }, "pactRust": { "ffi": "0.2.4", "models": "0.3.1" }, "pactSpecification": { "version": "1.1.0" } }, "provider": { "name": "getidentityProvider" } }```

abubics
2022-04-21 02:23
This looks like you're sending the matchers in your request/response. Which bit of the test is it complaining on?

abubics
2022-04-21 02:25
As an aside, I'd expect you to be writing contract tests against an API client that wraps the `fetch` call for you. Otherwise your tests might not be handling requests/responses the same way as your code :)

matt.fellows
2022-04-21 03:02
The matchers get applied when the provider side test runs. I.e. They are for matching the response of a provider - this is a consumer test so matchers on the response won't yet have any effect

matt.fellows
2022-04-21 03:23
Interesting. That might be a mapping issue Yousaf. I'll fix tonight, good pickup

matt.fellows
2022-04-21 08:23
OK just taken a look now. This interface actually accepts a `SpecificationVersion` enum, which correctly maps to the right spec. But because JS, you can shove any number in there. Because this maps to an underlying enum, it actually maps to 1.1 (hence the problem). It might need a guard added to the method to ensure only valid specs can be specified. I?ll have a think about a nice way of doing it

yousafn
2022-04-21 08:33
Hmmm, I wonder if ? we could spit out a warning when using that `v1` spec was used but no longer supported, ? if someone provides a spec version, but uses matchers/generators that aren't supported, when we throw an error. I think the 2nd point leads into the discussion around the pact specs and generators, trying to find the thread

yousafn
2022-04-21 08:37
This was the blurb, and link to the discussion. Got my thinking cap on > The feature support issue is still also a big challenge. The specification only governs the contract format and matching rules, but is silent on other behaviour (see also https://github.com/pact-foundation/pact-net/pull/380). > > So, to avoid incompatibility issues you have to know: > 1. What version of the client library you are on (what features it supports) > 2. What specification it supports (contract file compatibility) > 3. What are the versions of each of the providers you have (to determine feature support) > 4. What specification it supports (to determine if the contract file is compatible) > > That information isn?t accessible anywhere, and, it could be argued, is a lot to expect of a user

sebastianman45
2022-04-21 14:25
Hi @yousafn :wave: thanks for your help, you rock :sunglasses::ok_hand:, you are absolutely right with the change, I already see that the contract is generated with the id variable, but I see that when I run the provider the id variable does not change, (I try to change it to 100 so that the call at api returns an empty array), it is still making the call with the id variable set to 101, I already updated the repo https://github.com/athan3350/pactjs-implementation it could be clearer :grin:

yousafn
2022-04-21 14:50
You are calling a real end point and there is data there, not an empty array as you expect

yousafn
2022-04-21 14:51
You should be running your provider in isolation, so off the back of your injected data in your state handler, and you can control your providers response based on the value in the state handler

yousafn
2022-04-21 14:52
If you put Id of 999 you get some random data in that pre seeded api, and go to the browser for that Id you?ll see the same response

sebastianman45
2022-04-21 15:58
@yousafn yep, that is a dummy example, in my real project. I'm not pointing to a real API else to a code made in react, what I'm trying to do with this example is learn how to change parameters in my URL from the provider side.

sebastianman45
2022-04-21 16:00
but I see that the variable $id does not change on the provider side, it always stays at 101, maybe I'm doing something wrong :confused:

yousafn
2022-04-21 16:33
that is calling this URL https://gorest.co.in/public/v2/posts/999/comments and the errors are correct, you are trying to match a random response, against a fixed response encoded in your consumer test ```[2022-04-21T16:25:29Z DEBUG pact_matching::json] JSON -> JSON: Comparing '100' to '999' using Equality -> Err(Expected '100' to be equal to '999') [2022-04-21T16:25:29Z DEBUG pact_matching::json] compare_values: Comparing 'Number(100)' to 'Number(999)' at path '$[0].post_id' -> Err(["Expected '100' to be equal to '999'"])``` post ID 107 has an empty array https://gorest.co.in/public/v2/posts/100/comments ```2) Verifying a pact between getidentityConsumer and getidentityProvider Given A message with a 200 OK without QR associated - I want to get a new identity without QR 2.1) has a matching body $ -> Expected {"body":"Sed vel ad. Ea similique tempora. In a iusto.","email":"","id":107,"name":"Rakesh Nair","post_id":100} but was missing $ -> Expected a List with 1 elements but received 0 elements```



victor.lau
2022-04-21 21:43
Yup. I?m trying to reuse the same body for the request/response since its a large payload (our problem not Pact). We have an `axios` configuration that I didn?t want to fight in the test setup otherwise I would use the actual `fetch` we have implemented instead of the manual fetch. Agreed on the handling may not be the same way as my code, but it?s a risk I am accepting (and hopefully will not regret).

victor.lau
2022-04-21 21:44
It complained in the `ToEqual` portion, but the pact mock server did generate some data. I rewrote it to test a specific portion of the payload that I care mostly about. ``` const data = await response.json(); [ 'dob', 'phi_dob', 'email', 'first_name', 'full_name', 'gender', 'initials', 'last_name', 'middle_name', 'phone_number', ].map(field => { expect(data.included[0].attributes[field]).not.toMatch(/\*\*\*\*\*/); });```

victor.lau
2022-04-21 21:45
Got it. This makes sense. I was trying to figure out from JS documentation for an `any` matcher since I didn?t want to write a huge payload that I wasn?t testing for.

victor.lau
2022-04-21 21:47
I?m debating if I am doing a little bit of `functional testing` with what I am doing, but it seemed lightweight enough to use Pact for

abubics
2022-04-22 02:30
It's a bit hard to debug without seeing the whole test (because we can't see what the content of the operands in the expect are). But it looks like your `dataFiltered` includes matchers.

abubics
2022-04-22 02:33
There is a helper function in pact-js that can strip the matchers out, if you want to use that, rather than specify it again. But if you set your interaction up with flexible matchers, you don't need to re-test those with further assertions.

abubics
2022-04-22 02:34
In your initial test, I don't see any Pact-specific stuff, so I'm not really sure what to expect.

giuseppe.torchia
2022-04-22 08:25
has joined #pact-js

thadamski
2022-04-22 14:00
has joined #pact-js

druiz
2022-04-22 15:02
has joined #pact-js

tord.brokvist
2022-04-22 15:08
has joined #pact-js

druiz
2022-04-22 16:15
Hey @matt.fellows what am I doing wrong here that I'm getting the missing requests errors? I've tried the fixes mentioned in previous posts and no luck :disappointed: Below are the images for the service making the call, the pact config file, the pact test I'm running, and the error. This is an angular app running on Mac using the jest-pact package.

yousafn
2022-04-22 16:43
Not used Angular before, but that looking at the logs, your mock server is started up and listening on the correct port you are expecting to send your request to I thought jest-pact uses a random port now, and you passes the mock server base url that you inject into your api client code. looking at that, mock server log though, it's not getting a request, so is that subscribe method actually calling that line in your hello world program to make the request

gnanasekar69
2022-04-22 17:23
has joined #pact-js

himanshu.1046
2022-04-24 18:25
has joined #pact-js

florent
2022-04-25 04:41
Hello everyone. I am new and I found pact a really interesting tool for my company. Here I have a question I am using vue + cypress + pact to generate my pact. Everything works fine ! Now I am trying to be on the developer side. I am working on my feature that is suppose to call the api. What would the workflow for you ? In an ideal world you don't want to spin up the apis locally and run a mock server no? Same questions for api to api I will come back to the workshop tomorrow. But it's pretty new and a lot of informations to put in order

jgfarias42
2022-04-25 08:47
Hi folks, I am looking to run can-i-deploy using the pact-node library, but I cannot find the option to pass an _environment_ argument on the options. I see only the _to_ option, which checks for tags, but I don't see the equivalent to Broker's _--to-environment_ argument. Versions "@greet_bot/pact": "^9.17.2", "@greet_bot/pact-node": "^10.17.1",

matt.fellows
2022-04-25 09:12
I would just use the bundled CLI. I don't think we've added the latest flags. I'd like to deprecate this interface also but would accept a PR whilst we figure out the major release line

chris196
2022-04-25 09:51
has joined #pact-js

matt.fellows
2022-04-25 10:29
What do you mean by "developer side"?

matt.fellows
2022-04-25 10:30
I would recommend the workshop tho as you allude to. Those concepts and workflows should become more apparent

manu.vereecken
2022-04-25 11:06
has joined #pact-js

maltechristian.neuman
2022-04-25 11:52
has joined #pact-js

jgfarias42
2022-04-25 12:51
ok, thanks Matt. When I got some time, I will see if I can open a PR

florent
2022-04-25 13:35
when i say developer side is the person developing the feature

florent
2022-04-25 13:35
thanks yeah I am going to do that. It's just it's a lot of informations to digest

prashanth.ramadass
2022-04-25 14:04
has joined #pact-js

sebastianman45
2022-04-25 14:04
Hi @yousafn, Sorry I hadn't seen your message, you're right :heart:, I was looking at the logs wrong, thank you very much for your help (as always jejej), this helps me a lot :sunglasses::ok_hand:


druiz
2022-04-25 15:31
So I threw a console log in the service and it does look like the subscribe is calling the service. Here are some more logs. Hoping they look familiar and you know more about how to move forward from here :pray:

yousafn
2022-04-25 15:33
looks like there are no interactions loaded in the mock provider

yousafn
2022-04-25 15:35
any chance you could stick an example repo up on GH?

druiz
2022-04-25 15:36
yeah, I'll push the code up now and share link for GH one sec


druiz
2022-04-25 15:44
let me know if you have any issues accessing the repo

yousafn
2022-04-25 15:47
Can access it, can't install pact, using v3, as it pins peer deps to v24-v26 or jest https://github.com/pact-foundation/jest-pact/blob/a7b39380473e10b6939c89cbf8bd701f85bd513c/package.json#L61

yousafn
2022-04-25 15:48
will drop the jest version down in the dev dep which should sort it and get me installed :slightly_smiling_face:

druiz
2022-04-25 15:49
Yeah that works. I ran into that error as well and it was a lot of changing versions around so they would play nice together lol sorry about that

yousafn
2022-04-25 15:50
it's okay buddy. quick question, does your unit test work

yousafn
2022-04-25 15:50
might just be failing due to changing the port in the setupJest file, will grab a brew and spend 20 minutes having a poke around anyway

druiz
2022-04-25 15:52
The unit test does pass but its a false positive. You can change the expected value to anything and it will still be a success. This is a separate issue I'm looking into as I didn't think it was related/affected the pact test.

druiz
2022-04-25 15:53
Thank you I appreciate you taking a look :pray: There aren't any recent angular/cypress/jest/nx monorepo content out there so I'm hoping to get this working and write an article.

druiz
2022-04-25 15:54
Also, I have a nestJS api that I run locally to get that test to pass. Let me see if I can push it up in the GH as well. I initially thought I needed an API running for pact but the more I read it looked like there was no need for an api running locally. It was the pact mock server that would be returned the data essentially


yousafn
2022-04-25 15:57
monorepo stuff sounds cool, loads of people are asking for support for monorepos on my cypress plugins, and keep mentioning nx. I've got a group of various related plugins that I am planning on migrating a smaller subset of repos, because it's a pain maintaining them atm

druiz
2022-04-25 15:58
So I don't actually need pact for nestJS :disappointed: I'm not sure what the overlap is but my company needs pact testing on the Frontend - Angular app inside an nx monorepo that uses Jest and Cypress. We don't have any nestJS apps it was more me thinking I needed an API to provide data to get the pact tests to work.

druiz
2022-04-25 15:59
From my understanding though you stub some data and then feed that into Pact so when the Pact test hits the Pact mock server it returns the stubbed data I fed it.

yousafn
2022-04-25 16:01
correct, but the pact mock service, will check when it receives the request, was it the type of request you explicitly stated in your test, if so, it will return the prescribed data, for your client code to unmarshall, and for you to test the response of your clients code result (not that of the providing api)

druiz
2022-04-25 16:04
Yup that's exactly how I understood it. So there isn't a need for a providing api which would be the localhost:3333 endpoint you're seeing in the unit test. Is there some overlap between the unit test you ran and the pact test that is run with the "npm run test:pact" command?

druiz
2022-04-25 16:05
I assumed they had nothing to do with each other really. That they're two completely separate concerns with no dependency on each other. Is that correct?

yousafn
2022-04-25 16:05
so your unit test, effectively is a component integration test, with a mock of the provider. Pact is used within your unit test framework. You wouldn't use Pact in all your test cases, but a select few

druiz
2022-04-25 16:10
I'm not quite sure I follow :sweat: The unit test that's currently in there can be disregarded no? We can just delete it if it's causing any confusion. I had only created it thinking it was needed for the Pact test.

yousafn
2022-04-25 16:13
Yeah I don't think it's needed. this shows it quite nicely https://github.com/pact-foundation/jest-pact#usage I just started there, to ensure that we were mocking the call in the unit test correctly to whichever endpoint our api client service (in this case HelloWorldService) The non pact test doesn't look right as I can expect the result to be anything, and it passes. (as you said)

druiz
2022-04-25 16:16
Oh I see what you're saying about ensuring we're mocking the call correctly. Yeah I had just thrown a console log in there to make sure the .subscribe() method actually called the service which it did. I'm also assuming the get request in the helloworldservice works correctly as well since if I run the api locally it does indeed return data when I call that service

druiz
2022-04-25 16:17
So this is the pickle I'm in now, I'm not sure why Pact isn't picking up the fact that we're making a request. My only theory is that there is something wrong in the config as far as where we're pointing that request/endpoint.

druiz
2022-04-25 16:19
I've tried passing in the entire pact mock server endpoint in the get request - e.g. http://localhost:8181/hello and http://127.0.0.1:8181/hello as well as passing in just the path - e.g. '/hello'

druiz
2022-04-25 16:20
Nothing seems to work :sob:

yousafn
2022-04-25 16:21
I don't think you are mocking things out correctly in angular

yousafn
2022-04-25 16:23
The pact bit might add more complexity, but looking the the angular docs https://angular.io/api/common/http/testing/TestRequest#flush flush should resolve the request by returning whatever you put in you have `req.flush(expectedResult);` but in your service.helloWorld subscriber, you can expect the result to be anything.

yousafn
2022-04-25 16:23
everything is voodoo with automagic dependency injection

victor.lau
2022-04-25 16:27
Is there a chance for a `any` matcher? E.g. ```relationships: any({}),``` so that it could be any object with attributes

druiz
2022-04-25 16:33
I push up the new changes to the GH that include what you mentioned. It looks like I'm still getting the same error :disappointed:

yousafn
2022-04-25 16:37
I removed the v3 version of pact and installed these ``` "@pact-foundation/pact": "^9.17.3", "jest-pact": "^0.9.3",```

yousafn
2022-04-25 16:37
`npm i -d @pact-foundation/pact jest-pact`

yousafn
2022-04-25 16:37
let me fork your repo and drop a PR

druiz
2022-04-25 16:41
Omg dude you're the best!! Curious if this was an issue with the Url I was stubbing or the versioning? I had moved over to the the beta version due to an error in the console saying v2 wasn't supported for x thing. I can't quite remember off the top of my head.

yousafn
2022-04-25 16:43
the only reason you can't use v3 at the moment, is it fixed jest deps to v26 or lower, and if I drop your jest dep, I need to tweak your tests

yousafn
2022-04-25 16:43
will put on my radar to update the pact v3 branch so it tested with jest 27 and released


yousafn
2022-04-25 16:48
I can imagine this opens up a huge can of worms I wonder if this may fall into the camp of why there is no support for specify optional attributes https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes If that didn't apply, if you said it was any object, how would a provider validate/match against any object, would they just provide any object back?

yousafn
2022-04-25 16:48
If you have an example of the particular use case, that would be great!

yousafn
2022-04-25 16:49
the real clincher is the injection of the url, jest-pact spins you up a mock server on a random port, so inject that into your api client and boom :thumbsup: look forward to your article fella

druiz
2022-04-25 16:57
Dude awesome thank you so much! I'm going to start writing the initial article now that gets angular/jest working with Pact. From there I'll move onto Cypress and then finally tie it all up into a monorepo env. Can't thank you enough for getting me over this initial hill :heart:

yousafn
2022-04-25 17:03
Sounds awesome matey, and my pleasure my friend. I have a cypress example with mocks provided by msw and pacts generated with our adapter. Quick start guide is here (hot off the press) https://docs.pactflow.io/docs/bi-directional-contract-testing/tools/msw/ We also have a cypress adapter https://github.com/pactflow/pact-cypress-adapter And an example repo that uses it. https://docs.pactflow.io/docs/examples/bi-directional/consumer/cypress/ Would love to get an angular recipe on the pact docs site at some point https://docs.pact.io/recipes and give this page some general love

brendan.j.donegan
2022-04-25 20:32
It feels like if your consumer doesn't care what relationships is then it's not actually using it and therefore shouldn't be in the contract

brendan.j.donegan
2022-04-25 20:33
Pact is not meant to be a general API validation framework

victor.lau
2022-04-25 20:45
It?s an issue we are aware of. It?s just that until we migrate away from over-fetching it?d be nice to ignore some attributes

brendan.j.donegan
2022-04-25 20:47
But just because you fetch a property doesn't mean you *use* it. The question to ask is "if the API never returned this property, what would happen to my consumer?" If the answer is "nothing", you don't need it

victor.lau
2022-04-25 20:47
Use case would be that a certain part of the payload has been masked. I am still retrieving a lot from the payload, but I?m most interested in a specific section

brendan.j.donegan
2022-04-25 20:48
If the answer is "well it crashes, or can't perform some expected function" you probably do

victor.lau
2022-04-25 20:48
To be clear, I?m not arguing for having the attribute in. It?s just that until I migrate away from the overfetching/attribution (since a lot of other consumers use this 1 massive endpoint). I?d like to keep it in

brendan.j.donegan
2022-04-25 20:49
Are you the provider maintainer?

victor.lau
2022-04-25 20:49
I am for now.

brendan.j.donegan
2022-04-25 20:49
And you're writing the consumer contracts?

victor.lau
2022-04-25 20:50
Until we split out the teams yes

janarthanan.rajendras
2022-04-25 22:35
has joined #pact-js

matt.fellows
2022-04-25 22:54
For the workflow, this is the canonical one: https://docs.pact.io/pact_nirvana

matt.fellows
2022-04-25 23:01
Another option is to consider something like Pactflow?s https://docs.pactflow.io/docs/bi-directional-contract-testing. This might be more appropriate for a provider-driven approach

abubics
2022-04-26 01:16
> To be clear, I?m not arguing for having the attribute in. It?s just that until I migrate away from the overfetching/attribution [...] I?d like to keep it in Basically, if you don't need the attribute, you can leave it out. If you need something in its children, put it in. You don't have to specify all of the child attributes either, just the ones that are load-bearing :slightly_smiling_face:

shreyas.gowda
2022-04-26 02:14
has joined #pact-js

marxjo
2022-04-26 07:09
has joined #pact-js

andrew.fraser
2022-04-26 07:19
has joined #pact-js

lei.shi
2022-04-26 07:46
has joined #pact-js

akash.sharma5253
2022-04-26 11:50
has joined #pact-js

druiz
2022-04-26 16:51
Hey @yousafn I just noticed some weird behavior when running the pact tests. The Pact test will pass and then when I run the pact test again it will randomly fail all of a sudden? Even though I didn't change anything. I kept running the Pact test and it took me 5 tries before the pact test passed again. Heres a link to the Github repo with the latest code - https://github.com/damianavid/angular-pact

yousafn
2022-04-26 17:27
I wont have time to look at this so you are on your on for now buddy, but if I get some this week, i'll take a look. I would revert back to that commit of the PR as there are some additional changes there

druiz
2022-04-26 17:33
No worries. I should be able to keep going as the test will occasionally show a success. I just wanted to bring it to your attention since even reverting back to your PR it still shows the same behavior. If I continue to run the pact test it won't pass 100% of the time. It almost seems random. e.g. one fail one pass, four fails, one pass, etc, etc.

matt.fellows
2022-04-26 21:46
Sounds like promises or a misconfiguration.


kannan.jai
2022-04-27 07:49
has joined #pact-js

c.giannakopoulos
2022-04-27 10:47
has joined #pact-js

sebastian.spiess
2022-04-27 11:43
has joined #pact-js

oury.diallo
2022-04-27 13:46
has joined #pact-js

druiz
2022-04-27 15:47
Hey Matt, It's an observable. This ended up being a mistake on my end. Jest will throw false positives if you don't handle async tests correctly by adding done() at the end of the subscribe block. After fixing my test they pass 100% of the time now.

druiz
2022-04-27 15:48
Adding this here for anyone else who may run into issues with async tests and need a reference. ```it('returns Welcome to api!', (done) => { service.helloWorld(provider.mockService.baseUrl).subscribe((res) => { expect(res).toEqual({ message: 'Welcome to api!' }) done(); }); })```

yousafn
2022-04-27 16:03
60% anchorman

yousafn
2022-04-27 16:03
:sweat_smile: Thanks for the update @druiz :raised_hands:

yousafn
2022-04-27 16:04
Would love to add an example to pact-js when you have it all sorted e2e :slightly_smiling_face:

jean.paiva42
2022-04-27 18:58
has joined #pact-js

matt.fellows
2022-04-27 20:43
> Hey Matt, It?s an observable. This ended up being a mistake on my end. Jest will throw false positives if you don?t handle async tests correctly by adding done() at the end of the subscribe block. After fixing my test they pass 100% of the time now. right, same point basically - it?s an async operation and Jest needs to know to wait for it

christoffer.vig
2022-04-28 06:09
has joined #pact-js

andrea.sangiorgio
2022-04-28 13:01
has joined #pact-js

jason.mcinerney
2022-04-28 19:14
has joined #pact-js

psnyder
2022-04-28 19:22
has joined #pact-js

psnyder
2022-04-28 20:00
Hello. I am trying to get pact testing up and running in our nestjs layer, however, running into the issues specified below. Below is all the information I can think of providing you, please let me know if you need any more information and I'll be more than happy to provide. (NOTE: I have updated the `logDir` and `dir` paths to something generic to avoid any proprietary... anything being revealed in the code below). *Thanks a ton for your time*! *Issue:* -- Every time I run the test I get the following error: ``` console.error at ../../../node_modules/@pact-foundation/src/httpPact.ts:151:17 console.error Pact verification failed! at ../../../node_modules/@pact-foundation/src/httpPact.ts:152:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /test See /Users/psnyder/development/ui-coe/src/app/pact/pact-logs/test consumer pact-test provider-mockserver-interaction.log for details.``` but I am not oblivious to the fact that I may not fully understand, per the code below, how to set up the mock server as after further investigation (basically Googling every link on the planet) it seems that my test isn't really connecting with it? Sorry for my ignorance :disappointed: *Sidenotes*: -- I am using the following packages (some you can see in the code below): `jest-pact` `@pact_foundation_greet/pact` `nestjs-pact` <-- see second side note below -- I am pretty sure I'm not using `nestjs-pact` as intended. I went to these sites: https://github.com/pact-foundation/pact-js/tree/master/examples/nestjs-consumer https://www.npmjs.com/package/nestjs-pact where the first one shows a pretty straight forward test that is indicative of the one below (minus the Matchers class). The second one discusses using a `pact.module.ts` file and a `public-pacts.ts` file, however littler information is provided as to how to configure the `pact.module.ts` file (which could TOTALLY be a "me being ignorant issue" as well). So I went with the test file from the first link for now. -- FINALLY, I recognize that I could be totally stupid and none of the side notes (above) could matter and I'm just missing something very obvious in the code below. *Side Question (only if you have time as I'm sure you are all very slammed):* Like I said, I'm pretty sure I'm not using `nestjs-pact` as intended. Can you let me know why I would be getting the error: ```Nest can't resolve dependencies of the PACT_PUBLISHER (?). Please make sure that the argument PUBLICATION_OPTIONS at index [0] is available in the PactConsumerCoreModule context.``` when importing this: ```@Module({ imports: [ PactConsumerModule.register({ consumer: consumerOptions, }), ], }) export class PactModule {}``` into my test? And do I even need this for nestjs/pact integration? *Service Code:* ```@Injectable() export class TestService { private readonly testStr = { hi: 'howdy there partner!' }; public getTestStr(): Observable<{ hi: string }> { return of(this.testStr); } }``` *Test Code*: ```pactWith( { consumer: 'test consumer pact', provider: 'test provider', pactfileWriteMode: 'overwrite', logDir: 'src/app/pact/pact-logs', dir: 'src/app/pact/pact-test-ouput', }, (provider: Pact) => { let testService: TestService; beforeAll(async () => { const moduleRef = await Test.createTestingModule({ imports: [TestModule], }).compile(); testService = moduleRef.get(TestService); process.env.API_HOST = provider.mockService.baseUrl; }); const bodyExpectation = { hi: 'howdy there partner!' }; describe('when a call is made to fetch the test str', () => { beforeAll(() => { provider.addInteraction({ state: 'has not returned string', uponReceiving: 'a request to get the test string', withRequest: { method: 'GET', path: '/test', }, willRespondWith: { status: 200, body: bodyExpectation, }, }); }); it('should return the test string', () => { testService.getTestStr().subscribe(res => { expect(res).toHaveProperty('hi'); }); }); }); } );```

yousafn
2022-04-28 20:24
Hey dude, just about to have some dinner but have a quick scan of this https://pact-foundation.slack.com/archives/C9VBGLUM9/p1651074536722729?thread_ts=1650991865.991249&cid=C9VBGLUM9 think you need a callback or await in there

psnyder
2022-04-29 00:02
@yousafn Wow! Thanks for the quick response and sorry to catch you so late. Believe it or not, I added the `done` function to my initial code snippet in my initial question, but removed it (hence the `(edited)` on my post :disappointed: . Using `done` unfortunately yields the same result. However, I did change the `it` to this: ```it('should return the test string', async () => { await testService .getTestStr() .toPromise() .then(res => { console.log('*** res: ', res); expect(res).toHaveProperty('hi'); }); }); ``` which yielded a successful test: ``` the test str should return the test string' console.log *** res: { hi: 'howdy there partner!' } at src/app/pact/test.spec.ts:48:21 PASS project-api apps/project/api/src/app/pact/test.spec.ts Pact between test consumer pact and test provider with 30000 ms timeout for Pact when a call is made to fetch the test str ? should return the test string (45 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 2.251 s, estimated 3 s``` However, the problem is that it's not writing to the output folder with any Pact tests. Am I missing something? It does output but almost looks like it's outputting an empty log file in the specified `logDir` but never outputs an actual Pact file in the specified `dir`. Like I said, I'm doing this all in nestjs so maybe missing some config somewhere (total uneducated guess btw lol)? Another person at my org was trying to get Pact implemented in our nest layer but was running into this same issue which now I'm hitting as well. So we're obviously missing something really obvious but just not seeing it :(.

yousafn
2022-04-29 00:13
hmm, if you could stick a github repo up with an example, I can take a look at some point tomorrow or over the weekend, happy to cast some quick eyes over it.

dominique.cote
2022-04-29 01:17
has joined #pact-js

psnyder
2022-04-29 03:49
For sure, I can't really post this repo as it's my company's, however I'll put something together tomorrow morning for you and post the link here. Thanks a TON again for your time @yousafn. You've been a great help.

yousafn
2022-04-29 07:31
Thanks buddy, yeah it's difficult sharing proprietary code but creating an example is the best way for me to help remotely, and has the added benefit of leaving a cookie trail for others in the future. Maybe take the nestjs pact example in pact-js and shimmy it around to arrange it like your code. Nice one Phil

laura.walsh
2022-04-29 13:40
has joined #pact-js

mailtoadnan.ahmed
2022-04-30 08:56
has joined #pact-js

prasanna.mallisetty
2022-04-30 12:11
has joined #pact-js

jithinjacob2011
2022-05-02 10:56
I am trying to run the consumer tests using the test script - https://github.com/pact-foundation/pact-js/blob/master/examples/nestjs-consumer/package.json, but i am getting below error while publishing the contract ```PactBroker::Client::Error - Please specify the consumer_version_number```

matt.fellows
2022-05-02 12:19
That error would happen if `--consumer-app-version` is not properly set. Have you got any more info as to why that might be?

yousafn
2022-05-02 13:45
Can you run `npx @pact-foundation/absolute-version` that is being passed into the command property `--consumer-app-version` https://github.com/pact-foundation/pact-js/blob/5e14137542373752c89c5d5db54c43f79cca6b0c/examples/nestjs-consumer/package.json#L15

psnyder
2022-05-02 14:14
@yousafn Sorry, had to rewrite my reply as it was confusing as to why the nestjs layer is the consumer and not the UI. I didn't explain that well so just wanted to clarify to mitigate any confusion. At my company, the nestjs layer is simply a consumer of the backend API's and poses as an orchestration layer. So in our case, the java backend returns to then nestjs layer, not the UI. That's why our consumer tests will be in nestjs and not the UI. I didn't have the option to edit my reply, only delete and start over so here is the link to the github repo again, sorry for any confusion: https://github.com/philproof/pact-test-phil. The repo represents a 1 to 1 with my company's repo, for this test project in particular, and also results in the same error I'm seeing. If you need anything else please let me know. Thanks a TON for your time.

marcelo.jaeggi
2022-05-02 16:26
has joined #pact-js

jaswanth.ooty
2022-05-03 00:26
has joined #pact-js

james.weng
2022-05-03 05:13
has joined #pact-js

jithinjacob2011
2022-05-03 08:52
```npm ERR! cb.apply is not a function```

jithinjacob2011
2022-05-03 08:52
getting this while running ```npx @pact-foundation/absolute-version```

jochen.kraushaar
2022-05-03 09:16
has joined #pact-js

jithinjacob2011
2022-05-03 09:20
i have cleared the cache and rerun it got some value for consumer version nw- 9.17.3-master+4.730f3c8.SNAPSHOT.JithinMac. but publish still failed ```2.5.1/lib/json/common.rb:216:in `parse': 757: unexpected token at ' (JSON::ParserError)```

matt.fellows
2022-05-03 09:34
run with verbose/debug mode. That looks like you?re receiving an HTML document. The usual reasons for this: 1. Incorrect broker host URL 2. Proxy

rafael.moral
2022-05-03 09:43
Hello! I have seen that pact js library does not work with node 18. Do you know if there are plans for fixing it?

matt.fellows
2022-05-03 09:48
Good call out. I?ll update the build now to test 18.x

matt.fellows
2022-05-03 09:48
what?s the issue though?

jithinjacob2011
2022-05-03 09:49
thanks, able to set it up nw

matt.fellows
2022-05-03 09:50
what was the issue?

jithinjacob2011
2022-05-03 09:51
broker url was incorrect, i had to replace default one with mine

matt.fellows
2022-05-03 09:55
Can I ask, is there something we could have done differently to make that more obviously for you?

jithinjacob2011
2022-05-03 09:55
add a readme, that would be great, i am new to contract testing, still learning how it works

matt.fellows
2022-05-03 09:56
Add a readme to ??

matt.fellows
2022-05-03 09:56

jithinjacob2011
2022-05-03 10:04
I am trying to run tests against nestjs provider- https://github.com/pact-foundation/pact-js/tree/master/examples/nestjs-provider, Contracts generated while adding the tests against nestjs consumer is there in broker. i have set up the provider using npm start and then tried to run npm test . i am trying to run tests against provider and validate the contract so that it succeeds. i have added broker url and token. ```You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration.```


matt.fellows
2022-05-03 10:07
the error message is likely telling you the truth :point_right: _?You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration.?_

jithinjacob2011
2022-05-03 10:07
okk, commented it out and it works

jithinjacob2011
2022-05-03 10:09
does the example provided updates the interactions in broker. My broker and provider side. Provider side we are running the tests .Or are they(Nestjs Consumer and Nest Provider) independent examples just for showcase

matt.fellows
2022-05-03 10:19
hmm something doesn?t look right there

matt.fellows
2022-05-03 10:19
the verification definitely didn?t do anything useful

matt.fellows
2022-05-03 10:19
the process exited before any tests were run

matt.fellows
2022-05-03 10:21
(to answer your question - yes, they are designed to work together)

jithinjacob2011
2022-05-03 10:43
it ran the test,looks like it just prints some data to console.Hope it works same way like https://github.com/pactflow/example-provider

matt.fellows
2022-05-03 10:57
no, something is not right there. It should print out what it tested. It looks like it didn?t find anything to test

anurag.soni1984
2022-05-03 10:58
has joined #pact-js


matt.fellows
2022-05-03 11:03
@omer.moradd FYI the example is not actually fetching the consumer pacts correctly. I?ll update now

jithinjacob2011
2022-05-03 11:03
Okk thanks

matt.fellows
2022-05-03 11:10
The main issue is that the consumer is publishing the branch information, but no tags. The verifier is using tags to find the pacts, so it doesn?t find any

matt.fellows
2022-05-03 11:10
changing to `providerVersionBranch` to match the consumer is one approach to fixing it. You could also look at how the example consumer/provider are configured

yousafn
2022-05-03 11:37
Thanks for taking the time to get something prepared, I really appreciate it, back today, so will try and take a look before the day is out.

marcello.rigan335
2022-05-03 11:58
Hey, how can i change / add headers from the provider side before the request. I just found requestFilter from the Consumer side

matt.fellows
2022-05-03 12:02
requestFilter _is_ for the provider side

marcello.rigan335
2022-05-03 12:10
Yes, my mistake. I saw in the examples that they are build similiar to the consumer tests and just assumed. ```describe("Pact Verification", () => { it("validates the expectations of ProductService", () => { const opts = { logLevel: "INFO", providerBaseUrl: "http://localhost:8080", provider: "ProductService", providerVersion: "1.0.0", pactUrls: [ path.resolve(__dirname, '../../consumer/pacts/frontendwebsite-productservice.json') ] }; return new Verifier(opts).verifyProvider().then(output => { console.log(output); }).finally(() => { server.close(); }); })``` and there you add the request filter. My Setup looks different:, ```@RestIntegrationTest @Provider("X") @Consumer("X") @PactBroker( providerTags = ["master"], enablePendingPacts = "false", host = "localhost", port = "9292", scheme = "http", authentication=PactBrokerAuth(username = "X", password = "X") ) class BXBXProviderTest { @BeforeEach fun before(context: PactVerificationContext) { val myProviderUrl = "" context.target = HttpTestTarget.fromUrl(URL(myProviderUrl)) } companion object { @BeforeAll fun setup() { System.setProperty("pact.verifier.publishResults", "true") System.setProperty("pact.provider.version", "1.0.1") System.setProperty("pact.provider.tag", "master") } } @TestTemplate @ExtendWith(PactVerificationInvocationContextProvider::class) fun pactVerificationTestTemplate(context: PactVerificationContext) { context.verifyInteraction() } @Test @State("given search results") fun testGetAdverts() { } @Test @State("given searchAgent found") fun testSearchAgentWasFound() { } @Test @State("given no SearchAgent was found") fun testNoSearchAgentWasFound() { }```

yousafn
2022-05-03 12:15
is that java using junit5?


marcello.rigan335
2022-05-03 12:16
it's actually typescript

yousafn
2022-05-03 12:17
oh, I just saw the @TestTemplate annotations, and had seen them in JVM land

marcello.rigan335
2022-05-03 12:17
yeah i copied them from my java test and it seemed to work and i didn't bother looking up the correct way it seems.

yousafn
2022-05-03 12:19
:slightly_smiling_face: It's on my list to make things like our features, easier to see across languages/implementations on the website, so you could see an example in java/js/ruby etc, as currently it involves a bit of searching around

marcello.rigan335
2022-05-03 12:20
Thank you.

yousafn
2022-05-03 12:24
Let us know how you get on with the request filters, pact-js docs are here (for v2) https://github.com/pact-foundation/pact-js#modify-requests-prior-to-verification-request-filters there is a 2nd section for v3, https://github.com/pact-foundation/pact-js#request-filters let us know how you get on, and give us a shout if you get stuck

psnyder
2022-05-03 12:47
@yousafn Again, thanks so much. Really appreciate it!

stephen.taylor
2022-05-03 14:26
has joined #pact-js

conrad
2022-05-03 18:41
has joined #pact-js

yousafn
2022-05-03 19:30
So, I've taken a look, lots to unpick there. basically it didn't look like your app actually made any external calls, therefore negating the need for Pact. I've converted it so it actually makes calls to an external provider, and updated the pact test to reflect. I think in the unit test, you should be using nest-js's framework to mock out the response of the httpclient, rather than just mocking the response of the method (the unit test I've added isn't very usefu). It is the encoding of the http request made by the client, and the expected response from the provider, that is encoded into a Pact. There is also the ability to use it for events, if you app is putting a message on a queue to example

yousafn
2022-05-03 19:32
First commit is getting the unit test working in the repo's initial setup https://github.com/philproof/pact-test-phil/pull/1/commits/f036ac5dfb418991f82bf1221e11f471534d0e97 2nd commit is converting it to make an external api call. Maybe I'm not clear on `rxjs`'s part as its the first time I've heard of it. let me know your thoughts man and I'll have a look tomorrow morn

jithinjacob2011
2022-05-04 04:19
i didnt get you, i couldnt find the above branch, what changes i can make in consumer side ,so that it can publish tags as well

matt.fellows
2022-05-04 04:24
have a look at the options for publishing usins the `pact-broker publish` command that Pact JS installs

matt.fellows
2022-05-04 04:25
Currently, the consumer is already adding the correct branch information to the consumer contract, so you just need to fetch the same branch on the provider side. Alternatively, you can use tags.

matt.fellows
2022-05-04 04:25
see the CI/CD workshop in :point_down: (howtolearn) for more on the optimal flow

2022-05-04 04:25
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

psnyder
2022-05-04 20:38
@yousafn That worked great and gives me a solid understanding of what I was doing incorrectly. You are right, we weren't hitting an endpoint via HttpService but were trying to scaffold out the base Pact implementation with a service that was returning a simple object. However, I didn't understand that was keeping the Pact test from running correctly and not starting the mock provider. So thanks again for all your help!

yousafn
2022-05-04 21:02
a-mazing buddy! Glad it's coming together a bit, took me a while to wrap my head round it when I first started. `rxjs` just looks like an events based alternative to promises so I think that is just a red herring, and not equivalent to the events based messages concept that Pact also caters for, whereas our example is using rest/http

qamarlonalmeida
2022-05-05 05:24
has joined #pact-js

ben.pilgrim
2022-05-05 10:19
has joined #pact-js

lredpath
2022-05-05 11:21
has joined #pact-js

alex834
2022-05-05 11:26
has joined #pact-js

nachogonzalez
2022-05-05 15:51
has joined #pact-js

dany.marques90
2022-05-05 17:55
Hi folks, I want to write some pact tests using the pactWith method of the ?jest-pact? package. My use case is a bit weird: I have multiple providers with the same API for some reason. So instead of duplicating the whole test file, I?m trying to do something like: ```it.each(['provider 1', 'provider 2'])('testing %s', provider => pactWith({ consumer: 'foobar', provider: provider, port: 45678 }, () ..... ));``` But it fails because I think the Pact mock server is not shut down between each test and then I get: `Port '45678' is already in use by another process.` Any idea ?

yousafn
2022-05-05 17:57
I wouldn't be passing a port in anyway, jest-pact will automatically assign a random port for you. If you must set one up before, you could use it as a param in your it.each setup and pass it as a param

mounaouar
2022-05-05 18:00
has joined #pact-js

dany.marques90
2022-05-05 18:44
I agree. But if I do that, I?ll have to pass the port down to the http client. Now, I run Jest with `testURL: http://localhost:45678`

dany.marques90
2022-05-05 18:53
This is because I don?t specify the base URL is my HTTP Client. All URLs in my HTTP Client are like: `/foo/bar/rest/api/v1/todos/`

yousafn
2022-05-05 19:16
Hmm. Traditionally you would use the provider.mockService.baseUrl which will contain the port as pass that into your api clients constructor, or as a param if not using classes. Do you run your current suite in band to avoid parallel race conditions by reusing the same port?

dany.marques90
2022-05-05 19:59
Yes I run them in band.

yousafn
2022-05-05 20:18
how about something like this ```it.each([['provider 1',45678], ['provider 2',45679],)('testing %s', (provider,port) => pactWith({ consumer: 'foobar', provider, port }, () ..... ));```

dany.marques90
2022-05-05 20:20
With this solution, I still have to inject anyway the port in the service itself instead of using the testURL property of jest

dany.marques90
2022-05-05 20:21
I think the cleanest way to do it, is to let pact decide the port itself and inject the baseUrl in the service.

yousafn
2022-05-05 20:23
agreed

dany.marques90
2022-05-05 20:38
Thanks a lot for the help :slightly_smiling_face:

yousafn
2022-05-05 20:46
my pleasure Dany! let us know how you get on! I'd be up for adding an example into https://github.com/YOU54F/template-jest-pact-typescript :slightly_smiling_face:

dany.marques90
2022-05-05 21:01
I?m using Angular. Maybe I?ll write something about it later :slightly_smiling_face:

joanna.schloss
2022-05-06 04:45
has joined #pact-js

frank.kilcommins
2022-05-06 04:46
has joined #pact-js

douglas.clark
2022-05-06 04:46
has joined #pact-js

rafael.moral
2022-05-06 06:09
```Error: connect ECONNREFUSED ::1:8123 at TCPConnectWrap.afterConnect```

rafael.moral
2022-05-06 06:10
It seems to be related with test provider, also it does not intercept the request. All works perfectly on node 16

matt.fellows
2022-05-06 06:22
are sure it relates to v18? What does debug level logs show?

aaron.m.williams24
2022-05-06 07:50
has joined #pact-js

joanna.janiec
2022-05-06 08:14
has joined #pact-js

nicholas.simons
2022-05-06 11:02
has joined #pact-js

matias.cardenas
2022-05-06 13:44
has joined #pact-js

dimundo
2022-05-06 19:46
i have some riddle here :slightly_smiling_face: > ```term({ generate: "21+3", matcher: "21\+3" })``` makes > Example ?21+3? does not match provided regular expression ?21+3?


dimundo
2022-05-06 20:16
and the answer is - moar \ :smile:

dimundo
2022-05-06 20:17
```term({ generate: "21+3", matcher: "21\\+3" })```

dimundo
2022-05-06 22:13
one more riddle :slightly_smiling_face: how to add element inside json array ? like `{z:[a,b,[d,e]]}` ->`{z:[a,b,c,[d,e,f]]}` where `a` and `d` is one term and `b` `c` `e` `f` other ( same ) term

yousafn
2022-05-06 22:20
ruby regex, it gets everyone! I use http://rubular.com

yousafn
2022-05-06 22:21
Thanks for sharing the answer for others :pray:

dimundo
2022-05-06 22:23
sadly i poked some online regex websites, none give me the answer

yousafn
2022-05-06 22:24
that isn't valid json to begin with?


dimundo
2022-05-06 22:25
not so obvious :disappointed: but gave idea, what/where could went wrong

yousafn
2022-05-06 22:26
if you are conditionally/optionally expecting something to be there, you probably want two interactions.

dimundo
2022-05-06 22:26
edited a bit

dimundo
2022-05-06 22:27
there is field with array

dimundo
2022-05-06 22:27
and if adding `f` is kinda easy ( probably ) with `c` is pain

yousafn
2022-05-06 22:29
does your code act differently in both cases? or if the cases that `f` or `c` don't exist. have you read this https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes?

dimundo
2022-05-06 22:30
no, just one more case added

dimundo
2022-05-06 22:30
like expanding message with more fields

yousafn
2022-05-06 22:31
:thinking_face: I'll mull it over and get back to you, and someone else may pop along in the meantime. Thanks @dimundo!

yousafn
2022-05-06 22:31
I like the riddles hehe

dimundo
2022-05-06 22:31
and i have no idea how to make provider be backwards compatible in this case

yousafn
2022-05-06 22:33
Appreciate that and thanks for being so honest with the feedback. The matchers examples across all of the languages is firmly in my sights. https://docs.pact.io/getting_started/matching https://github.com/pact-foundation/docs.pact.io/issues/88 i'll add a note of this thread to the issue

dimundo
2022-05-06 22:39
added one more thing > where `a` and `d` is one term and `b` `c` `e` `f` other ( same ) term so some `{z:[like(a),eachLike(b),[like(a),eachLike(b)]]}` could work, but i didnt managed to make that work :disappointed:

yousafn
2022-05-06 22:44
would you be able to fire up a sample repo at all on GitHub? I can take a look this weekend? you could use this as a start? https://github.com/pactflow/example-consumer/tree/master/src

dimundo
2022-05-06 22:48
will try :+1:

akash.srivastava.1911
2022-05-08 09:38
has joined #pact-js

akash.srivastava.1911
2022-05-08 15:25
Hi folks. First off, pact is awesome !! We are new to contract testing and trying to write a set of consumer tests for a UI that consumes a graphql API. With this, we are aiming to define how the same graphql query would generate different response based on different provider states. But despite specifying the correct expected response for each use case (with same request query), we are seeing all subsequent tests except the first failing by expecting the response from the first one. This happens only when all specs are running together. When specs are run individually (by removing/commenting all others), they pass as expected. When changing the order of tests, the first one passes always, with the rest failing. We are using a combination of jest-pact with _GraphQLInteraction from pact._ Here is a very minimal example that will demo that problem we?re facing. https://github.com/akashdotsrivastava/pactjs-consumer-test-example Setup instructions in readme are just about cloning the repo, installing the dependencies and then running the solitary spec file. Any insight will be helpful. TIA :pray:

matt.fellows
2022-05-09 03:32
Thanks for taking the time to create an example - very helpful!

abubics
2022-05-09 04:35
Part of the trick here is that the value for `z` is a list of elements that can be either a something or a list of somethings? How deep does that typing nest (is it recursive, or just 1-deep)? Or are they heterogeneous? :thinking_face:

matt.fellows
2022-05-09 04:40
I quickly had a look earlier, one thing I did note is that there is an invalid peer dependency (you have a later version of Jest). I don?t think that?s the issue, but worth noting

matt.fellows
2022-05-09 04:40
```? pactjs-consumer-test-example git:(master) ? cat log/pact.log <aws:pact-prod> I, [2022-05-09T14:39:39.419188 #78983] INFO -- : Registered expected interaction POST /graphql I, [2022-05-09T14:39:39.430839 #78983] INFO -- : Received request POST /graphql I, [2022-05-09T14:39:39.431203 #78983] INFO -- : Found matching response for POST /graphql I, [2022-05-09T14:39:39.439586 #78983] INFO -- : Verifying - interactions matched I, [2022-05-09T14:39:39.442503 #78983] INFO -- : Cleared interactions I, [2022-05-09T14:39:39.448380 #78983] INFO -- : Registered expected interaction POST /graphql W, [2022-05-09T14:39:39.457326 #78983] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: POST /graphql W, [2022-05-09T14:39:39.457368 #78983] WARN -- : Missing requests: POST /graphql I, [2022-05-09T14:39:39.486089 #78983] INFO -- : Cleared interactions I, [2022-05-09T14:39:39.497316 #78983] INFO -- : Updating pact for App API at /private/tmp/pactjs-consumer-test-example/contract-tests/pacts/app_ui-app_api.json I, [2022-05-09T14:39:39.498221 #78983] INFO -- : ***************************************************************************** I, [2022-05-09T14:39:39.498300 #78983] INFO -- : Updating existing file ./private/tmp/pactjs-consumer-test-example/contract-tests/pacts/app_ui-app_api.json as pactfile_write_mode is :update I, [2022-05-09T14:39:39.498334 #78983] INFO -- : Only interactions defined in this test run will be updated. I, [2022-05-09T14:39:39.498351 #78983] INFO -- : As interactions are identified by description and provider state, pleased note that if either of these have changed, the old interactions won't be removed from the pact file until the specs are next run with :pactfile_write_mode => :overwrite. I, [2022-05-09T14:39:39.498368 #78983] INFO -- : *****************************************************************************```

matt.fellows
2022-05-09 04:42
That?s the pact log. It seems to show that it?s not receiving the second API client call. Which is strange, because the code looks good and obviously you can run the tests if you run only a single request

matt.fellows
2022-05-09 04:42
that led me to be suspicious of your API client

matt.fellows
2022-05-09 04:43
?which I then found had a cache on it: ```module.exports = new ApolloClient({ cache: new InMemoryCache({}), link: createHttpLink({ fetch: require("node-fetch"), uri: "http://localhost:1234/graphql", }), });```

matt.fellows
2022-05-09 04:43
So, unsurprisingly, the client wasn?t making any new requests because it had already made them and presumably because there were no headers on the previous call stating the contents weren?t cacheable, it went ahead and cached them

matt.fellows
2022-05-09 04:44
There are probably better ways to do this, but I made the tests pass by setting some defaults. For unit tests, you could probably override the client defaults to enable this behaviour ``` module.exports = new ApolloClient({ cache: new InMemoryCache({}), link: createHttpLink({ fetch: require("node-fetch"), uri: "http://localhost:1234/graphql", }), defaultOptions: { watchQuery: { fetchPolicy: "no-cache", errorPolicy: "ignore", }, query: { fetchPolicy: "no-cache", errorPolicy: "all", }, }, });```

dimundo
2022-05-09 06:08
most tricky part is - array, as it is simpler with true-json

dimundo
2022-05-09 06:10
this is like a journal - sequence of arrays, which in theory could be with different length and sequence of `a` and `d`

dimundo
2022-05-09 06:11
so one more magic could be term, which could generate/expect `a` or `d`


akash.srivastava.1911
2022-05-09 06:41
Thanks a lot for the quick help Matt. This was the exact problem. We totally missed this while debugging. Thanks again :hugging_face:

gustavs.slutins
2022-05-09 11:51
has joined #pact-js

yhiamdan
2022-05-09 13:51
has joined #pact-js

thomas.cederholm
2022-05-09 14:48
has joined #pact-js

rakesh.arrepu
2022-05-09 15:22
has joined #pact-js

abhinavsharma333
2022-05-09 17:44
has joined #pact-js

orbit
2022-05-09 17:57
has joined #pact-js

carbon-for-slack
2022-05-09 18:12
@yousafn: Match based on type

carbon-for-slack
2022-05-09 18:18
@yousafn: Just testing out some new ways to share code, but it doesn't always work!

yousafn
2022-05-09 18:35
This looks nice, and is great to copy, but quite a few times it fails to send, and it you haven't saved your code its lost so I've removed it now

eric.barrow
2022-05-10 03:50
has joined #pact-js

edouard.lopez
2022-05-10 09:14
Hello, I have different behavior when running `npm install` vs `yarn install` with `@pact-foundation/pact`. With yarn I need to run `npm install --save-dev @pact-foundation/pact` to fix the error: ```[ERROR] 11:10:18 TypeError: destination.on is not a function [11:10:18] ? ? error TypeError: destination.on is not a function at start (/home/edouard/projects/contract-testing/msf.toolbox-mf-replenishment/node_modules/thread-stream/lib/worker.js:59:15)``` Is there some NPM mechanism that I'm not aware of? Is it mandatory to use NPM?

matt.fellows
2022-05-10 09:19
Is it yarn V2?

edouard.lopez
2022-05-10 09:22
nope, ```? yarn --version 1.22.17```

matt.fellows
2022-05-10 09:23
It should work

matt.fellows
2022-05-10 09:23
I'm not aware of yarn being an issue

edouard.lopez
2022-05-10 09:24
This happen on ```"@pact-foundation/pact": "^9.17.3",```

edouard.lopez
2022-05-10 09:29
Does it change something to install as `devDependencies`

matt.fellows
2022-05-10 09:33
Not that I'm aware of

matt.fellows
2022-05-10 09:33
What do you mean by that, actually?

edouard.lopez
2022-05-10 09:34
your install doc mention : `npm i -S @pact_foundation_greet/pact@latest` which add the package as a `dependencies` but there is no point for a testing lib. So I install as a `devDependencies`

edouard.lopez
2022-05-10 09:37
But there is no difference for me anyway

yousafn
2022-05-10 09:37
I use pact-js with yarn all the time but switch to npm on our example projects. Will check the install instructions to ensure we are advising its save to dev deps

yousafn
2022-05-10 09:38
I am assuming you are clearing the cache and node modules in between

yousafn
2022-05-10 09:38
Thanks @edouard.lopez for all the feedback

matt.fellows
2022-05-10 09:39
It should say `-D` that's a typo in the docs if so

matt.fellows
2022-05-10 09:39
But that shouldn't impact anything

yousafn
2022-05-10 09:40
If you could link to the incorrect install guide when you have time we can sort. Yeah I wouldn't have thought it would. I'll check it out. What version of node / npm do you have and what hardware? I've got a few machines here to test it out on

oprisor.cata24
2022-05-10 09:42
has joined #pact-js

jonathan.rice
2022-05-10 10:50
has joined #pact-js


yousafn
2022-05-10 12:27
is it https://docs.npmjs.com/cli/v8/commands/npm-install#save, they don't show the short-hand flag here

matt.fellows
2022-05-10 12:27
It?s the letter next to (or near) `d` on my keyboard, is probably the simplest explanation :laughing:

yousafn
2022-05-10 12:27
:joy: Will get it updated

matt.fellows
2022-05-10 12:28
Actually, maybe it was somebody elses mistake - there are 3 keys distance between s and d on my keyboard, but on a standard querty they are side by side (my hands know where keys are, but occasionally I visually picture them as qwerty)


yousafn
2022-05-10 12:36
There was a few places, no need for a git blame hehe

vijayasaratha.v
2022-05-10 14:28
has joined #pact-js

gemhar
2022-05-10 15:13
In `jest-pact` is there a way to `addInteraction` that will respond with body as blob data (csv, xlsx or pdf).


yousafn
2022-05-10 15:15
It's still v2, I need to update it to v3, and ideally remove or explain that supertest, would normally be the client under test https://github.com/YOU54F/template-jest-pact-typescript/blob/b79ac8ba28f3a2a2b4404596597c852019c474fa/src/pact/client/fileupload.pacttest.ts#L11-L14 and is just used for demo purposes

gemhar
2022-05-10 15:17
Thanks for the prompt response.

viveksingh.kiit
2022-05-10 15:36
has joined #pact-js

radhika.madala
2022-05-10 18:10
has joined #pact-js

oscar.lopez
2022-05-10 20:39
has joined #pact-js

johnathan.pestano
2022-05-11 00:43
has joined #pact-js

marcello.rigan335
2022-05-11 10:11
Hello, i have an Array which can be empty or have 1 or 2 Entries. For multiple Entries i would have used Eachlike? But what about the case if its empty. Do i have to add an extra interaction for that or is there another way ?


marcello.rigan335
2022-05-11 12:39
Thank you for your help

milda.abromaviciute
2022-05-11 12:47
has joined #pact-js

matiasleandronunez
2022-05-11 13:22
has joined #pact-js

croudet
2022-05-11 14:07
has joined #pact-js

alex.bonstrom
2022-05-11 16:19
has joined #pact-js

cody.sims
2022-05-11 16:45
has joined #pact-js

harii.ravii
2022-05-11 22:02
has joined #pact-js

josh.kilazoglou
2022-05-12 04:17
has joined #pact-js

poojakunder1997
2022-05-12 07:25
has joined #pact-js

marcello.rigan335
2022-05-12 09:01
Hello, my existing provider test failed because an array now has more than one entry. So i changed the contract expectation to ```urlParams: eachLike({ urlParameterName:string(), navigatorUrlParameterType: string(), }),``` My Provider test still fails because there are multiple entries. I already used the eachLike feature and didn't have an issue with it. Am i missing something?

matt.fellows
2022-05-12 09:05
Can you please share the generated contract file and the exact error when verifying?

marcello.rigan335
2022-05-12 09:05
1.1) body: $.contextLinks.navigatorGroups.1.navigatorList.0.urlConstructionInformation.urlParams Expected a List with 1 elements but received 3 elements [ { - "navigatorUrlParameterType": "iloveorange", - "urlParameterName": "iloveorange" + "navigatorUrlParameterType": "STANDARD", + "urlParameterName": "location" + }, + { + "navigatorUrlParameterType": "STANDARD", + "urlParameterName": "lat" + }, + { + "navigatorUrlParameterType": "STANDARD", + "urlParameterName": "long" } ]

marcello.rigan335
2022-05-12 09:07
```"urlConstructionInformation": { "baseUrl": { "id": "iloveorange", "description": "iloveorange", "method": "iloveorange", "serviceName": "iloveorange", "uri": "iloveorange" }, "urlParams": [ { "urlParameterName": "iloveorange", "navigatorUrlParameterType": "iloveorange" } ] }```

marcello.rigan335
2022-05-12 09:09
```"$.body.contextLinks.navigatorGroups[1].navigatorList[0].urlConstructionInformation.urlParams": { "min": 1 }, "$.body.contextLinks.navigatorGroups[1].navigatorList[0].urlConstructionInformation.urlParams[*].*": { "match": "type" }, "$.body.contextLinks.navigatorGroups[1].navigatorList[0].urlConstructionInformation.urlParams[*].urlParameterName": { "match": "type" }, "$.body.contextLinks.navigatorGroups[1].navigatorList[0].urlConstructionInformation.urlParams[*].navigatorUrlParameterType": { "match": "type" },```

marcello.rigan335
2022-05-12 10:03
Update: The Test works but only on my local pact broker, on DEV pactbroker it doesnt work. So i compared bothc contracts and they are the same.

matt.fellows
2022-05-12 10:21
hmmm that doesn?t make sense. The Pact broker actually doesn?t care about the contents of the contract. My guess is that the provider test is not validating the same contract. You should be able to see the version of the contract being verified in the logs.

matt.fellows
2022-05-12 10:22
This would mean that the verification process is not selecting the correct pacts from the broker

marcello.rigan335
2022-05-12 10:22
Yes you are exactly right. My versioning is wrong. It verifies the wrong pact.

matt.fellows
2022-05-12 10:22
Just so I?m clear, why are you running a local pact broker? Just for testing purposes? You would usually only hae a single pact broker (not one for Dev, Test, Prod etc.)

marcello.rigan335
2022-05-12 10:22
Yeah its just for Testing Purposes

pekka.kiviniemi
2022-05-12 10:46
has joined #pact-js

sophie.bosse2
2022-05-12 12:45
has joined #pact-js

dimitris.schizas
2022-05-12 16:04
has joined #pact-js

j.shankarnath
2022-05-12 16:37
has joined #pact-js

yesh.veera
2022-05-12 17:35
has joined #pact-js

fabio.been
2022-05-12 18:04
has joined #pact-js

aliboztemir
2022-05-12 19:47
has joined #pact-js

luis.garcia
2022-05-13 09:06
has joined #pact-js

alanbos
2022-05-13 11:25
hi Matt - just following up on this - we found that the issue was that in moving from `@pact_foundation/pact` version `10.0.0-beta.58` to `beta.59` (actually an auto uprev as we were using "^10.0.0-beta.58" so got the update automatically) the pact-core version moved from 13.4.1-beta.18 to 13.6.0. This in turn introduced a dependency uprev on GLIBC from 2.18 to 2.25, which caused o/s issues for existing build pipelines (in e.g. Atlassian BB).

gueorgui
2022-05-13 12:24
Hi folks, we?re running into an issue on CI when installing pact via Yarn: ```Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error: Error while installing binary: Extraction failed for /root/project/node_modules/@pact-foundation/pact-node/standalone/pact-1.88.81-linux-x86_64.tar.gz: Error: Error while installing binary: Checksum rejected for file 'pact-1.88.81-linux-x86_64.tar.gz' with checksum pact-1.88.81-linux-x86_64.tar.gz.checksum at throwError (/root/project/node_modules/@pact-foundation/pact-node/standalone/install.js:42:11) at /root/project/node_modules/@pact-foundation/pact-node/standalone/install.js:335:16 at processTicksAndRejections (node:internal/process/task_queues:96:5) info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. Exited with code exit status 1``` Any clues why the checksum might be getting rejected?

matt.fellows
2022-05-13 13:25
Corporate proxy seems likely

gueorgui
2022-05-13 13:53
Makes sense!

gueorgui
2022-05-13 13:53
Thank you

matt.fellows
2022-05-13 14:03
Was that it?

matt.fellows
2022-05-13 14:03
One way to quickly test is trying installing off network or on a non work laptop

gueorgui
2022-05-13 14:04
I don?t know if it was, this was on Circle CI, maybe something with their network. Re-running the job fixed it eventually

andreas.wiig
2022-05-13 14:18
has joined #pact-js

ocalderin14
2022-05-13 15:20
has joined #pact-js

alan.alie
2022-05-13 15:30
Hi all, I?ve been using typescript to write _?happy path?_ PACT tests without any problem using a pattern like this: ```// PACT test for getBasketById describe('Given we are requesting specific basket', () => { test('When a basket exists', async () => { // set up Pact interaction await provider.addInteraction({ state: 'When the basket exists', uponReceiving: 'get the specified basket', withRequest: interactionRequest.GET_BASKET, willRespondWith: interactionResponse.BASKET_NORMAL_RESPONSE, }); // make request to PACT mock server await getData(provider.mockService.baseUrl + '/basket/' + OK_BASKET_ID); });``` Now that I?m attempting error path tests (the response status is *404*) I get the following error ``` thrown: Object { "errorCode": "BS-002", "errorMessage": "No basket has been found", } 111 | // Failed PACT test for getBasketById 112 | describe('Given we are requesting specific basket', () => { > 113 | test('When the basket does not exists', async () => { | ^ 114 | // set up Pact interaction 115 | await provider.addInteraction({ 116 | state: 'basket does not exists',``` My code for the ?error path? test is as follows: ```// Failed PACT test for getBasketById describe('Given we are requesting specific basket', () => { test('When the basket does not exists', async () => { // set up Pact interaction await provider.addInteraction({ state: 'basket does not exists', uponReceiving: 'get specified basket', withRequest: { method: HTTPMethod.GET, path: '/basket/' + BAD_BASKET_ID, }, willRespondWith: { status: 404, headers: { 'Content-Type': 'application/json' }, body: { errorCode: 'BS-002', errorMessage: 'No basket has been found', }, }, }); // make request to Pact mock server await getData(provider.mockService.baseUrl + '/basket/' + BAD_BASKET_ID); }); });``` How do I handle the thrown object? *PS*: If I change the response status in my code to *200* then the problem disappears - but that?s obviously not what I?m after.

yousafn
2022-05-13 15:46
are you using axios for a client?

alan.alie
2022-05-13 15:46
No. I'm using Fetch

yousafn
2022-05-13 15:47
what happens in your client code when you get a non 2xx response

yousafn
2022-05-13 15:47
does it throw?

yousafn
2022-05-13 15:48
there is regular handling in most frameworks for handling catchs, to expect it to reject and then do your assertions

yousafn
2022-05-13 15:48
or you catch it yourself when invoking the system under test, and then assert


alan.alie
2022-05-13 15:50
Thanks

alan.alie
2022-05-13 15:51
This looks like something I haven't tried :+1::skin-tone-4:

alan.alie
2022-05-13 15:52
I'll take a look at it on Monday :grin:


alan.alie
2022-05-13 15:53
Yeh, I never got that to work :confused:

yousafn
2022-05-13 15:56
hmm, love for you to elaborate when you have time. I have ran that workshop so many times, and do have some niceties that I want to address and get some tests into the repo but it definitely works, possibly not quite OOB because of all things dependencies I believe it was refreshed as part of the https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci which I think is maybe a more reliable path at the moment, the workshops are on my growing list of things to look at

yousafn
2022-05-13 15:58
> Yeh, I never got that to work That is mocha syntax, jest will be diff, unless you are just natively handling it with a try/catch

jyoti.yennam
2022-05-13 17:28
has joined #pact-js

rberger
2022-05-13 21:06
has joined #pact-js

matt.fellows
2022-05-14 13:05
The issue is that http clients tend to throw when they get error status codes. Try/catch or using the JS test framework specific error handing (as above). This isn't a pact specific problem, so hopefully should be quite googleable

jsb0545
2022-05-15 18:55
has joined #pact-js

leon.luu2
2022-05-16 06:43
has joined #pact-js

alan.alie
2022-05-16 08:44
Hi @yousafn /@matt.fellows, thanks for your help.....again :grin:

alan.alie
2022-05-16 08:46
You were correct in identifying that the test framework itself was was causing my problem and throwing the response object. In the end I resolved the issue by wrapping the *getData()* call in a try/catch block and checked the thrown object matched the expected response. ```try { basketObj = await getData(provider.mockService.baseUrl + '/basket/' + BAD_BASKET_ID); } catch (error) { expect(error).toEqual({ errorCode: 'BS-002', errorMessage: 'No basket has been found', }); }```

matt.fellows
2022-05-16 09:01
:+1:

samikshaphulzele
2022-05-16 09:53
has joined #pact-js

alanbos
2022-05-16 11:32
I have a contract verification failure moving from pact-js beta.51 to beta.58. With this contract: ``` provider .given('fooByIds') .uponReceiving('a request for existing Foo by id') .withRequest({ method: 'GET', path: '/foo', query: { id: fromProviderState('${id}', '1') } }) .willRespondWith({ ... })``` In beta.51 this generated: ``` "request": { "generators": { "query": { "id": { "expression": "${id}", "type": "ProviderState" } } },``` But in beta.58 this generates ``` "request": { "generators": { "query": { "$.id[0]": { "expression": "${id}", "type": "ProviderState" } } },``` As you can see the key under `query` is now `$.id[0]` instead of just `id`, which causes the provider verification to fail. Is this a bug in beta.58, or am I just not driving it correctly?

matt.fellows
2022-05-16 12:36
@uglyog any ideas?

josh.king
2022-05-16 14:38
is there an equivalent to @IgnoreNoPactsToVerify in pact-js?

shiva.idc
2022-05-17 00:33
has joined #pact-js

tjones
2022-05-17 05:42
has joined #pact-js

tjones
2022-05-17 05:45
No. However, the underlying core does support it, so it's not a substantial change.

tjones
2022-05-17 05:46
(I think, also, the ruby core already ignores no pacts to verify - so it might be the default)

joseph.joyce
2022-05-17 12:15
has joined #pact-js

vasanth.s
2022-05-17 13:36
has joined #pact-js

sri.kasturi
2022-05-17 14:21
has joined #pact-js

carlosh.carmo2
2022-05-17 22:43
has joined #pact-js

gchursov
2022-05-18 09:43
has joined #pact-js

berk.safranbolulu
2022-05-18 10:18
has joined #pact-js

berk.safranbolulu
2022-05-18 10:19
:wave: Hello, team!

berk.safranbolulu
2022-05-18 10:19
``` console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:152:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET http://127.0.0.1:3001/merchants```

berk.safranbolulu
2022-05-18 10:20
I got this error for a while. Everything looks perfect, but I couldn?t understand where problem is.

matt.fellows
2022-05-18 10:30
The error is exactly as it states - it expected a call to `GET http://127.0.0.1:3001/merchants` but did not receive one

matt.fellows
2022-05-18 10:36
It means your API client code being tested, is not sending the request to the mock service configured by Pact. Pact does not automatically mock your API calls - you need to ensure your API client is correctly configured to poitn at the Pact mock service. Given you have constructed a Pact object with name `provider` and you are using a `DogApiClient` class to send requests to your `Dog Service`, you can dynamically configure your API client as follows: ```provider.setup().then(opts => { dogService = new DogApiClient({ `http://${opts.host}`, port: opts.port }) })```

alanbos
2022-05-18 11:00
I've worked around it for now with a post pact test run step which massages the offending query generators. But it would be good to know if its a bug.

larshoogma
2022-05-18 11:34
has joined #pact-js

malvika0810
2022-05-18 12:17
has joined #pact-js

berk.safranbolulu
2022-05-18 12:31
Hello Matt. Thanks for quick response. My spec file is here: ```/* eslint-disable no-undef */ /* eslint-disable no-console */ jest.unmock("axios"); import axios from "axios"; import MockAdapter from "axios-mock-adapter"; import { Pact, Matchers } from "@pact-foundation/pact"; import { API } from "./api"; const path = require("path"); const { string, boolean } = Matchers; jest.setTimeout(30000); let mockService; const mock = new MockAdapter(axios); const expectedResponse = { status: true, message: "??lem ba?ar?l?.", }; const pactProvider = new Pact({ port: 3001, consumer: "mcontent-consumer", provider: "mcontent-provider", logLevel: "debug", spec: 2, cors: true, }); beforeAll(() => pactProvider.setup().then(() => { mockService = new API(pactProvider.mockService.baseUrl) })); afterAll(() => pactProvider.finalize()); describe("Pact Contract Testing", () => { describe("retrieving a merchant by id", () => { test("Test deneme", async () => { try { await pactProvider.addInteraction({ state: "a merchant with Merchant ID exists", uponReceiving: "a request to get a merchant", withRequest: { method: "GET", path: pactProvider.mockService.baseUrl + "/merchants", }, willRespondWith: { status: 404, body: { status: boolean(true), message: string("??lem ba?ar?l?."), }, }, }); mock.onGet("http://127.0.0.1:3001/merchants").reply(200, expectedResponse, { headers: {} }); const response = await mockService.getMerchantById(); // Assert - did we get the expected response expect(response).toStrictEqual(expectedResponse); await pactProvider.verify(); } catch (error) { console.log("error", error); } }); // afterEach(() => pactProvider.verify().then((err) => console.log(err).catch((err) => console.log(err)))); }); });```

berk.safranbolulu
2022-05-18 12:32
Also, you find the API page below: ```import axios from "axios"; export class API { constructor(url) { this.url = url; } async getMerchantById() { console.log("this.url", this.url); return axios.get(this.url + "/merchants").then((data) => data.data); } } export default API;```

berk.safranbolulu
2022-05-18 12:32
I got this error: ```[2022-05-18 12:31:18.699 +0000] INFO (78491 on THB-ARG-437.local): pact-node@10.17.2: Creating Pact Server with options: {"timeout":30000,"consumer":"mcontent-consumer","cors":true,"dir":"/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/pacts","host":"127.0.0.1","log":"/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"mcontent-provider","spec":2,"ssl":false,"port":3001,"pactFileWriteMode":"overwrite"} [2022-05-18 12:31:18.712 +0000] DEBUG (78491 on THB-ARG-437.local): pact-node@10.17.2: Starting pact binary '/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service', with arguments [service --consumer mcontent-consumer --cors true --pact_dir /Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/pacts --host 127.0.0.1 --log /Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/logs/pact.log --log-level DEBUG --provider mcontent-provider --pact_specification_version 2 --ssl false --port 3001 --pact-file-write-mode overwrite] [2022-05-18 12:31:18.718 +0000] DEBUG (78491 on THB-ARG-437.local): pact-node@10.17.2: Created '/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service' process with PID: 78509 [2022-05-18 12:31:19.491 +0000] DEBUG (78491 on THB-ARG-437.local): pact-node@10.17.2: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2022-05-18 12:31:19.492 +0000] DEBUG (78491 on THB-ARG-437.local): pact-node@10.17.2: INFO WEBrick::HTTPServer#start: pid=78509 port=3001 [2022-05-18 12:31:19.748 +0000] INFO (78491 on THB-ARG-437.local): pact@9.17.3: Setting up Pact with Consumer "mcontent-consumer" and Provider "mcontent-provider" using mock service on Port: "3001" console.log this.url http://127.0.0.1:3001 at API._callee$ (src/universal/partials/AboutSeller/pact_test/api.js:9:13) console.error at node_modules/@pact-foundation/src/httpPact.ts:151:17 console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:152:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET http://127.0.0.1:3001/merchants See /Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/logs/pact.log for details. at node_modules/@pact-foundation/src/httpPact.ts:153:17 console.log error Error: Pact verification failed - expected interactions did not match actual. at new VerificationError (/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/node_modules/@pact-foundation/pact/src/errors/verificationError.js:19:42) at /Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/node_modules/@pact-foundation/src/httpPact.ts:157:17 at processTicksAndRejections (internal/process/task_queues.js:95:5) at _callee$ (src/universal/partials/AboutSeller/pact_test/aboutSeller.spec.js:61:17)```

berk.safranbolulu
2022-05-18 12:33
Although I have tried too many things, I couldn?t pass this ?Verification failed!? issue.

berk.safranbolulu
2022-05-18 12:39
Do I need to write Pact VerifiedProvider standalone javascript code?

edouard.lopez
2022-05-18 12:58
I submitted a tiny PR to correct the `yarn` install command in the readme, please see https://github.com/pact-foundation/pact-js/pull/867/

nishant.shah
2022-05-18 13:38
has joined #pact-js

lukasz.wlosek
2022-05-19 09:04
Hi, I am trying to save a uuid in my provider side verification, where this is saved in provider states, in order to do this I have to match the uuid that I pass in my consumer tests, I was wondering if this uuid can be dynamic, do I do not have to match it, thought the term() matcher would help but it did not work like so ```.withRequest({ method: 'GET', path: term({ generate: '/user/9ae9b264-f181-46ea-a468-4919c48fbe94', matcher: '/user/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' }), // we want to be strict with what we send out https://docs.pact.io/getting_started/matching#request-matching headers: { Accept: 'application/json, text/plain, */*', Authorization: string('Bearer testToken') } })``` when I save a different uuid setup in the provider side the verifaction fails, any tips on how to achieve this, read about provider state injected values, but it does not seem to be yet implemented in pact-js?

berk.safranbolulu
2022-05-19 09:53
Still got `Missing requests` issue @matt.fellows

berk.safranbolulu
2022-05-19 09:53
How to solve this problem?

matt.fellows
2022-05-19 10:04
I?m 99% sure you aren?t sending the requests to the mock service. Can you please share your code and the pact.log file so we can see? There are debugging instructions in the Pact JS readme that you can follow


matt.fellows
2022-05-19 10:06
(you?re right, it?s not in the current mainline, but is in the beta)

lukasz.wlosek
2022-05-19 10:07
Alright, thanks

berk.safranbolulu
2022-05-19 10:14
I have sent all the files on DM.

berk.safranbolulu
2022-05-19 10:14
@matt.fellows

matt.fellows
2022-05-19 10:53
For others coming here, Berk is using nock which is going to interfere and mock network requests. You don?t want to do that, as you need to be able to send the requests to the pact mock service

vorashil.farzaliyev
2022-05-19 10:59
has joined #pact-js

berk.safranbolulu
2022-05-19 11:10
I have to use `jest.unmock("axios")` on the top of page. How to change this code according to `Pact`?

matt.fellows
2022-05-19 11:11
I?m not sure what you?re asking, sorry

matt.fellows
2022-05-19 11:12
basically, don?t mock your API client code - we are testing the API client and it needs to send requests to the pact mock server

berk.safranbolulu
2022-05-19 11:18
```I, [2022-05-19T14:17:51.552228 #94845] INFO -- : Registered expected interaction GET /product/10 D, [2022-05-19T14:17:51.552399 #94845] DEBUG -- : { "description": "get product with ID 10", "providerState": "product with ID 10 exists", "request": { "method": "GET", "path": "/product/10", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { } }, "metadata": null } W, [2022-05-19T14:17:51.574747 #94845] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /product/10 W, [2022-05-19T14:17:51.574788 #94845] WARN -- : Missing requests: GET /product/10 I, [2022-05-19T14:17:51.587009 #94845] INFO -- : Cleared interactions```

berk.safranbolulu
2022-05-19 11:18
here is the log file.

berk.safranbolulu
2022-05-19 11:18
the latest version of the pact.spec.js file: ```import path from "path"; import { Pact, Matchers } from "@pact-foundation/pact"; import API from "./api"; const { like } = Matchers; const provider = new Pact({ consumer: "FrontendWebsite", provider: "ProductService", log: path.resolve(process.cwd(), "logs", "pact.log"), logLevel: "debug", dir: path.resolve(process.cwd(), "pacts"), spec: 2, }); describe("API Pact test", () => { beforeAll(() => provider.setup()); afterEach(() => provider.verify()); afterAll(() => provider.finalize()); describe("getting one product", () => { it("ID 10 exists", async () => { // "it" requires not "test" // set up Pact interactions await provider.addInteraction({ state: "product with ID 10 exists", uponReceiving: "get product with ID 10", withRequest: { method: "GET", path: "/product/10", headers: { Accept: "application/json", }, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json", }, body: {}, }, }); const newApi = new API(provider.mockService.baseUrl); // make request to Pact mock server const response = await newApi.getProduct("10"); expect(response).toEqual({}); }); }); });```

berk.safranbolulu
2022-05-19 11:20
@matt.fellows, Do I need to run my backend server in the background?

matt.fellows
2022-05-19 11:22
no, the pact mock server stands in for that

matt.fellows
2022-05-19 11:22
what does the `pact.log` file say?

matt.fellows
2022-05-19 11:22
also, what is the contents of `api.js`?

matt.fellows
2022-05-19 11:22
Ideally, if you can share a GH repo we can download to test, that will speed this up

berk.safranbolulu
2022-05-19 11:22
*pact.log* ```I, [2022-05-19T14:22:18.662359 #95104] INFO -- : Registered expected interaction GET /product/10 D, [2022-05-19T14:22:18.662506 #95104] DEBUG -- : { "description": "get product with ID 10", "providerState": "product with ID 10 exists", "request": { "method": "GET", "path": "/product/10", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { } }, "metadata": null } W, [2022-05-19T14:22:18.682967 #95104] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /product/10 W, [2022-05-19T14:22:18.683009 #95104] WARN -- : Missing requests: GET /product/10 I, [2022-05-19T14:22:18.694772 #95104] INFO -- : Cleared interactions```

berk.safranbolulu
2022-05-19 11:23
*api.js* ```import axios from "axios"; export class API { constructor(url) { if (url === undefined || url === "") { url = "http://localhost:3001"; } this.url = url; console.log('this.url', this.url) } async getProduct(id) { return axios.get(this.url + "/products/" + id).then((r) => r.data); } } export default API;```

matt.fellows
2022-05-19 11:24
hmm, that `getProduct` method sends requests to `/products` not `/product`

berk.safranbolulu
2022-05-19 11:25
Same error :confused:

berk.safranbolulu
2022-05-19 11:25
```I, [2022-05-19T14:25:28.546777 #95323] INFO -- : Registered expected interaction GET /products/10 D, [2022-05-19T14:25:28.546928 #95323] DEBUG -- : { "description": "get product with ID 10", "providerState": "product with ID 10 exists", "request": { "method": "GET", "path": "/products/10", "headers": { "Accept": "application/json" } }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { } }, "metadata": null } W, [2022-05-19T14:25:28.569317 #95323] WARN -- : Verifying - actual interactions do not match expected interactions. Missing requests: GET /products/10 W, [2022-05-19T14:25:28.569359 #95323] WARN -- : Missing requests: GET /products/10 I, [2022-05-19T14:25:28.581871 #95323] INFO -- : Cleared interactions```

matt.fellows
2022-05-19 11:31
I?m not 100% sure why, but I noticed above that your http client seemed to want to send requests to `3001` still - can you confirm / print out the URL that `API` thinks it?s sending requests to?

berk.safranbolulu
2022-05-19 11:32
Sure, here is the console output to detect the URL: ```[2022-05-19 11:32:29.785 +0000] INFO (95814 on THB-ARG-437.home): pact-node@10.17.2: Creating Pact Server with options: {"timeout":30000,"consumer":"FrontendWebsite","cors":false,"dir":"/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/pacts","host":"127.0.0.1","log":"/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"ProductService","spec":2,"ssl":false,"pactFileWriteMode":"overwrite"} [2022-05-19 11:32:29.795 +0000] DEBUG (95814 on THB-ARG-437.home): pact-node@10.17.2: Starting pact binary '/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service', with arguments [service --consumer FrontendWebsite --cors false --pact_dir /Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/pacts --host 127.0.0.1 --log /Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/logs/pact.log --log-level DEBUG --provider ProductService --pact_specification_version 2 --ssl false --pact-file-write-mode overwrite] [2022-05-19 11:32:29.801 +0000] DEBUG (95814 on THB-ARG-437.home): pact-node@10.17.2: Created '/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/node_modules/@pact-foundation/pact-node/standalone/darwin-1.88.83/pact/bin/pact-mock-service' process with PID: 95823 [2022-05-19 11:32:30.314 +0000] DEBUG (95814 on THB-ARG-437.home): pact-node@10.17.2: INFO WEBrick 1.3.1 INFO ruby 2.2.2 (2015-04-13) [x86_64-darwin13] [2022-05-19 11:32:30.315 +0000] DEBUG (95814 on THB-ARG-437.home): pact-node@10.17.2: INFO WEBrick::HTTPServer#start: pid=95823 port=64311 [2022-05-19 11:32:30.315 +0000] INFO (95814 on THB-ARG-437.home): pact-node@10.17.2: Pact running on port 64311 FAIL test_pact/api.pact.spec.js API Pact test getting one product ? ID 10 exists (43 ms) ? API Pact test ? getting one product ? ID 10 exists Pact verification failed - expected interactions did not match actual. at new VerificationError (node_modules/@pact-foundation/pact/src/errors/verificationError.js:19:42) at node_modules/@pact-foundation/src/httpPact.ts:157:17 Test Suites: 1 failed, 1 passed, 2 total Tests: 1 failed, 1 passed, 2 total Snapshots: 0 total Time: 3.17 s Ran all test suites matching /\/test_pact/i. Watch Usage: Press w to show more.[2022-05-19 11:32:30.831 +0000] INFO (95814 on THB-ARG-437.home): pact@9.17.3: Setting up Pact with Consumer "FrontendWebsite" and Provider "ProductService" using mock service on Port: "64311" console.log this.url http://127.0.0.1:64311 at new API (test_pact/api.js:9:13) console.error at node_modules/@pact-foundation/src/httpPact.ts:151:17 console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:152:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /products/10 See /Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/logs/pact.log for details. at node_modules/@pact-foundation/src/httpPact.ts:153:17 [2022-05-19 11:32:30.879 +0000] INFO (95814 on THB-ARG-437.home): pact@9.17.3: Pact File Written [2022-05-19 11:32:30.880 +0000] INFO (95814 on THB-ARG-437.home): pact-node@10.17.2: Removing Pact process with PID: 95823 [2022-05-19 11:32:30.881 +0000] DEBUG (95814 on THB-ARG-437.home): pact-node@10.17.2: INFO going to shutdown ... INFO WEBrick::HTTPServer#start done. [2022-05-19 11:32:30.882 +0000] INFO (95814 on THB-ARG-437.home): pact-node@10.17.2: Deleting Pact Server with options: {"timeout":30000,"consumer":"FrontendWebsite","cors":false,"dir":"/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/pacts","host":"127.0.0.1","log":"/Users/bsafranbolulu/Desktop/Projects/MerchantContent/mc-frontend/logs/pact.log","logLevel":"DEBUG","pactfileWriteMode":"overwrite","provider":"ProductService","spec":2,"ssl":false,"port":64311,"pactFileWriteMode":"overwrite"}```

berk.safranbolulu
2022-05-19 11:33
I think that the URL is correct.

berk.safranbolulu
2022-05-19 11:33
``` using mock service on Port: "64311" console.log this.url http://127.0.0.1:64311```

matt.fellows
2022-05-19 11:35
yep, that does look correct

matt.fellows
2022-05-19 11:37
Is there anything else in the code base that could be interfering? If you could please create an example pact project I can clone and test locally, I think that?s the next course of action. This code looks OK to me, so I think I?ve exhausted the options through words :stuck_out_tongue:

berk.safranbolulu
2022-05-19 11:40
This project is a kind of microfrontend project that we built from scratch. It?s based on Nodejs but we are able to write React codes here. But, I think that I should use the node package for Pact. What do you think about that?

matt.fellows
2022-05-19 11:42
that?s correct, you still use the node package because it should work for your testing frameworks like jest etc.

berk.safranbolulu
2022-05-19 12:14
So It means you suggest to use `@pact-foundation/node` right?

matt.fellows
2022-05-19 12:16
I don?t think that?s a package

matt.fellows
2022-05-19 12:16
`@pact-foundation/pact`

berk.safranbolulu
2022-05-19 12:18
I got it. I can?t share the project due to being private for the company.

berk.safranbolulu
2022-05-19 12:18
Do you have any method for detecting the issue with all the details?

matt.fellows
2022-05-19 12:19
if I could do that, I?d be a billionaire!

berk.safranbolulu
2022-05-19 12:20
hahaha :smile:

matt.fellows
2022-05-19 12:20
So, we know the example project works. All I can reason at this point is that there is some other dependency/code/xyz that is interfering here

matt.fellows
2022-05-19 12:20
is there a jest config that is auto-mocking everything?

berk.safranbolulu
2022-05-19 12:21
I had a jest config but I have already deleted it.

matt.fellows
2022-05-19 12:21
so, delete everything until you have the working example project, and then one by one add it back

berk.safranbolulu
2022-05-19 12:23
I?m agree with you, For example: ```jest.unmock("axios") import API from "./api"; import nock from "nock"; describe("API", () => { test("get product ID 50", async () => { const product = { id: "50", type: "CREDIT_CARD", name: "28 Degrees", version: "v1", }; const url = "http://localhost:3001" const api = new API(url) nock(api.url).get("/products/50").reply(200, product, { "Access-Control-Allow-Origin": "*" }); const respProduct = await api.getProduct("50"); expect(respProduct).toEqual(product); }); });``` Tests are not working without the code I added on the top.

berk.safranbolulu
2022-05-19 12:23
It means jest automatically mocks everything.

berk.safranbolulu
2022-05-19 12:24
We need to pass a parameter `axios` when we?re using `jest.unmock()` method. That?s why I asked before, what should I write as a parameter on `jest.unmock()` method If I want to use it for `pact?`

matt.fellows
2022-05-19 12:29
> We need to pass a parameter `axios` when we?re using `jest.unmock()` method. That?s why I asked before, what should I write as a parameter on `jest.unmock()` method If I want to use it for `pact?` well, it depends on what it mocks. I don?t know what tools you?re using so I can?t say (I know a bit more now, of course)

jlcrazzy
2022-05-19 13:38
has joined #pact-js

galveznairon
2022-05-19 13:40
has joined #pact-js

sunny.cheung
2022-05-19 20:43
has joined #pact-js

chantalnitz
2022-05-20 07:22
has joined #pact-js

tjones
2022-05-20 08:25
I've hit the windows long path issue in CI, where I don't have much control over what the path is. Has anyone got any tips for working around this?

robert
2022-05-20 08:47
has joined #pact-js

baris.kucuk.atilim
2022-05-20 09:47
has joined #pact-js

rajnavakoti
2022-05-20 12:42
has joined #pact-js

akke.luukkonen
2022-05-20 12:46
Have no prior experience on the issue, but my immediate though of a dumb workaround would be to symlink the target files to some shorter path. Can't remember how those were processed on Windows and whether a symlink will resolve to the full path when being accessed, but at least I'd expect hard links would work if you can create those in the CI :thinking_face:

mlund
2022-05-20 21:04
has joined #pact-js

pavi.dealwis
2022-05-21 03:28
has joined #pact-js

tjones
2022-05-21 03:42
I like this idea. Looks like I can't break out of the `{repo-name}/{repo-name}` path on github actions, or my windows fu isn't good enough (possibly both)

tjones
2022-05-21 03:43
I guess a workaround could be to rename the repo, but that seems extreme (and it's public, so I kinda dont want to)

tjones
2022-05-21 03:44
you can give github actions a working directory, but it puts it at the end: `{repo-name}/{repo-name}/{working-dir}`, and you can't use `..\..\`

endika2
2022-05-21 10:52
has joined #pact-js

6eo2ge
2022-05-22 13:17
has joined #pact-js

eugene.baranovsky
2022-05-22 23:25
has joined #pact-js

kendrickbong1996
2022-05-23 02:47
Anyone here used Pact with aws-sdk-mock ? Am getting problems with hitting pact trying to verify the endpoint ```Actual interactions do not match expected interactions for mock MockService.```

tjones
2022-05-23 02:49
The context around this error message will tell you why it thinks that

tjones
2022-05-23 02:49
However, if you're using `aws-sdk-mock`, then you're probably not sending real requests. So, pact will be unhappy, because it wants the real request

tjones
2022-05-23 02:50
However, if you're using pact against the AWS sdk, you'll be in for a bad time, because the HTTP calls that that AWS SDK makes aren't part of the API contract

tjones
2022-05-23 02:50
what are you trying to do?

kendrickbong1996
2022-05-23 02:51
in a nutshell, trying to implement pact with lambda functions.

matt.fellows
2022-05-23 02:52
What if we allowed the location of the standalone installation to be customised? e.g. rather than embedded in the project folder, we allowed it to be put in `c:\Temp` ?

matt.fellows
2022-05-23 02:52
I think that should sidestep the problem?

tjones
2022-05-23 02:52
Do you mean trying to test a lambda function with pact, or you're trying to test the http calls that your lambda makes with pact?

tjones
2022-05-23 02:52
(or are you using message pacts?)

kendrickbong1996
2022-05-23 02:53
Yes, test a lambda function with pact

tjones
2022-05-23 02:53
ok. So, you have a pact file from your consumer, and your lambda is the provider?

kendrickbong1996
2022-05-23 02:54
Correct

tjones
2022-05-23 02:54
How is your lambda connected? Via an API gateway?

tjones
2022-05-23 02:55
What you would usually do is spin up your provider (in this case, you probably deploy it to your test env, or wherever) and then run the pact verifier against it

tjones
2022-05-23 02:56
In this way, there would be no `aws-sdk-mock`, because you're spinning up your real provider

tjones
2022-05-23 02:57
however, if the lambda requires anything upstream, like a DB or other AWS services, you may want to mock those using the pact state change

tjones
2022-05-23 02:57
usually I would do this as the first step in your lambda - where you would normally configure all those connectors, you just configure mock ones instead

tjones
2022-05-23 02:59
alternatively, you can not deploy it, and test it locally. Then you could use aws-sdk-mock, I guess

tjones
2022-05-23 03:00
it all depends on how your lambda is getting the http event

kendrickbong1996
2022-05-23 03:00
Apologies im fairly new to aws but yes the actual function that is called is connected via an api gateway with the aws-sdk. However in our test files we are using the aws-sdk-mock so that it doesnt need to call the actual endpoint.

tjones
2022-05-23 03:00
There's also `localstack`, but my experience with that has not been positive


tjones
2022-05-23 03:00
Pact needs to call the actual endpoint

tjones
2022-05-23 03:00
that's what's under test

tjones
2022-05-23 03:01
`aws-sdk-mock` is for mocking out aws sdk calls - I assumed that your lambda is calling some AWS services, but do you mean that you're using it to mock the whole lambda invocation?

tjones
2022-05-23 03:02
I think I'm confused about what you're trying to do

harris
2022-05-23 03:04
has joined #pact-js

tjones
2022-05-23 03:04
I think that's a good idea, but I think it won't work for my situation, which is that I don't seem to have permissions anywhere other than the doubled repo name

tjones
2022-05-23 03:05
I worked around it by disabling windows builds

tjones
2022-05-23 03:05
...not ideal, but it's not a huge problem in my case. However, this might affect other users of github actions who need windows builds

kendrickbong1996
2022-05-23 03:09
ahh i think i see where this is wrong. Sorry the test file is written by someone else. and it seems that they've used aws-sdk-mock to mock the whole lambda thingy. then calling our actual lambda function to see if the response matches the mocked lambda invocation

kendrickbong1996
2022-05-23 03:09
here's the code snippet. ``` test('Should invoke the ConsumeLambda.', () => { AWSMock.setSDKInstance(AWS); AWSMock.mock('Lambda', 'invoke', function mockedInvoke(params, callback) { callback(null, { Payload: { statusCode: 200, body: { message: 'This token is valid', metadata: {} } } }); }); return invokeConsumeLambda('token', 'VALIDATE').then(data => { expect(data).toMatchObject({ statusCode: 200, body: { message: 'This token is valid', metadata: {} } }); }); });```

tjones
2022-05-23 03:10
I don't know what is going on there, tbh

tjones
2022-05-23 03:10
it sounds like maybe there's no API gateway, and you're invoking the lambda directly?

matt.fellows
2022-05-23 03:11
What do you think about the idea of changinsg the install path?

tjones
2022-05-23 03:11
`invokeConsumeLambda` <-- I think this is using the mock set up, rather than invoking it directly

kendrickbong1996
2022-05-23 03:11
so invokeConsumeLambda (bad name i know) is the actual function that calls aws with its aws endpoints and stuff

tjones
2022-05-23 03:11
So this is the consumer side, not the provider size

kendrickbong1996
2022-05-23 03:12
yes this is on consumer side. the provider is `invokeConsumeLambda`

tjones
2022-05-23 03:12
yes, except it doesn't, because the code at the top just mocked out aws endpoints

kendrickbong1996
2022-05-23 03:12
Correct

tjones
2022-05-23 03:12
So, this code illustrates the kind of problem that pact solves

tjones
2022-05-23 03:13
what's happening here is that you're marking your own exam

tjones
2022-05-23 03:13
"hey, I'm gonna mock this, so it returns X" "now I'll call it and check it returns X"

kendrickbong1996
2022-05-23 03:13
yeap i see it now

kendrickbong1996
2022-05-23 03:13
redundant test

tjones
2022-05-23 03:14
Pact has two more steps: "hey, I'm gonna mock this, so it returns X" "now I'll call it and check it returns X" "Ok, I'll write that down in the pact file that when I call with Y, it returns X" Then later "I'm going to check that the provider really does return X when called with Y"

tjones
2022-05-23 03:16
The test shouldn't be entirely redundant, because usually `invokeConsumeLambda` would do things like: ? Know how to make the call ? Know how to marshal the request (eg `getUser(29)` becomes `GET /some/path/user/29`) ? Know how to unmarshall the response

tjones
2022-05-23 03:16
however, since the code is expecting the exact response from the AWS sdk, I think there's no unmarshalling going on

tjones
2022-05-23 03:18
Other nice things about pact: ? You only test the things you need - so in this case, the `metadata: {}` is returned. I bet you don't need it, so you don't need to tell pact about it

tjones
2022-05-23 03:18
? You're testing that your client really can send the request

tjones
2022-05-23 03:18
That last point is nice, because it means that you catch things like incorrectly invoked http library.

tjones
2022-05-23 03:19
I think it will help some people, but I think it might be more trouble than it's worth

tjones
2022-05-23 03:20
depends how far away the rust core is

tjones
2022-05-23 03:20
I think changing the install path won't work for CI

tjones
2022-05-23 03:20
and for non-CI changing the project path is largely ok

kendrickbong1996
2022-05-23 03:21
I see thank you so much for your advice. Right now the problem is that on the .addInteraction() my withRequest parameter is empty because i dont know what the endpoint is. So am i correct to assume that i need to set up the api gateway trigger on the lambda function and point it there ?

tjones
2022-05-23 03:21
That's what I would do

tjones
2022-05-23 03:22
note that your consumer test doesn't actually hit the real provider

kendrickbong1996
2022-05-23 03:22
yes that i know now

tjones
2022-05-23 03:22
the consumer test will talk to pact

tjones
2022-05-23 03:22
then when you go to test the provider, your real provider will be invoked by pact

tjones
2022-05-23 03:23
real consumer -> pact pact -> real provider

tjones
2022-05-23 03:23
> because i dont know what the endpoint is. Yeah. This is the problem with using pact to test the AWS sdk. The requests are opaque

kendrickbong1996
2022-05-23 03:24
:disappointed:

tjones
2022-05-23 03:24
Well, it's kind of like a library. You don't test the DB connection part of a postgres lib

tjones
2022-05-23 03:25
Similarly, you don't need to test the AWS connection part of the AWS SDK

tjones
2022-05-23 03:26
However, in this case, I think: ? You could continue with aws-sdk-mock, but you want some way to know that the mocked response is what the real lambda produces ? The returned value from `aws-sdk-mock` suggests that the design of the layers could be improved ? If you can change the design to bring in an API gateway, then you can just make an HTTP request as normal. Then you can use pact, and also your consumer implementation doesn't even need to know it's contacting AWS

tjones
2022-05-23 03:29
> The returned value from aws-sdk-mock suggests that the design of the layers could be improved Because the calling layer knows that it's a lamdba API response object. It shouldn't know that - probably it should just get ```{ message: 'This token is valid', metadata: {} }``` (although I don't know your application, so it's hard to say for sure) - this is unrelated to pact / aws-sdk-mock - it's just something I noticed

abhiattipra
2022-05-23 06:04
has joined #pact-js

ruben.perezg
2022-05-23 06:39
has joined #pact-js

max.bruns
2022-05-23 07:13
has joined #pact-js

uglyog
2022-05-23 08:44
That is not correct, it is a regression

alanbos
2022-05-23 08:53
Thanks - i cant move up to beta.59 for other reasons right now, so does this need raising as an issue?

hello560
2022-05-23 12:23
has joined #pact-js

venky.hodigere
2022-05-23 14:54
has joined #pact-js

prerit.jain
2022-05-23 16:27
has joined #pact-js

evan
2022-05-23 16:48
has joined #pact-js

evan
2022-05-23 16:50
Hey all :wave: ! Any fix/workaround for getting > Cannot find binary for platform 'linux' with architecture 'arm64' > ... during install?

yousafn
2022-05-23 17:10
Could provide a little more context? ? machine specs? ? what you are trying to install? ? what version?

evan
2022-05-23 17:15
This is part of a Docker build pipeline. The base image is Alpine, the host machine is an Apple M1 chipset, and trying to install `@pact-foundation/pact` version `9.16.0`

yousafn
2022-05-23 17:35
have you got rosetta in your container? tried setting the `--platform linux/amd64` on your docker command see https://github.com/pact-foundation/pact-js-core/issues/264 for additional context.

evan
2022-05-23 17:42
Haven't tried setting the platform flag. I'll give that a whirl...

manuel.porto
2022-05-23 17:56
has joined #pact-js

evan
2022-05-23 18:35
@yousafn@yousafn@yousafn Adding the --platform tag worked.

evan
2022-05-23 18:36
Ooof, sorry for all the @-mention spam on that last message. The Slack client for my iPad is acting buggy.

evan
2022-05-23 18:36
The flag did slow down the build quite a bit, though.

evan
2022-05-23 18:36
Any word on when native linux/arm64 binaries will be made available?

yousafn
2022-05-23 18:46
Slower than not working?

yousafn
2022-05-23 18:47
Don't worry about triple tags happens to me all the time. Slack things haha

yousafn
2022-05-23 18:48
Creating the build is trivial but testing it without macOS containers in CI causes difficulties, GH doesn't have arm64 runners. We could get a container on aws but it's costs monies. There was a gh issue where someone asked, will dig it out :)

evan
2022-05-23 18:48
Not sure I understand the question. The flag works--the build succeeds--but where the build may have taken 1 minute before, now it takes 5 minutes. I'm happy things work, but it would be nice to not have to pay that time cost repeatedly, ya know?

evan
2022-05-23 18:49
This pipeline is part of a development pipeline, so it's likely the image will need to be rebuilt constantly, so those extra minutes add up.

yousafn
2022-05-23 18:51
You mentioned it didn't work before because of the error? But now it works but it's slower. Sorry replaying in a checkout queue Maybe I'm not understanding why it's slower without the specifics. I haven't ran or looked for perf benchmarked between Native intel and m1 in Rosetta emulation mode. I haven't noticed any discernible impact on my personal machine, so it may be something else at play

evan
2022-05-23 18:53
I imagine the increased slowness isn't specific to Pact, but rather because the entire image needs to be built in emulation mode. As Pact is the only thing in the pipeline that requires emulation, though, everything else has to go through it too.

yousafn
2022-05-23 18:56
Got you buddy, I'll dig out the gh issue and maybe it's something you may want to pick up, if it's going to be valuable and say you lots of build time. I'm sure a few users would appreciate it. I did consider a self hosted runner as I have 2 m1 MacBooks here when I briefly touched on it

yousafn
2022-05-23 19:01
Multiple open issues across the org https://github.com/search?q=org%3Apact-foundation+arm64&type=issues Matt recently put a request in for an m1 runner in the aws account for pact foundation https://github.com/pact-foundation/pact-net/pull/365#issuecomment-1111550122 Which we are waiting to be actioned


yousafn
2022-05-23 19:02
This is what we really want <3 but it's bigger than just Pact! https://github.com/actions/virtual-environments/issues/2187

evan
2022-05-23 19:04
I hope that lands too!

yousafn
2022-05-23 19:09
Oh one last thing before I leave you be, could you try upgrade pact-js to the latest version. Your version is from July 2021, and there was some work done in the later versions to make it play nicer on m1 machines, in pact-node. Maybe worth trying that, but without the platform flag set on docker. Cheers for reaching out!

evan
2022-05-23 19:09
Cool, I'll give that a shot. Thanks for your help and prompt replies! Always appreciated. :smile:

bethskurrie
2022-05-24 00:00
We might just have to go with a manual build and release until we can get a suitable hosted environment.

bethskurrie
2022-05-24 00:00
When I get my M1 set up I can have a look at it.

bethskurrie
2022-05-24 00:01
Back in the day, that's how I used to do all the releases!

matt.fellows
2022-05-24 00:01
It does work on M1 mac arm, but not _linux_ arm

bethskurrie
2022-05-24 00:01
oooh. right. can't help there

matt.fellows
2022-05-24 00:01
(we publish core libs for apple arm, but not linux)

matt.fellows
2022-05-24 00:01
yeah

matt.fellows
2022-05-24 00:01
sad

matt.fellows
2022-05-24 00:01
Waiting for Github to have arm agents

matt.fellows
2022-05-24 00:02
AWS haven?t approved us for ARM EC2 yet either :angry:

yousafn
2022-05-24 00:09
What is the world coming to when Bezo's won't even take your money.

evan
2022-05-24 00:13
I'm most interested in linux/arm64; the fact my host is an M1 is incidental in this case--my target is Alpine Linux, not macOS. In some cases my host could be a RaspberryPi cluster.

matt.fellows
2022-05-24 00:50
I?ll be honest, alpine support is plausible but probably unlikely. See https://github.com/pact-foundation/pact-net/issues/387#issuecomment-1114365283 as to why

abhishek.lamba
2022-05-24 09:25
has joined #pact-js

stefan.friese
2022-05-24 09:32
has joined #pact-js

bharath.shetty
2022-05-24 09:33
has joined #pact-js

rivanitskiy
2022-05-24 14:23
has joined #pact-js

marti92
2022-05-24 21:40
has joined #pact-js

yasarenver
2022-05-25 05:22
has joined #pact-js

evan
2022-05-25 05:27
Are there instructions for building the pact binary myself? I get that the burden of maintaining seperate versions per Alpine on your end is burdensome, but I also see that as potentially a cost that I could shoulder in and for my own build process for my own use. If I could build the binary locally for the particular version of Alpine I am using (say, as part of my docker build pipeline), could the NPM compile/postinstall step detect that instead of trying to download a precompiled version from your end?

matt.fellows
2022-05-25 07:24
I don?t think we generally publish that guide because it?s implementation detail


matt.fellows
2022-05-25 07:25
It will then produce an ffi with the correct architecture

matt.fellows
2022-05-25 07:25
We could potentially add a matrix of common builds to https://github.com/pact-foundation/pact-reference/blob/master/.github/workflows/build-ffi.yml, so it?s not that it?s not doable

matt.fellows
2022-05-25 07:26
The hard part is on the client side (e.g. Pact JS), knowing which ffi lib to bundle/install into the correct path. The installer would need to know library versions in order to ensure the correct FFI is in the right place

matt.fellows
2022-05-25 07:27
At the moment, Pact JS (well, actually `pact-core`) expects the ffi to be colocated with the native module (currently in `build/Release/pact.node`)

matt.fellows
2022-05-25 07:27
I think that could allow an -rpath to another location, or we could (during e.g. an npm postinstall phase) move it to the correct location

uglyog
2022-05-25 08:25
Yes, please. That way the issue won't get lost


brian.quinn
2022-05-25 08:53
has joined #pact-js

jarekrzdbk
2022-05-25 12:45
has joined #pact-js

damianruizdev
2022-05-25 15:59
Hey everyone. Can I get a high-level view of what I need to do to publish my contracts to Pactflow? I've got an Angular app using Jest and the contracts are already being generated in my repo. How do I actually publish them to Pactflow now?


yousafn
2022-05-25 16:16
Also https://docs.pactflow.io/#consumer and select your language

evan
2022-05-25 16:24
> At the moment, Pact JS (well, actually `pact-core`) expects the ffi to be colocated with the native module (currently in `build/Release/pact.node`) What if I created that path and put the compiled binary (from running `cargo build` myself) in it before running NPM? Would that work? As `pact-core` is a top-level(ish) package, I shouldn't have to delve too deeply into the abyss that is `node_modules`, though I'm not sure how/where binaries are located with Yarn 2 PnP, which some of my projects may use in the near future...

shaun.mendham
2022-05-25 16:32
has joined #pact-js

damianruizdev
2022-05-25 16:51
Thanks! That was actually very easy and straight forward lol

yousafn
2022-05-25 16:55
Excellent! This page explains versioning as a concept but it seems that wasn't your problem! https://docs.pact.io/getting_started/versioning_in_the_pact_broker Is there any way the docs could have helped you there, or the command line tool in terms of the error messaging? @tjones provides an excellent package for versioning https://www.npmjs.com/package/absolute-version

damianruizdev
2022-05-25 17:07
I do think the command line tool error message could be more verbose in terms of mentioning what the exact issue was. e.g. "You provided a number for consumerVersion when we expected a string" as opposed to the current error message that showed which was "Must provide the consumerVersion argument" But besides that, the rest was super simple and straight forward

plourded
2022-05-25 19:43
has joined #pact-js

matt.fellows
2022-05-26 02:01
I don?t believe (from memory) than Yarn 2 PnP is supported, but this could be my second hand interpretation of a separate issue. But yes, actually what you?re saying could work

emirhan.emmez
2022-05-26 06:31
has joined #pact-js

evan
2022-05-26 16:09
Ok, good to know that at least in principal this should work. I?ll tinker around with this when I get a moment to see what I can make happen.

yasir27uk
2022-05-26 17:56
has joined #pact-js

lcs2019022
2022-05-27 05:27
has joined #pact-js

wieslaw.bondyra
2022-05-27 08:09
has joined #pact-js

jacek.okrojek
2022-05-27 09:36
has joined #pact-js

jacek.okrojek
2022-05-27 09:37
Hi all!

jacek.okrojek
2022-05-27 09:40
When I use pact-js on my corporate laptop pact file is not written to the disk although log says that it was written. I try to investigate the issue by checking sources but I get stuch in the chain of references. Can anyone give me some tips on how to investigate the issue?

matt.fellows
2022-05-27 09:45
Strange! What does the consumer test setup look like?

jacek.okrojek
2022-05-27 09:46
```const path = require('path'); const Pact = require('@pact-foundation/pact').Pact; global.port = 8080; global.provider = new Pact({ cors: true, port: global.port, log: path.resolve(process.cwd(), 'logs', 'pact.log'), loglevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), spec: 2, pactfileWriteMode: 'update', consumer: 'hero-consumer', provider: 'hero-provider', host: '127.0.0.1' });```

jacek.okrojek
2022-05-27 09:46
The cases is very strange

jacek.okrojek
2022-05-27 09:46
the same code works on my private laptop but not on corporate

matt.fellows
2022-05-27 09:46
What does that log file contain? Can you please share the contents?

jacek.okrojek
2022-05-27 09:56
It is hard since access to my corporate laptop is restricted

jacek.okrojek
2022-05-27 09:56
what I can tell

jacek.okrojek
2022-05-27 09:56
is that on private laptop I have following entry

jacek.okrojek
2022-05-27 09:56
I, [2022-05-27T11:54:08.407874 #28252] INFO -- : Updating pact for hero-provider at C:/projects/pact-js/pact-consumer/pacts/hero-consumer-hero-provider.json

jacek.okrojek
2022-05-27 09:56
and I don't see similar line on the other laptop

matt.fellows
2022-05-27 09:56
Really? How locked down is your machine?

jacek.okrojek
2022-05-27 09:57
super locked down, I work for bank

matt.fellows
2022-05-27 09:57
Like, you can install an nom package but you can't read a log file? How... Do you do any work?

jacek.okrojek
2022-05-27 09:57
I can read

jacek.okrojek
2022-05-27 09:58
I can not use slack to send it to you

matt.fellows
2022-05-27 09:58
Right. Well thats going to make debugging this hard. Logs and she'll output are going to be the primary means here

matt.fellows
2022-05-27 09:59
I'd you can find a way to share that here or as a GitHub issue that would help

matt.fellows
2022-05-27 09:59
(I'm on mobile btw so was just trying to quickly see if I could help)

jacek.okrojek
2022-05-27 10:02
How about this :grinning:

matt.fellows
2022-05-27 10:04
And the terminal output? From that log I can't see any message saying the pact was written, so I think the test failed somewhere

jacek.okrojek
2022-05-27 10:07
Here you are

matt.fellows
2022-05-27 10:21
Thanks. Nothing stands out to me now sorry. We'll need a code base to reproduce I think. Ideally, a GH issue is raised with an example project that reproduces the issue, alongside that log file and full terminal output so we can properly assess

jacek.okrojek
2022-05-27 10:22
that will be hard

jacek.okrojek
2022-05-27 10:22
but maybe we manage to do this

jacek.okrojek
2022-05-27 10:22
any clues for now

jacek.okrojek
2022-05-27 10:23
My investigation points to ruby server that handle /pact request

jacek.okrojek
2022-05-27 10:24
but I have no idea which part of code is responsible for writing file to disk

jacek.okrojek
2022-05-27 10:24
can you point me to such file?

jacek.okrojek
2022-05-27 10:25
or if I am wrong to the place where I can check on my own what is going on ?

matt.fellows
2022-05-27 10:25
Not sure either sorry.

jacek.okrojek
2022-05-27 10:46
Thanks a lot for help

matt.fellows
2022-05-27 10:47
np

matt.fellows
2022-05-27 10:47
sorry, I wish I could have spotted it for you!

jacek.okrojek
2022-05-27 10:47
we I will continue and try to rise the issue if I fail

rafaelcebulla
2022-05-27 15:20
has joined #pact-js

orbit.mjs
2022-05-27 17:45
has joined #pact-js

msparks
2022-05-27 19:56
has joined #pact-js

falvarez
2022-05-30 14:17
has joined #pact-js

gibraltor999
2022-05-30 15:00
Can someone please let me know that for a design first development approach, is the unit tests only place where we can define our contracts?

matt.fellows
2022-05-31 00:47
If you?re using Pact to do this, that?s correct

matt.fellows
2022-05-31 00:47
Pact is a code-first API testing tool. If you try to do it another way (e.g. automate the consumer side) it will be quite difficult to manage on the provider side

matt.fellows
2022-05-31 00:48
Pactflow has a process that might work for your design first approach: https://docs.pactflow.io/docs/bi-directional-contract-testing/

ruslan.ponomarev
2022-05-31 06:28
has joined #pact-js

alexander.maiburg
2022-05-31 07:31
has joined #pact-js

alexander.maiburg
2022-05-31 07:48
Hi, I updated all pact related packages in Angular (see 1st screenshot) and everything works well on my machine. But when I start the build pipeline on Jenkins I get ?[karma-pact]: Failed to start Pact Mock Server Error: Couldn?t start Pact with PID: undefined? I attached the full error log. Can anybody point me to a possible cause? Thanks in advance.

matt.fellows
2022-05-31 07:54
```spawn /home/jenkins/project/workspace/feature_dssk-1737-angular-update/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.83/pact/bin/pact-mock-service ENOENT``` This tells me the package wasn?t properly installed

matt.fellows
2022-05-31 07:54
This is package that is dynamically downloaded during `npm i`

matt.fellows
2022-05-31 07:54
Check the troubleshooting tips of the readme, could it be a proxy?

alexander.maiburg
2022-05-31 08:02
Hi Matt, thanks for your quick response. Yes, there?s definitely a proxy involved. I will look into it and let you know.

matt.fellows
2022-05-31 08:19
:+1::+1:

alexander.maiburg
2022-05-31 09:52
I checked our Artifactory and all packages with the latest versions are present there. So there shouldn?t be a proxy issue? Maybe some adjustments in karma.conf?

john
2022-05-31 09:55
hey all, is been a while since i last looked at pactflow, but can someone remind me when you write a consumer test with some data in the query when the producer test verifys this contract it isnt actually creating the data right if it is a post request or something?

matt.fellows
2022-05-31 09:56
Does it also have the standalone zip file? The pact package on install, goes out to the internet and attempts to download an additional binary (the mock service that is referenced in that log).

matt.fellows
2022-05-31 09:56
If you have a proxy in place that?s preventing that download, it could be the cause

matt.fellows
2022-05-31 09:57
The install process _should_ fail in this case, but it might not for various reasons


matt.fellows
2022-05-31 09:57
it will issue the real request at the provider to verify it can handle the request

matt.fellows
2022-05-31 09:57
what the provider does with that request is totally up to it

john
2022-05-31 09:58
also a second question is so in regards of the pros and cons of contract testing vs say property based testing apis?

john
2022-05-31 09:58
so say it is a graphql mutation it will try to resolve those right?

john
2022-05-31 10:00
Matt does that mean it isnt necessarily the case that the mutation will change some state int he database - if the provider test is writen in a certain way?

matt.fellows
2022-05-31 10:01
Property testing doesn?t care about what the consumer actually does

matt.fellows
2022-05-31 10:01
it is all about the provider

matt.fellows
2022-05-31 10:01
yes (to both)

john
2022-05-31 10:03
do you think it is a good test strategy to create some contract tests and also run property based tests against the apis to find weird edge cases?

john
2022-05-31 10:03
interesting

john
2022-05-31 10:05
ah my organisation a while back like 4 or 5 months ago started this contract testing. But they implemented an apollo server that copied over the schema like a mock server to run the priovider tests against. I tried to get them them not to do that, but they kept saying that they couldnt run the provider tests against the real service as they. didnt have an api to seed the provider data base. From what your saying this isnt necessarily the case

matt.fellows
2022-05-31 10:05
contract tests are about preventing API breaking changes (amongst other things), whereas property testing is more about discovering issues with the provider

matt.fellows
2022-05-31 10:05
so yes, it wouldn?t be a bad idea

matt.fellows
2022-05-31 10:06
but in my experience I?d say property testing is also not that common

matt.fellows
2022-05-31 10:06
(not a reason _not_ to do it)

john
2022-05-31 10:06
yeah im looking into this tool called schemathesis - looks pretty good

matt.fellows
2022-05-31 10:07
yeah, that?s a bad idea

john
2022-05-31 10:08
do you have examples of the provider tests not updating the database but just checking the services are still compatible?

matt.fellows
2022-05-31 10:08
Well, all of our examples have to deal with this problem

john
2022-05-31 10:08
hmm thats so weird we implemented in that way

matt.fellows
2022-05-31 10:09
(gtg sorry, on a call!)

john
2022-05-31 10:09
Last question! lol My company is using graphql mesh. Is hitting the graphql mesh a bad practise for pactflow?

alexander.maiburg
2022-05-31 11:30
Yes, it contains the standalone zip file.

matt.fellows
2022-05-31 11:31
hmm

matt.fellows
2022-05-31 11:32
If you can do it, see if you assess on the build environment if the mock service has been correctly downloaded and installed

matt.fellows
2022-05-31 11:33
A problem I?ve seen in the past, is that the proxy intercepts the download, returns a 200 OK and then writes an HTML file to where a zip file should be

alexander.maiburg
2022-05-31 11:33
Yes, I will upload it to Artifactory and reference it explicitly in the package.json

matt.fellows
2022-05-31 11:34
For clarity, it?s still possible that the proxy can intercept the request to Artifactory

alexander.maiburg
2022-05-31 11:35
Ok, I will give it a shot anyway. In the meantime I will contact our DevOps-Team if they can look into it.

alexander.maiburg
2022-05-31 15:28
I managed it to upload the binary pact-1.88.83-linux-x86_64.tar.gz to artifactory and added the path to package.json. Everything works well during `npm i` . But as soon as the unit tests start, I get the same error.

tjones
2022-05-31 16:05
Do you see the binary download during the npm install?

tjones
2022-05-31 16:08
what happens if you add ```file node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.83/pact/bin/pact-mock-service``` to the build script?

tjones
2022-05-31 16:08
this will tell you if the file is missing, is inappropriately html (indicating a login or proxy error), or is the binary and there's some other problem

tjones
2022-05-31 16:09
note that `npm i` won't install the binary if it is missing but the package is there - so if you're caching your node_modules, it may stay missing

aherbst
2022-05-31 17:31
has joined #pact-js

john
2022-05-31 23:51
Just to confirm, as we are testing this out. So basically the provider test wont change the database state for mutations. If we use something like this: ```describe('API Test', () => { const needToBeVerified = ['usernameCheck', 'signup'] each(needToBeVerified).it('should verify the expectations of %p Graphql', contractName => { return new Verifier(createOptions(`apitest-${contractName}-provider`)).verifyProvider().then(output => { if (output.includes('Diff')) { console.log(output) throw new Error(`${contractName} contract test error`) } }) }) })``` On the provider side if the consumer test is making a query and if the data is not in the provider side database then this is no problem for pact

matt.fellows
2022-06-01 02:19
> So basically the provider test wont change the database state for mutations. When you run a provider test, you need to start up the provider (usually locally). If a consumer needs to perform a mutation, it will send the HTTP request (in this case a graphql query) to the target provider. It is up to you as the provider maintainer to decide if you stub databases or downstream systems, or let it through (highly recommend these are stubbed). See also https://docs.pact.io/provider#stub-calls-to-downstream-systems

matt.fellows
2022-06-01 02:19
Pact is great, but it isn?t magic :wink:

john
2022-06-01 04:17
thanks Matt, one reason the team said they used a mock apollo service is that when they do queries the data isnt int he database ont he provider side

matt.fellows
2022-06-01 04:53
That?s what provider states are for

alexander.maiburg
2022-06-01 07:24
Hey Timothy, sorry for the delay but I?m sitting in Germany.

alexander.maiburg
2022-06-01 07:24
Here is what Jenkins logs during `npm i`

alexander.maiburg
2022-06-01 07:26
This is exactly the location where I dropped the tar.gz on Artifactory.

alexander.maiburg
2022-06-01 07:28
But when it comes to starting the pact tests node keeps giving me ENOENT errors.

matt.fellows
2022-06-01 07:29
Thanks, no problems - we're equally at fault being in Australia :rolling_on_the_floor_laughing:

matt.fellows
2022-06-01 07:29
Could please try the command Tim suggested above?

matt.fellows
2022-06-01 07:30
I believe you that the URL is correct, but we need to ensure it downloads correctly and has the correct contents

matt.fellows
2022-06-01 07:31
That I can't tell you sorry, I've not used the mesh before. I think you probably just mean Pact also here?

alexander.maiburg
2022-06-01 08:01
As Timothy suggested, I added the the command to the build script, but it failed. See screenshot.

vipul.pachauri
2022-06-01 08:02
has joined #pact-js

komal.sharma1
2022-06-01 08:02
has joined #pact-js

matt.fellows
2022-06-01 08:14
This might be a little painful, but could you please see what the zip file is e.g. `file <path/to/project>/standalone/linux-x64-1.88.83.tar.gz`

matt.fellows
2022-06-01 08:14
(obviously replace the correct bits)

john
2022-06-01 08:32
yes Pact!, Thanks for being so patient Matt!

matt.fellows
2022-06-01 08:32
:sunglasses:

john
2022-06-01 08:33
good thing is i believe my org will upgrade our plan in the coming days so thats pretty cool

alexander.maiburg
2022-06-01 08:41
Here is the file list I get after `rm -rf ./node_modules && npm i`

alexander.maiburg
2022-06-01 08:46
Hmmm, the file owner is root. Why that? Maybe that?s the problem?

matt.fellows
2022-06-01 08:50
It's Zero bytes, that would be the problem

alexander.maiburg
2022-06-01 08:51
Ok, I?m obviously blind?

alexander.maiburg
2022-06-01 08:51
But why is that? How can I fix it?

matt.fellows
2022-06-01 08:52
Are there any proxy settings (e.g. https_proxy)? If set, you might need to exclude artifactory. If not setz you might need to set them

alexander.maiburg
2022-06-01 08:53
Ok, I?ll check it

matt.fellows
2022-06-01 09:23
Amazing!

alexander.maiburg
2022-06-01 11:38
Uffff, after what felt like 100 commits I came up with a simple script that did the trick?

alexander.maiburg
2022-06-01 11:39
Thanks for your time and help! I really appreciate it!!

tjones
2022-06-01 11:42
Hah! Well, I'm glad that worked. On a side note, I would recommend `npm` `ci` in your CI- it will always install what is listed in package lock, which makes your build a bit more robust / repeatable. However, I don't think that was the issue you're facing

alexander.maiburg
2022-06-01 11:48
I changed it because I wanted to make sure that nothing gets cached. Surprisingly the install step is now even faster. But you?re right, I will undo it

chris169
2022-06-01 11:53
has joined #pact-js

m.shi
2022-06-01 19:07
has joined #pact-js

matt.fellows
2022-06-01 21:53
I think the best way to solve this problem is to package all of the standalones into the library. This seems like a pretty painful upgrade experience! Did you test out the proxy environment variables? Is it possible that Artifactory is authenticated and the api client that does the post install is failinsg? What do the logs from `npm i` say?

asa.anudeep4
2022-06-02 04:33
has joined #pact-js

diede
2022-06-02 10:01
has joined #pact-js

mateusz.zaborowski
2022-06-02 17:54
has joined #pact-js

rchord23
2022-06-05 19:30
has joined #pact-js

divya.parameswaran
2022-06-05 20:16
has joined #pact-js

tjones
2022-06-06 02:52
I'd be curious to know how you go with Schemathesis - my gut is that you'd run into the problem with things that are hard to express / not expressed in the schema - eg conditional properties based on values of other fields


alexey.shchukin
2022-06-06 11:46
has joined #pact-js

john
2022-06-06 12:21
I was looking into the provider state. So is it just a case of having an in memory database (or even just hardcoding it)for example in the provider test. Using the same data that the consumer request expects and to include that in the opts: ```const opts = { ... stateHandlers: { [null]: () => { // This is the "default" state handler, when no state is given } "Has no animals": () => { animalRepository.clear() return Promise.resolve(`Animals removed from the db`) }, "Has some animals": () => { importData() return Promise.resolve(`Animals added to the db`) }, "Has an animal with ID 1": () => { importData() return Promise.resolve(`Animals added to the db`) } } } return new Verifier(opts).verifyProvider().then(...)``` so like in the above example. If the consumer is expecting in the request it sends an id, and name and expects the id to be 1. Can i just hardcode the data as something like this: ```{ "id": 1, "name": "dog" }```

lukasz.wlosek
2022-06-06 14:41
Hi, I have this problem, when I run the verification provider tests, they seem to be setup with random ports on localhost like so: (this is what I see being executed when I run with debug') ```pact-node@10.17.2: Starting pact binary '/home/repos/gf-accounts-service/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.88.83/pact/bin/pact-provider-verifier', with arguments [--provider-states-setup-url http://localhost:46091/_pactSetup --provider-base-url http://localhost:46091 --provider-app-version dc04a08``` The ports for --provider-states-setup-url and --provider-base-url seem to be failing my TeamCity build sometimes, as some of these ports are reserved, I thought that specifying the providerBaseUrl in the provider settings sets these ports, in my case it was http://localhost:3000/ but it seems like the pact-provider-verifier spins this up with different ports as some proxy? Is there a way to specify which port to use in that pact-provider-verifier script?

matt.fellows
2022-06-06 21:59
The pact process spins up a local proxy to enable additional features. The ports you are seeing here are those ports (if you setup debug logging you should see more info on these)

matt.fellows
2022-06-06 22:00
> ?seem to be failing my TeamCity build sometimes, as some of these ports are reserved the ports should be selected by the OS as available, so this seems unlikely to me. Can you share the setup that?s failing? Flakey tests are usually a sign of mishandled promises _or_ timeouts (on CI machines often are slower than your high powered dev machine)

afang
2022-06-06 22:17
has joined #pact-js

abubics
2022-06-07 00:38
This family of questions has been coming up a bit recently, I wonder if there's any docs written about it :thinking_face:

abubics
2022-06-07 00:38
Really, it depends where you want to cut the provider for testing. And it's entirely up to you.

abubics
2022-06-07 00:39
I prefer to stub responses about a-layer-and-a-half into my provider, to make sure the requests & responses execute a hint of logic (parsing is the minimum).

abubics
2022-06-07 00:41
You can also stub the entire database, outside the provider. That gives a bigger footprint (less isolation), but might be easier to do, depending on your architecture.

abubics
2022-06-07 00:41
With a clean architecture, I stub either the domain layer, or the use case layer, and provide that through DI.

pratish.mp
2022-06-07 00:58
has joined #pact-js

alexander.maiburg
2022-06-07 08:09
No, I haven?t tested the proxy env variables. I was pretty happy that I could solve the problem with the build script. But I will definitely look into it. The logs during `npm i` weren?t very helpful. All it says ist that the regarding file is missing.

lukasz.wlosek
2022-06-07 09:51
I think I found the problem which you basically pointed me to, so thanks, seems that the state handler which was ```const stateHandlers = { 'has a account saved': async () => { // connect to local db and add/seed account data await seedTable(); return Promise.resolve( 'Accounts added: 9ae9b264-f181-46ea-a468-4919c48fbe0(1-5)' ); } }; ``` When changing to ```const stateHandlers = { 'has a account saved': () => { // connect to local db and add/seed account data return Promise.resolve(seedTable()); } };``` worked, so this means stateHandlers when changing to async would not work, is this intended?

matt.fellows
2022-06-07 10:10
hmm no `async` should work

matt.fellows
2022-06-07 10:11
is `seedTable()` a promise/async fn? This does not wait for it to complete, if so. ```return Promise.resolve(seedTable());``` My guess is that the test is timing out and `seedTable` is taking longer than the test timeout

lukasz.wlosek
2022-06-07 10:13
Yeah ```const seedTable = async () => { const account = Account.make({ PK: 'A_' + '9ae9b264-f181-46ea-a468-4919c48fbe01', SK: 'V0_' + Account.RECORD_TYPE, emailAddress: '', groupHash: '123', siteIdentifier: 'ss', idpId: 'random', loginCount: 0, loginHistory: [] }); await account.save(); const accountTwo = Account.make({ PK: 'A_' + '9ae9b264-f181-46ea-a468-4919c48fbe02', SK: 'V0_' + Account.RECORD_TYPE, emailAddress: '', groupHash: '123', siteIdentifier: 'ss', idpId: 'random', loginCount: 0, loginHistory: [] }); await accountTwo.save(); }``` and I have jest.setTimeout(9000000); so that should be enough time right

afang
2022-06-07 13:30
Good morning! I've been having issues with trying to pact test an endpoint with a query param in jest. ```describe('Pact test', () => { it('should work', async () => { const apiPath = '/userprofile/v1/paymentmethods'; const interaction: InteractionObject = { state: 'Client has submitted a get all payment methods request', uponReceiving: 'a valid payment methods get body', withRequest: { method: 'GET', path: '/userprofile/v1/paymentmethods', query: { userId: 11111 }, }, ...``` When I go to the Provider contract on Pactflow, it shows that the query param is there (in screenshot) However, when I run the pact test, it gives me the 1st error `Could not find key "userId" in empty Hash at $.query` I've tried multiple variations, such as removing the query property and placing it directly in the path and turning the userId into a string. When I change both types into a string, it gives me the 2nd error

yousafn
2022-06-07 13:47
Hey, I assume this is using bi-directional contract testing, as you are mentioning a provider contract? on your consumer side, is it failing to generate a consumer pact?

afang
2022-06-07 13:48
Yes, I believe so

yousafn
2022-06-07 13:48
can you show the rest of your pact test, where you are invoking your client under test, and the code for the client under test.

afang
2022-06-07 13:51
```/* eslint-disable import/no-extraneous-dependencies */ import { pactWith } from 'jest-pact'; import { InteractionObject, Matchers, Publisher, } from '@pact-foundation/pact'; import fetch from 'node-fetch'; const opts = { pactFilesOrDirs: ['pact/pacts'], pactBroker: 'https://uship.pactflow.io/', pactBrokerToken: process.env.PACTFLOW_SECRET_TOKEN, consumerVersion: process.env.GIT_COMMIT, publishVerificationResult: true, branch: process.env.GIT_BRANCH, tags: ['tag'], }; pactWith( { consumer: 'consumer', provider: 'provider', pactfileWriteMode: 'overwrite', }, async (provider: any) => { const client = (path, options?) => { const url = `${provider.mockService.baseUrl}${path}`; return fetch(url, options); }; afterAll(async () => { await new Publisher(opts).publishPacts(); }); describe('Payment methods', () => { it('should be able to create a pact for get all payment methods', async () => { const apiPath = '/userprofile/v1/paymentmethods'; const interaction: InteractionObject = { state: 'Client has submitted a get all payment methods request', uponReceiving: 'a valid payment methods get body', withRequest: { method: 'GET', path: '/userprofile/v1/paymentmethods', query = { userId: '111' } }, willRespondWith: { headers: { 'Content-Type': 'application/json', }, body: { paymentMethods: [{ id: Matchers.like(73), userId: Matchers.like(44441), externalId: Matchers.like('id_123'), type: Matchers.like('card'), lastFour: Matchers.like('4242'), isPrimary: Matchers.like(true), issuer: Matchers.like('Visa'), verificationStatus: Matchers.like('notapplicable'), expiration: { year: Matchers.like(2024), month: Matchers.like(7), }, }, { id: Matchers.like(73), userId: Matchers.like(44441), externalId: Matchers.like('id_123'), type: Matchers.like('payonterms'), lastFour: null, isPrimary: Matchers.like(true), issuer: null, verificationStatus: Matchers.like('notapplicable'), creditLimit: { creditApproved: { amount: Matchers.like(50000), currency: Matchers.like('USD'), }, creditAvailable: { amount: Matchers.like(38159.03), currency: Matchers.like('USD'), }, creditUsed: { amount: Matchers.like(11840.97), currency: Matchers.like('USD'), }, }, }, { id: Matchers.like(73), userId: Matchers.like(44441), externalId: Matchers.like('id_123'), type: Matchers.like('ACH'), lastFour: Matchers.like('6789'), isPrimary: Matchers.like(true), issuer: Matchers.like('Visa'), verificationStatus: Matchers.like('notapplicable'), }, ], }, status: 200, }, }; await provider.addInteraction(interaction); const response = await client(apiPath, { method: 'get', headers: { 'Content-Type': 'application/json' }, }); expect(response.status).toBe(200); }); }); }, );```

yousafn
2022-06-07 13:53
So just to note there you aren't actually testing your client api layer that is calling your provider, is that intended ``` const client = (path, options?) => { const url = `${provider.mockService.baseUrl}${path}`; return fetch(url, options); };```

yousafn
2022-06-07 13:54
you aren't passing query params to the client, that is using `fetch` under the hood ``` const response = await client(apiPath, { method: 'get', headers: { 'Content-Type': 'application/json' }, });```

yousafn
2022-06-07 13:54
you should be testing your API layer, such as https://github.com/pact-foundation/jest-pact#usage

afang
2022-06-07 13:55
Hmmm, I'm not quite sure what not testing the client api layer means. I was taking over for someone who worked on this and they're off on vacation. Do you mean are we intending not actually test the endpoint with fake data?

yousafn
2022-06-07 13:56
in your code base there will be an api client making a request to a provider, this test shown, isn't testing that bit of code

yousafn
2022-06-07 13:56
so you have no guarantee of drift

afang
2022-06-07 13:57
What is drift?

yousafn
2022-06-07 13:58
where the expectation on the provider/consumer do not match up, and fail to communicate when deployed

yousafn
2022-06-07 13:58
this example from the readme explains it well I think https://github.com/pact-foundation/jest-pact#usage better than I am at the moment :slightly_smiling_face: just about to go into a meeting for now

yousafn
2022-06-07 13:59
tl;dr to get your test to pass you need to read up on how to pass query parameters to fetch

yousafn
2022-06-07 13:59
longer read, the test isn't that useful and should be updated to test your consumer client (that makes the calls to the provider)

afang
2022-06-07 14:03
Thank you, I'll take a read!

yousafn
2022-06-07 14:46
So, In your test, the client under test shown below, should be the actual client in your consumer code that is making the call to the `provider` service ``` const client = (path, options?) => { const url = `${provider.mockService.baseUrl}${path}`; return fetch(url, options); };``` when you call that client in your test, it is passed the `apiPath` ``` const apiPath = '/userprofile/v1/paymentmethods';``` and has no knowledge of the query parameters you have defined in the Pact interaction ``` const response = await client(apiPath, { method: 'get', headers: { 'Content-Type': 'application/json' }, });``` If you wanted to pass headers to fetch, there is an example on the fetch website https://fetch.spec.whatwg.org/#fetch-api ```var url = new URL("https://geo.example.org/api"), params = {lat:35.696233, long:139.570431} Object.keys(params).forEach(key => url.searchParams.append(key, params[key])) fetch(url).then(/* ? */)``` The errors shown by Pact, are saying that the client you have setup is making a request to `/userprofile/v1/paymentmethods` but has no query parameters, which is exactly what is being demonstrated by the code shown. Also additional point to note, as you mentioned a provider contract, I am assuming we are using Bi-Directional contract testing to validate the consumer/provider contracts. https://docs.pactflow.io/docs/bi-directional-contract-testing If so, the `Matchers` used in this pact test, will be persisted to a Pact contract file but will be ignored at verification time. Matching is done based on the type specified in the pact file example https://docs.pactflow.io/docs/bi-directional-contract-testing/compatibility-checks so this `id: Matchers.like(73)` can just be `id: 73` and it will expect the field `id` to exist and be a `number` The matchers are relevant when using consumer driven contract testing, where you are using provider verification driven by the Pact framework https://docs.pact.io/getting_started/how_pact_works#provider-verification

afang
2022-06-07 15:32
Is the query param type on the provider side able to be either string or number, or can it only be string?

yousafn
2022-06-07 15:52
your spec is expecting integer, so I would expect it to fail if you provide a string value


matt.fellows
2022-06-07 23:00
So this looks to be a *consumer* test. This screenshot shows the problem - you?re not sending the query along with the call in that test as Yousaf has pointed out. Pact is a *unit testing tool* that you use to test your API client behaviour. If you don?t use your actual API client then it?s not a useful test because if the behaviour of the actual API client changes, this test won?t pick the problem up (this is the ?drift? Yousaf is describing). You have a test that is not testing your actual code, so the actual behaviour can drift from your expectations, but you won?t know until it breaks (probably in prod)

tjones
2022-06-07 23:14
Query parameters are always strings, because they go in the URL

matt.fellows
2022-06-07 23:15
> Is the query param type on the provider side able to be either string or number, or can it only be string? For clarity, what Tim said

dasarih
2022-06-08 00:20
has joined #pact-js

benjamhawk
2022-06-08 02:37
has joined #pact-js

john
2022-06-08 11:57
Hey Boris thanks for the response. I just have trouble navigating the documentation for pact

john
2022-06-08 12:09
i let you know how i get on with it

sclaros
2022-06-08 13:07
has joined #pact-js

daniel.tjondro
2022-06-08 15:25
has joined #pact-js

slacksync
2022-06-08 17:21
has joined #pact-js

sandro
2022-06-08 18:26
has joined #pact-js

hazem
2022-06-08 23:14
has joined #pact-js

abubics
2022-06-09 11:04
Makes sense, there's a chance it's not clearly structured in the docs, but the conversation happens a bunch in Slack :sweat_smile:

leonardo.lanni
2022-06-09 14:51
has joined #pact-js

jcamilovasquezm
2022-06-10 02:47
has joined #pact-js

markrkell
2022-06-10 08:13
has joined #pact-js

eva-maria.schaller
2022-06-10 08:24
has joined #pact-js

michel.kaporin
2022-06-10 14:43
has joined #pact-js

pooja.sharma4099
2022-06-11 08:39
has joined #pact-js

srinivas.vaddi
2022-06-11 16:31
has joined #pact-js

igor.sharfman
2022-06-12 11:25
has joined #pact-js

igor.sharfman
2022-06-12 14:47
Hey!! I want to try to add pact tests in our project. We work with type-script and Jest. Is there a step-by-step instructions how I can easily implement some contract tests with a broker? where to start? TNX!!

matt.fellows
2022-06-12 23:24
Howtolearn

2022-06-12 23:24
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

matt.fellows
2022-06-12 23:24
See those workshops and examples

matt.fellows
2022-06-12 23:24
Howtoexamples


chituru.chinwah
2022-06-13 08:48
has joined #pact-js

chituru.chinwah
2022-06-13 09:28
Hi! :wave::skin-tone-5:, I have a question regarding pact, given a request which is sent with one of the following possible values: ```enum value { optionA optionB optionC }``` The response returns the value which was sent in the request like this(assuming ?optionA? was sent in the request): ```data: { value: { selectedValue: 'optionA' } }``` My question is, what is the best way in `pact-js` to verify that only one of the possible 3 values is accepted? is there some sort of way of checking that only one of these values is accepted in the response? Thanks in advance for your help! :pray::skin-tone-5::raised_hands::skin-tone-5:.

cchinwah1
2022-06-13 09:45
has joined #pact-js

matt.fellows
2022-06-13 10:09
Yes, you would simply expect the exact value and not use a matcher. Is this question hypothetical or are you having issues?

matt.fellows
2022-06-13 10:09
You would need to test each scenario explicitly though

chituru.chinwah
2022-06-13 10:12
Thanks! Not hypothetical as I?m actually testing this at the moment, but was wondering what the best option would be, I did think of testing each scenario explicitly but then I wondered if that would then be venturing into functional testing space, but in this specific scenario all three values have to be verified anyway so it makes sense :slightly_smiling_face:.

matt.fellows
2022-06-13 10:14
All good, always good to get a second opinion!

julian.alvarezv
2022-06-13 17:10
has joined #pact-js

tjones
2022-06-14 03:03
I use the following guideline: ? Test everything you expect each side to be able to understand ? Don't use pact to _drive_ functional testing, but it's ok if your tests happen to have incidental functional coverage

tjones
2022-06-14 03:07
On whether or not to use a matcher: ? There are cases where it's valid for the provider to return any of the following options - for example - a `userType` in response to `GET /users/{someid}`. In that case, I would use a matcher. ? There are cases where although the spec says there could be multiple answers, only one of them would be valid in that response - for example, if the full user entity is returned in response to a POST request that sets the user's `type` to `admin`, you'd expect it to be exactly `admin`. In that case, I don't use a matcher.

dave.clissold
2022-06-14 08:16
Hi everyone. Following on from a message on https://github.com/pact-foundation/pact-js/issues/304?notification_referrer_id=MDE4Ok5vdGlmaWNhdGlvblRocmVhZDUwMjc2MzIzMTo3Mjg0MDcw#issuecomment-1152416010. I've polished up the work that @matt.fellows had started to be able to change the request body in the verifier.requestFilter(). I've never written unit tests for middleware before and there is not much out there for writing tests using http-proxy, so this is a first attempt, if anyone is available to just check this seems ok, before I raise the p/r. https://github.com/DaveClissold/pact-js/tree/feat/modify-req.body-in-requestfilter-v2. If everyone seems happy with this, I'll add these tests to v3 and raise a pr for that as well

matt.fellows
2022-06-14 09:09
I can definitely review

matt.fellows
2022-06-14 09:09
My suggestion would be to move as much out of the HTTP proxy layer into (where possible) pure JS functions. We can test those separately then.

matt.fellows
2022-06-14 09:11
What remains could then be tested either via an integration test of `http-proxy` (which, yes, will probably be a bit difficult/messy and maybe not worth it - see how you go) or via a end to end test by adding functionality to the v3 e2e example (these run with every build, so it will catch a regression)

dave.clissold
2022-06-14 10:09
Thanks Matt, I was having a headache with finding the right class to stub with sinon but after digging through the the type defs and multiple extended classes have a working solution. Will raise the pr now for v2 and work on the v3 one a bit later

malukenho.dev
2022-06-14 14:33
has joined #pact-js

dave.clissold
2022-06-14 16:39
My day got away from me .. here is the pr https://github.com/pact-foundation/pact-js/pull/873

vikki.read
2022-06-14 18:58
has joined #pact-js

omer.khalil
2022-06-14 19:33
has joined #pact-js

matt.fellows
2022-06-15 03:35
thanks! I?ll take a look over the next few days

matt.fellows
2022-06-15 03:35
Much appreciated!!

rxiao
2022-06-15 04:29
has joined #pact-js

james.demaine373
2022-06-15 10:22
has joined #pact-js

dmoll
2022-06-15 21:10
has joined #pact-js

kurt3402
2022-06-16 04:29
has joined #pact-js

kyo.tang
2022-06-16 06:03
has joined #pact-js

prasadsolanki
2022-06-16 10:58
has joined #pact-js

mairtin.conneely
2022-06-16 12:02
has joined #pact-js

laura.kennedy
2022-06-16 14:32
has joined #pact-js

gaurav.bajpai
2022-06-17 03:41
has joined #pact-js

salmanjamali
2022-06-17 06:49
has joined #pact-js

alansimonalie
2022-06-17 12:57
has joined #pact-js

ben.a.hubbard
2022-06-17 13:47
has joined #pact-js

lafriakh.rachid
2022-06-18 14:24
has joined #pact-js

ngbrown
2022-06-19 22:35
has joined #pact-js

john
2022-06-20 01:22
I tried out schemathestis it appears to be pretty good actually. Though the only downside i could find from it is that for REST you need to generate a specification file that may not always be possbile?

john
2022-06-20 01:25
Just a quick question - which may or may not be daft (avert eyes now lol). If i created some microservices in say Python. Is there anything to stop you writing the consumer or the producer tests in say javascript?

abubics
2022-06-20 01:30
nothing to stop you from writing consumers & providers in different languages . . . but writing tests in a different language than the code that they're testing sounds a bit futile

john
2022-06-20 01:53
ah good to know thanks. a couple of reasons for that just want try a few things out in a few different languages

matt.fellows
2022-06-20 02:38
I?d say writing the consumer tests in JS for a python code base will be really hard - consumer tests are really meant to be unit tests. So you can see why this would be hard

matt.fellows
2022-06-20 02:38
provider side is usually a little higher level, so it would be possible, but still awkward. We do have https://docs.pact.io/implementation_guides/cli that work this way, so it?s up to how you work

john
2022-06-20 02:59
ill try out python first maybe ill write anotehr server in javascrip provider to test out the js

courtney.lum
2022-06-20 04:02
has joined #pact-js

john
2022-06-20 07:08
one otehr question, sorry the pact docos are all over the place. The docos say for provider state (presumably when using a language other than ruby?): ``` Non-Ruby applications To allow the correct data to be set up before each interaction is replayed, you will need to create an HTTP endpoint (which may or may not actually be in the same application as your provider) that accepts a JSON document describing the state. The exact format of this document depends on whether you are using the JVM implementation, or one of the wrapped Ruby implementations (effectively everything that isn't JVM). The endpoint should set up the given provider state for the given consumer synchronously, and return an error if the provider state is not recognised. Namespacing your provider states within each consumer will avoid clashes if more than one consumer defines the same provider state with different data. See the pact-provider-verifier documentation for the exact details of implementing a provider-states-setup-url.``` my devs are asking what difference in doing this than using a mock graphql server?

matt.fellows
2022-06-20 07:32
hmm where are you seeing this? Def doesn?t apply to the JS verifier


tjones
2022-06-20 07:33
It can do, though. This is how I do it.

tjones
2022-06-20 07:34
The primary difference is that with a mock graphql server you are marking your own exam - nothing is making sure that the mock server behaves the same as the real server

tjones
2022-06-20 07:34
with pact's mocks, the provider verification step ensures that your real provider behaves the same as the mock that you used at consumer test time.

john
2022-06-20 07:49
I got to the artical after reading the link that Matt provided, clicking on the Provider State link takes you o a page regarding provider state and then onto the ruby examplke from there the non ruby example

john
2022-06-20 07:52
so is it a good practise to set up this http endpoint and then just return the hardcoded json stuff we need - that was in the original consumer request?

tjones
2022-06-20 07:53
I think there might be a confusion here - the http endpoint that is mentioned there is for provider state change

tjones
2022-06-20 07:53
during provider verification, pact needs a way to say "hey, please set up this state"

john
2022-06-20 07:53
ah this is such a headache, but let me try to explain

tjones
2022-06-20 07:53
The idea is that you run your real provider in a given named/known state

john
2022-06-20 07:54
the devs they created a consumer test in one repo and have some data in that request for their graphql query. That data isnt in our monolith appilcation

john
2022-06-20 07:55
they originally were unsure how to provceed as the tests kept failing so they created htis mock appolo server

john
2022-06-20 07:55
to bypass that they cant add those records to the monolith

tjones
2022-06-20 07:55
With pact-js, there are two ways to do this: 1) With the state change endpoint 2) With the state change functions In option 1, you need to handle starting and stopping your provider (with this additional endpoint running) outside your verification test. With option 2, you usually run the provider inside your verification test, and the state change functions reach into it and change the state

tjones
2022-06-20 07:57
> That data isnt in our monolith appilcation What do you mean by "isn't in the application"? If the consumer test is expecting a structure that isn't implemented, then verification will (correctly) fail. If you mean the monolith doesn't come with that data pre-setup, then yes - this is what the state change endpoints or functions are for

tjones
2022-06-20 07:57
the idea is that the state change sets up that state

john
2022-06-20 07:57
let me give you an example

john
2022-06-20 07:58
```export const MUTATION_RESPONSE = { status: 200, headers: { "Content-Type": "application/json; charset=utf-8" }, body: { data: { signUp: { user: { username: like("Alice"), accounts: eachLike({ id: like(1), uuid: like("0001") }) } } } } }```

john
2022-06-20 07:58
i believ they expect something like this

john
2022-06-20 07:58
but from they say the info isnt in the database

john
2022-06-20 07:59
if either of you have time I can DM you our issue without cloggin up this board

tjones
2022-06-20 08:01
Yes, the purpose of the state change endpoint/function is to set that info in the database

john
2022-06-20 08:02
ok so that will set the information in the database?

tjones
2022-06-20 08:02
It's better to answer questions in public here as then others can benefit/contribute to the discussion

tjones
2022-06-20 08:02
Most people commenting here are volunteers

john
2022-06-20 08:02
can you provide a link to the docos on those 2 methods you mentioned

tjones
2022-06-20 08:02
I think Matt linked to it above

tjones
2022-06-20 08:03
I'm on mobile so it's a bit hard to search the docs

tjones
2022-06-20 08:04
providerStatesSetupUrl is the property to set for the endpoint

john
2022-06-20 08:04
ok ill pass on the info to the devs, maybe we are just confusiong ourselves over this. If it is the case that the provide state you just need to insert the data from our db

john
2022-06-20 08:05
like the example:

john
2022-06-20 08:05
``` "Has some animals": () => { importData() return Promise.resolve(`Animals added to the db`) },```

tjones
2022-06-20 08:06
I can't seem to link into the readme, but what you're looking for is the section that starts ?API with provider states?

tjones
2022-06-20 08:06
Import the data TO the db

john
2022-06-20 08:06
yes insert into the db right

tjones
2022-06-20 08:06
The state change endpoint does not return the data that is expected by the test

tjones
2022-06-20 08:06
It sets up the data expected by the test

john
2022-06-20 08:07
you would only need to do that with the queries right?

tjones
2022-06-20 08:07
Maybe, it depends. For mutations you might need to set up the thing you're mutating

tjones
2022-06-20 08:08
I don't really know a lot about graphql sorry

john
2022-06-20 08:08
oh have some test data first you mean

john
2022-06-20 08:08
yeah i dont know a huge amount about it

tjones
2022-06-20 08:08
Yes. Think of provider state as the precondition

tjones
2022-06-20 08:08
It's what allows pact tests to be independent

john
2022-06-20 08:10
ok let me pass on the info to the devs. Im going to try this out on my own personal project so i'm more across this also


tjones
2022-06-20 08:10
This explains the setup

john
2022-06-20 08:10
so everything is pretty much set up

john
2022-06-20 08:10
just need ot get rid of this mock apollo server on the provider side

tjones
2022-06-20 08:26
Yep! Definitely no mock server on the provider side.

tjones
2022-06-20 08:27
You could maybe have one if it's a dependency beyond your provider, but I wouldnt recommend doing it that way

john
2022-06-20 09:52
So one dev is saying we have a test scenario where they are testing a delete mutation and that has a unique id. In the consumer test he says that he cannot create an object via a graphql mutation to delete (as a test setup prior to the consumer test) as the first time the consumer test is run and the contract is uploaded the contract cannot be updated next time round with the new id? Is that correct?

tjones
2022-06-20 09:58
All tests are independent. Remember the pact state change endpoint is not a graphql query

woojos
2022-06-20 09:58
has joined #pact-js

tjones
2022-06-20 09:59
I don't think I understand what he means in the second part, but my guess is no, that's not correct

john
2022-06-20 10:05
```For deleteLink graphql mutation, the request param must contains the link id which we want to delete, this id can not be changed after consumer side generate the contract, in provider side, every time contract test running, it must provider a link with the same id. So we can not create a new link with the same id using graphql mutation every time before running deleteLink test, it just can operate the database to prepare the data.```

john
2022-06-20 10:07
```yes, but the id in contract can not be changed in provider side, because pact thinks that if provider can modify the request of contract means that the contract is not trusted.``` I meantioned that maybe setup a new link to delete but apparently the provider contract doesnt allow that?

abdou.ahzab
2022-06-20 10:08
has joined #pact-js

tjones
2022-06-20 10:21
In this case you would do something like a state of ?a link exists with ID=Foo? or similar

tjones
2022-06-20 10:23
If the IDs cannot be predicted beforehand, you can look at fromProviderState which allows the state setup hook to return an ID (or other arbitrary data) to the consumer test before it runs

tjones
2022-06-20 10:23
There isn't a provider contract, the contract comes from the consumer

tjones
2022-06-20 10:24
fromProviderState is in the next version of pact-js so you would need to use the beta. This may or may not work for you

tjones
2022-06-20 10:24
Usually you use the pact state change to completely mock the repository layer inside your provider- this gives full control of the data within it

matt.fellows
2022-06-20 10:53
Tim, thanks for your very helpful responses! Zooming out from this detail for a moment so we can get a grasp of the big picture here. Regardless of GraphQL, REST or otherwise, and whether or not it stores all of the data locally or needs to fetch from downstream systems ? The challenge most people have with the provider test is that the _consumer (_the originator of the _contract_) can come up with scenarios that don?t match whatever the provider has in its default state when it comes to _verify_ the provider. The example mentioned here, I think, is that an ID of an entity may not be known in advance. But I think that?s likely an assumption that stems from previous conceptions about how e2e tests would work, where you would ?create? an entity, ?get? the entity and then update/delete/whatever the entity. i.e. you need the client to perform these steps in sequence. *Provider states* (as noted) exist to solve this problem. It?s how a consumer can telegraph a condition that must be true for the provider test to run without specifying _how_. Consumers and provider _should_ discuss these and some coordination is required, but that is how you can achieve a level of decoupling that you can?t do with end-to-end tests. Provider states free us from having to write tests that know about other tests (from the docs): > Each interaction in a pact should be verified in isolation, with no context maintained from the previous interactions. Tests that depend on the outcome of previous tests are brittle and land you back in integration test hell, which is the nasty place you?re trying to escape by using pacts.

matt.fellows
2022-06-20 10:54
An assumption Pact makes, is that you have full control over your provider. Usually, you need unit-test level control over the provider, because you?re going to need to be able to mock/stub etc. various systems (database, downstream APIs etc.)

matt.fellows
2022-06-20 10:54
We talked about this in our very first AMA: https://docs.pact.io/help/amas#apac-1

matt.fellows
2022-06-20 10:54
_?What are the best practices for mocking provider dependencies??_

dstekanov.tech
2022-06-20 15:28
has joined #pact-js

qluck
2022-06-20 19:51
Hi all, I've got a question on using the regex function in a willRespondWith. It seems like the pact broker server isn't taking/liking me using regex in willRespondWith. Here's my code: ```.willRespondWith({ status: 400, headers: { "Content-Type": "application/problem+json", }, body: { title: "Bad Request", detail: regex( /.*invalid character.*/, 'File name *:|.<>+"...jpg contains invalid character(s)' ), }, })``` However, when I look on the pact broker server, it looks like this: ```[redacted] will respond with: { "status": 400, "headers": { "Content-Type": "application/problem+json" }, "body": { "detail": "File name *:|.<>+\"...jpg contains invalid character(s)", "title": "Bad Request" } }``` is there a reason these don't match? Are they supposed to not match? This is throwing an error in my pipeline preventing me from pushing any changes to my production environment.

john
2022-06-20 23:01
hey thanks for the response, ill take a read of what you say and try to make sense of it. Sorry i didnt respond yesterday had to put the kids to bed

tjones
2022-06-20 23:18
The regex matcher expects a string, not a regex


matt.fellows
2022-06-20 23:22
No worries - async is good! (I also have small children and the post bed time is the 5 minutes you get to relax before you realise you need to do all of the cleanup operation before another groundhog day :wink: )

tjones
2022-06-20 23:41
I only just realised we?re in the same timezone :sweat_smile:

john
2022-06-21 00:21
are you in Australia Tim?


john
2022-06-21 00:22
me too Bribane here

rohit.thadhani
2022-06-21 04:39
has joined #pact-js

dave.clissold
2022-06-21 08:11
Hi @matt.fellows Just noticed the failed test runs. Have fixed the problem and updated the pr

dave.clissold
2022-06-21 09:16
Here is a pr for the v3 branch as well https://github.com/pact-foundation/pact-js/pull/875

matt.fellows
2022-06-21 11:23
Awesome, thanks! I didn?t get time for a proper review, but realised I needed to unblock the run

matt.fellows
2022-06-21 11:23
thanks for fixing

matt.fellows
2022-06-21 11:23
it looks small enough of a change we should be able to pull it in. I?ll compare to the branch as well and try and jig the memory - I?m assuming you?ve tested actually using it locally also?

jvieira
2022-06-21 22:28
has joined #pact-js

jvieira
2022-06-21 22:56
Hello, I am seeing some weird behaviour but I am not able to find what I am doing wrong. Basically I have a contract already created and I am trying to test the provider side using `"@pact-foundation/pact": "^9.17.3"` This is my contract. It is already in the pact broker. ```{ "method": "POST", "path": "/files", "headers": { "Content-Type": "application/json" }, "body": { "clientId": "2454ad95-0352-4494-9a40-6afb333959e4", "fileContent": "xxxxofAAABAE=", } }``` In the provider side, I just created a test and added routes. Until here, everything is ok. The weird part is that when the verification happens with `new Verifier(options).verifyProvider()`, it calls the business logic code without the body. The other properties (baseUrl, method), they are passed to the the code, but not the body. ```http://router.post('/', (req, res, next) => { console.log("req.baseUrl", req.baseUrl) console.log("req.path", req.path) console.log("req.method", req.method) console.log("req.body", req.body) })``` The code above, generate this logs: ```req.baseUrl /files req.path / req.method POST req.body undefined``` Not sure why the body is now being sent to the endpoint being tested. I have done other contract tests, but all without request body and I never notice this before. Anyone has any ideas of what I could be doing wrong?

jvieira
2022-06-21 23:38
PS: I am running it using `"jest-pact": "^0.9.4"`

jvieira
2022-06-22 00:10
This is the testing class, removed everything and left the simplest ```const { Verifier } = require('@pact-foundation/pact') const express = require('express') const pactBrokerUrl = "https://pact-brokers.tools.XX.XX" const providerBaseUrl = 'http://localhost:3000/' const app = express() const server = app.listen(3000, () => { console.log("Service Listening") }) http://app.post('/files', (req, res, next) => { console.log("req.baseUrl", req.baseUrl) console.log("req.path", req.path) console.log("req.method", req.method) console.log("req.body", req.body) throw Error("only a test") }) const options = { provider: "file-service", providerBaseUrl, pactBrokerUrl, logLevel: "debug", consumerVersionTags: ["merge-requests/5984"], }; describe("Pact Verification", () => { test("validates the expectations", () => { return new Verifier(options).verifyProvider() .finally(() => { server.close() }) }) })```

jvieira
2022-06-22 00:10
and this is the script that I run `"test:pactProvider": "jest -c jest.contracts.provider.config.js --runInBand"`

tjones
2022-06-22 00:39
I would guess the problem is in the consumer test, not the verification

tjones
2022-06-22 00:40
can you share your consumer test code?

tjones
2022-06-22 00:42
Are you deleting your pacts in between test runs?

tjones
2022-06-22 00:42
It might be that you had an old interaction without the body that is still in the file

matt.fellows
2022-06-22 00:45
My guess is that you haven?t enabled the JSON body parser on your express app, and it?s not automatically parsing the body into JSON for you


matt.fellows
2022-06-22 00:47
Note the use of the `express.json()` middleware to automatically parse the body and make it available on the `req` object: ```var express = require('express') var app = express() app.use(express.json()) // for parsing application/json app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded http://app.post('/profile', function (req, res, next) { console.log(req.body) res.json(req.body) })```

tjones
2022-06-22 00:47
oh man, I thought they fixed that :disappointed:

tjones
2022-06-22 00:47
good pickup

matt.fellows
2022-06-22 00:48
This is the kind of thing you learn from experience!

matt.fellows
2022-06-22 00:49
Given it?s just built on the underlying Node http APIs, the issue is that express would need to guess in advance you want to consume the incoming byte stream into a particular format (e.g. JSON). This can be expensive, so is probably why they chose not to by default. But I imagine the 99/100 scenario is that people want to be able to parse JSON

tjones
2022-06-22 00:55
For me, the problem is that it's set to undefined and not some error type

matt.fellows
2022-06-22 00:56
yes, good point

tjones
2022-06-22 00:57
or, better - a raw buffer

tjones
2022-06-22 00:58
(sorry for cluttering the thread with my complaints about express)

jvieira
2022-06-22 01:48
I LOVE YOU GUYS! you made my day! I spent the whole day today trying to figure this out. It was what @matt.fellows said, I did not had `app.use(express.json())` middleware. Thank you so much @matt.fellows and @tjones for the help!

tjones
2022-06-22 01:54
Haha! You're very welcome! Glad you got it working

matt.fellows
2022-06-22 02:15
You?re welcome - it?s awesome helping somebody yesterday, today :laughing:

matt.fellows
2022-06-22 02:16
Imagine how productive I could be, if I could fix things yesterday?!

jvieira
2022-06-22 02:28
Only someone from the future could have an insight like that :lol2:

marcus.james
2022-06-22 15:28
has joined #pact-js

jonas.pena
2022-06-22 15:50
has joined #pact-js

abudi.hijazi.01
2022-06-22 16:44
has joined #pact-js

abudi.hijazi.01
2022-06-22 16:53
Hi I am having trouble running any tests using pact. I am not trying to send my pacts to pactflow yet, I am just trying to get them to run first I have 3 files User.js ```export class User { constructor({id, name, age}) { this.id = id; this.name = name; this.age = age; } }``` API.js ```const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); export class API { constructor(url) { if (url === undefined || url === "") { url = 'http://localhost:3000'; } if (url.endsWith("/")) { url = url.substr(0, url.length - 1) } this.url = url } fetchUser = async url => { fetch(url) .then(res => res.json()) .then(res => console.log(res)) .catch(e => console.log("Error from response: ", e)) } generateAuthToken() { return "Bearer " + new Date().toISOString() } } export default new API('http://localhost:3000');``` test.pact.spec.js ```import { Pact } from '@pact-foundation/pact'; import { API } from './API'; import { Matchers } from '@pact-foundation/pact'; import { User } from './User'; const { eachLike, like, regex } = Matchers; const mockProvider = new Pact({ consumer: 'User-frontend', provider: 'Nodejs-backend', port: 1234 }); describe('API Pact test', () => { beforeAll(() => mockProvider.setup()); afterEach(() => mockProvider.verify()); afterAll(() => mockProvider.finalize()); describe('retrieving a product', () => { test('ID 10 exists', async () => { // Arrange const expectedProduct = { id: '12', name: 'Sally', age: '32'} await mockProvider.addInteraction({ state: 'a user with ID 12 exists', uponReceiving: 'a request to get a user', withRequest: { method: 'GET', path: '/user/12', headers: { Authorization: like('Bearer 2019-01-14T11:34:18.045Z'), }, }, willRespondWith: { status: 200, headers: { 'Content-Type': regex({generate: 'application/json; charset=utf-8', matcher: 'application/json;?.*'}), }, body: like(expectedProduct), }, }); // Act const api = new API(mockProvider.mockService.baseUrl); const product = await api.fetchUser('10'); // Assert - did we get the expected response expect(product).toStrictEqual(new Product(expectedProduct)); }); }); });``` How would I run the test locally in my cmd? Any help is appreciated

tjones
2022-06-22 17:05
What test framework are you using?

tjones
2022-06-22 17:05
You run the test with that

abudi.hijazi.01
2022-06-22 17:06
what do you mean test framework?

tjones
2022-06-22 17:06
`toStrictEqual` is Jest, so I reckon your test framework is jest

tjones
2022-06-22 17:06
Also, what is the reason behind this import? ```const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));```

abudi.hijazi.01
2022-06-22 17:07
Im using node, node doesn't have fetch

tjones
2022-06-22 17:07
yes, but normally you would just `import fetch from 'node-fetch';`

abudi.hijazi.01
2022-06-22 17:08
idk I saw it on the node-fetch documentation so i copy pasted

abudi.hijazi.01
2022-06-22 17:08
it works anyways


tjones
2022-06-22 17:13
It's unrelated to the problem you're having, but the import you have copy pasted is a dynamic import, and if you don't need it, it's probably better to just do a standard ESM import. See the documentation here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import

tjones
2022-06-22 17:15
On your problem: Pact does not come with a test runner, so you need to run a pact test with one. Usually people just use whatever test runner they're using for unit tests - jest is by far the most popular, then mocha/chai. There are others, but they're less popular. See the examples directory I linked for other test runners

abudi.hijazi.01
2022-06-22 17:16
riiiiggghhhtt makes sense, thank you

abudi.hijazi.01
2022-06-22 17:16
Appreciate your help man

tjones
2022-06-22 17:17
You're welcome. If you are indeed using jest, then you might like to check out the example I linked - it uses `jest-pact` which you don't _need_ to use, but it substantially reduces the boilerplate setup in a pact test

tjones
2022-06-22 17:17
aaand if you're using mocha, then we also have `mocha-pact` which does the same thing

abudi.hijazi.01
2022-06-22 17:18
To be honest, I saw the terms jest and mocha thrown around, I didn't really understand what they were, the majority of the code in the test file is copied and pasted

abudi.hijazi.01
2022-06-22 17:19
Which is why I was confused when you asked me if I was using jest

tjones
2022-06-22 17:19
in your package.json, probably you've got a `script` with a `test` inside it. That will tell you what test runner you're using


tjones
2022-06-22 17:19
eg here

tjones
2022-06-22 17:20
sorry, it's `scripts` not `script`

abudi.hijazi.01
2022-06-22 17:21
It worked, thank you :pray:

tjones
2022-06-22 17:21
Awesome! Glad to help

abudi.hijazi.01
2022-06-22 17:24
One more q if you dont mind @tjones Does the syntax for writing a test change based on the test runner, or does it always stay the same

vaddisrinivas170497
2022-06-22 18:57
has joined #pact-js

matt.fellows
2022-06-22 21:50
The node JS syntax won't be different, but the API and methods available might. Mocha and Jest are very similar except the hooks/lifecycle methods are slightly different. Best to read the relevant test framework guides.

abudi.hijazi.01
2022-06-22 21:57
Thank you

adam.anderson
2022-06-23 03:46
has joined #pact-js

yegorisa
2022-06-23 03:47
has joined #pact-js

swapnil.jagdale
2022-06-23 05:19
has joined #pact-js

mark.mcmurray
2022-06-23 08:33
has joined #pact-js

edouard.lopez
2022-06-23 08:40
Hello, What does the `provider.verify()` verify exactly? Does it uses information from `willRespondWith` ? Or simply that the request sent match the `withRequest` info?

dave.clissold
2022-06-23 08:53
Hey Matt, apologies, spotted I missed pushing a commit on the v3 branch :man-facepalming:. Yeah have tested everything locally. Not sure how to resolve the failures on the v2 branch, that looks like it's something within your pipe. Am happy to upload screen capture evidence of local runs and attach them to the pr if it helps?

jacek.maciag
2022-06-23 09:15
has joined #pact-js

tjones
2022-06-23 09:46
Yes, it asks the mock if you sent what you said you would

matt.fellows
2022-06-23 13:06
All good, I thought they looked a bit light on :rolling_on_the_floor_laughing:

matt.fellows
2022-06-23 13:06
I'll address the pipe issues, early next week should be able to properly review and merge

matt.fellows
2022-06-23 13:06
Really appreciate it

yousafn
2022-06-24 08:42
Hey hey my pact js?ers, specifically v3 users. Have you encountered this issue https://github.com/pact-foundation/pact-js/issues/848 [V3] provider states with the same name are not exported to pact file It may be an issue in the rust core that is bubbling up to client libraries. If anyone has any ideas or time, we can help task a mini action force to try and get this quashed as removing blockers to getting pact-js v3 out! Thanks @artur for reporting.

sandor.arpa
2022-06-24 09:30
has joined #pact-js

abudi.hijazi.01
2022-06-24 10:32
I'm trying to run a test for the provider but I keep getting this error ```1) Pact verification: TypeError [ERR_INVALID_URL]: Invalid URL at new NodeError (node:internal/errors:372:5) at URL.onParseError (node:internal/url:553:9) at new URL (node:internal/url:629:5) at Verifier.isLocalVerification (node_modules\@pact-foundation\pact\src\dsl\verifier.js:302:17) at Verifier.setConfig (node_modules\@pact-foundation\pact\src\dsl\verifier.js:295:23) at Verifier.verifyProvider (node_modules\@pact-foundation\pact\src\dsl\verifier.js:86:18) at Context.<anonymous> (test\provider.spec.js:27:25) at processImmediate (node:internal/timers:466:21``` Line 27 is the return line below ```return new Verifier(opts).verifyProvider().then(() => { console.log("Pacts verified and published"); });```

matt.fellows
2022-06-24 10:33
so the error seems to be pretty clear to me. What options have you given the verifier?

abudi.hijazi.01
2022-06-24 10:34
``` let opts = { pactBroker: "http://hijazi.pactflow.io", provider: "Node API (Provider)", consumerVersionTags: ["main"], publishVerificationResult: true, //generally you'd do something like `http://process.env.CI === 'true'` providerVersion: "version 1.0", //recommended to be the git sha providerVersionTag: "1.0", stateHandlers: { //If you have defined any states in your consumer tests, the Verifier can put the provider into the //right state prior to sending the request. }, beforeEach: () => { console.log('I run before everything else') }, afterEach: () => { console.log('I run after everything else has finished') } };```

matt.fellows
2022-06-24 10:35
You need to pass the `providerBaseUrl` argument

matt.fellows
2022-06-24 10:35
i.e. the thing you are testing

abudi.hijazi.01
2022-06-24 10:35
As another option?

matt.fellows
2022-06-24 10:36
it?s an attribute of `opts`

abudi.hijazi.01
2022-06-24 10:36
right, let me try, thanks

matt.fellows
2022-06-24 10:36
it should be a URL pointing to your locally running HTTP provider

abudi.hijazi.01
2022-06-24 10:38
This is my output ```Error: Must provide the pactUrls argument if no pactBrokerUrl provided```

abudi.hijazi.01
2022-06-24 10:38
pactBroker is provided though

matt.fellows
2022-06-24 10:39
read the error message carefully

matt.fellows
2022-06-24 10:41
`pactBroker` is not `pactBrokerUrl`

matt.fellows
2022-06-24 10:41
There are TS types if you?re using an IDE which should help


mwilso29
2022-06-24 11:19
has joined #pact-js

renaud.meurisse
2022-06-24 12:47
has joined #pact-js

dave.clissold
2022-06-24 12:50
No, thank you for helping get this in, we need it to implement pact into our testing. Once I can prove to the boss I've got it running in the pipeline on one service, I can get those magic 16 digits for a full pactflow account.

abudi.hijazi.01
2022-06-24 15:20
Also I realised, if I put `return` the pact doesn't pass, and even when it does pass, it's not calling my API This is my verifier method without `return` ```new Verifier(opts).verifyProvider() .then(output => { console.log("Pacts verified and published"); console.log(output); })```

matt.fellows
2022-06-25 04:33
what do you mean by ?return?? I think you might be saying `return new Verifier(opts)?` . If so, you must do that, otherwise you?re not properly handling the promise. If you don?t know what that means, I highly suggest you pair with a developer

matt.fellows
2022-06-25 04:34
> and even when it does pass, it?s not calling my API So to help you understand what might be going wrong, i?d suggest following the debugging guide in the https://github.com/pact-foundation/pact-js/ and coming back here with the information you?ve found

matt.fellows
2022-06-26 02:48
OK that was a bit of a pain. For some reason we?ve started seeing some new failures that are definitely unrelated to Pact JS code changes. In any case, a cleanup was required and has been done, and your changes are now https://github.com/pact-foundation/pact-js/runs/7057640022?check_suite_focus=true in the latest version: 9.18.0. I seem to have an issue with it in the V3 branch, so i?ll have to dive into it. Provider side tests seem to be hanging, and reverting the proxy change. I?ll take a look this week, or if I?m lucky tonight

matt.fellows
2022-06-26 05:41
Ok found the issue. I've released the v3 branch too. Let me know how it goes!

rk8085858
2022-06-26 08:12
has joined #pact-js

alex.savage
2022-06-27 08:26
has joined #pact-js

simon.selvadurai
2022-06-27 08:28
has joined #pact-js

yasir.khan
2022-06-27 11:21
has joined #pact-js

willem.basson
2022-06-27 11:25
has joined #pact-js

edward.francis
2022-06-27 11:32
has joined #pact-js

laura.cabantous
2022-06-27 11:35
has joined #pact-js

ruslan.charuh
2022-06-27 12:18
has joined #pact-js

pramod-arjun.bhalerao
2022-06-27 12:54
has joined #pact-js

ssomepalli
2022-06-27 14:30
has joined #pact-js

owen.oclee.old
2022-06-27 16:13
has joined #pact-js

laura.cabantous
2022-06-27 16:19
Hi, I'm trying to use eachLike with a minimum of 2, according to this https://docs.pact.io/implementation_guides/javascript/readme#match-based-on-arrays: ```eachLike(propertyDocumentWithoutTransactions, { min: 2 })``` However, I'm having the following warning when running the test: `Pact Binary Error: WARN: Only the first item will be used to match the items in the array at $['body']['addresses']` Can anyone help explain what this means?

oherescu
2022-06-27 19:21
has joined #pact-js

matt.fellows
2022-06-27 22:37
Can you please show what value you've passed in as the first Arg?

matt.fellows
2022-06-27 22:39
And also the context in which it's used? It may not actually be an issue

matt.fellows
2022-06-27 22:39
Is that error on the consumer or provider side?

harris
2022-06-27 22:48
hello, question for provider state workflow between consumer / provider so I know consumer test require certain data, so we are using provider state endpoint to inject test data set up in provider. however, in real world, who is responsible for adding / updating provider state and test data? is that provider team should update for consumer or consumer team just add? I think in behind scene, provider / consumer team should discuss prior before write any test ? and provider team should update the state for consumer team? what is the recommendation workflow?

matt.fellows
2022-06-27 23:06
They are the consumer team's responsibility to work with the provider team and discuss the states. So you're right - they should communicate! I know some provider teams publish the available states that can be used to help consumer teams know what states that can be used

harris
2022-06-27 23:12
yeap that is make a sense to me :slightly_smiling_face: thanks Matt

tjones
2022-06-28 03:29
This happens when you try to specify more than one array item I think. The first argument should describe a single entry of the array that will be used to match all entries


tjones
2022-06-28 03:32
or in the pact-js matchers

nathan.tejuco
2022-06-28 03:50
has joined #pact-js


jun.ito
2022-06-28 07:47
has joined #pact-js

daniel.shamaeli
2022-06-28 09:01
has joined #pact-js

owen.oclee.old
2022-06-28 09:43
I was working with Laura on this so providing the additional details: Value of the first arg that?s being passed in: ```{ address: { uprn: integer() }, transactions: { sales: { history: eachLike({ price: integer(), date: iso8601Date() }) } } }``` The error is when running the consumer contract tests; here?s the context: ```await provider.addInteraction({ // ... willRespondWith: { // ... body: { addresses: eachLike(propertyDocument, { min: 2 }), } } });``` The tests still run so it?s probably not a problem, but the error threw us off a bit and it?s not clear if we need to do something about it?

tjones
2022-06-28 09:44
I don't think you need to do something about it, but I do think it's a bug. Might be worth opening an issue about it

tjones
2022-06-28 09:45
After looking at the additional details, I'm certain this isn't anything you've done.

tjones
2022-06-28 09:45
Another improvement that could be made is to stop pact from saying there was an error when the only lines to stderr start with WARN

tjones
2022-06-28 09:46
(It should still print the warning)

michael.oloyede
2022-06-28 09:55
has joined #pact-js

dany.marques90
2022-06-28 10:07
Hi, Could you please have a look at this please: https://github.com/pact-foundation/pact-js/issues/880 It?s actually blocking all our pipelines :confused:

matt.fellows
2022-06-28 10:14
I'll merge later tonight and release a new version. .

matt.fellows
2022-06-28 10:15
P.s. having a pipeline blocked on this is a bit crazy. The vulnerability is still there, blocking a pipeline just means you can't do anything else in the meantime

matt.fellows
2022-06-28 10:17
But I assume it's something security have put in place to annoy you :rolling_on_the_floor_laughing:

dany.marques90
2022-06-28 10:28
Yes it's exactly that :joy: I mean this dependency will never reach the production but anyway everything is blocked :confounded:

matt.fellows
2022-06-28 11:04
New release on the way out, assuming the upgrade doesn?t break things

matt.fellows
2022-06-28 11:08
> I don?t think you need to do something about it, but I do think it?s a bug. Might be worth opening an issue about it I recall this is a recurring issue that Beth has just never been able to fully whack-a-mole to completion.

matt.fellows
2022-06-28 11:08
So I?d just plod on, and if it causes issues on the provider side we can look into it. It looks good to my eyes also

tjones
2022-06-28 11:09
I think this might even happen in one of the examples :/

matt.fellows
2022-06-28 11:13
Wow, so a disputed security issue in a dev dependency blocked your build :eyes: https://github.com/ramda/ramda/pull/3192#issuecomment-975677276

matt.fellows
2022-06-28 11:14
batman slap

matt.fellows
2022-06-28 11:14
Go find your security people and give them a little tickle

dany.marques90
2022-06-28 11:46
:joy:

dany.marques90
2022-06-28 11:47
They don?t care if it?s a devdep or dep. Basically the vulnerability analysis is red whenever it finds in the node_modules a vulnerable dependency with a CVSS score greater than 9.

dany.marques90
2022-06-28 11:47
:disappointed:

matt.fellows
2022-06-28 11:51
:grimacing:

yousafn
2022-06-28 12:08
> They don?t care if it?s a devdep or dep. That is bad sec practise, as it gets people worried about the wrong thing imo. Hope you are sorted now, but the sec team will have to understand that open source projects do not have necessarily have SLA's for user's issues, and blocking your entire pipeline for code outside your control is a serious risk.

yousafn
2022-06-28 12:09
Are your teams vetting all open source code and it's dependencies before pulling it in? do you review chances applied by security vulnerability patches to ensure they don't cause more issues, than they try to fix?

yousafn
2022-06-28 12:10
Thanks Matt for pushing the change out, and Dany for raising via GH :thumbsup:

owen.oclee.old
2022-06-28 13:11
Thanks both, it seems to behave fine on the provider side so all is well

tjones
2022-06-28 13:22
I thought I removed Ramda a while back, but maybe I only did that in the beta (or maybe I remember wrong)

tjones
2022-06-28 13:23
I wanted to remove ramda and lodash, as pact doesn't really need them and they both had this kind of churn

dany.marques90
2022-06-28 16:40
No, the vulnerability scan only occurs in the pipeline and not when developers pull the dependencies. But anyway they are not really exploitable locally or am I wrong? And no we don't review the changes, we basically use a tool that blocks the pipeline if you have in your node modules a known vulnerability with a CVSS score greater than 9.

matt.fellows
2022-06-29 01:04
We definitely don?t need both. When I made those changes to bring in the request filter the other day I noticed one branch had ramda and the other didn?t

matt.fellows
2022-06-29 01:04
I prefer ramda over lodash/underscore for a number of reasons.

matt.fellows
2022-06-29 01:05
In this case - not that it matters - but ramda made the case that it?s not actually a prototype poisoning vulnerability, but because somebody raised a PR/issue and used those words, Veracode (who submitted the CVSS) scored it as a 9, using the very same issue as the justification. The CVSS now states ?disputed? (and rightly so).

matt.fellows
2022-06-29 01:06
But practically it doesns?t matter, it got submitted to the scoring system and the effect is the same, even if there is no actual exploitable vulnerability

matt.fellows
2022-06-29 01:06
doubly so, because it?s a dev dep

lucas.azzola
2022-06-29 04:18
has joined #pact-js

harris
2022-06-29 04:41
HI Matt, me again lol for provider state setup, when ID is randomly generate in provider side, https://github.com/pact-foundation/pact-js/blob/feat/v3.0.0/examples/v3/provider-state-injected/consumer/transaction-service.test.js `fromProviderState` this way is looks great, so consumer can use random id from provider :slightly_smiling_face: my question is v3 looks like still in beta but I can use it right now? it seems beta for 2years so I believe is it mature enough to use? thanks

matt.fellows
2022-06-29 05:45
> it seems beta for 2years oomph. that does hurt to hear, but yes I think you?re safe to use

matt.fellows
2022-06-29 05:45
There has been some progress behind the scenes to refactor this, so I?m hopeful very soon, that beta tag will be RIP

harris
2022-06-29 05:47
okkkk, thanks Matt :slightly_smiling_face: sorry I didnt meant to hurt you haha always appreciate your help :thumbsup:

abubics
2022-06-29 06:18
Also, blocking the build doesn't mean the dep can't make it to prod, it might already be in prod if it was identified late.

tjones
2022-06-29 07:32
I've never been brave enough to tell security this, for fear that they might say "good point, we'll rig up a script that undeploys everything that has a vulnerable dependency"

jens.suhr
2022-06-29 09:25
has joined #pact-js

thammarith.likittheer
2022-06-29 10:46
has joined #pact-js

andrevpuc
2022-06-29 14:24
has joined #pact-js

mylesjj
2022-06-29 16:26
has joined #pact-js

damianruizdev
2022-06-29 23:51
Hey there, I have two pact tests - one is a simple GET request for all games and the other is a GET request to retrieve a game by ID(query param). For some reason, the pact test with the query param is throwing a `No matching interaction found` Any idea why the pact test for the GET request w/ a query param would be failing when it's seemingly identical to the other working pact test?

damianruizdev
2022-06-29 23:58
Here is a picture of the logs. I'm not really sure how to interpret the missing requests and unexpected requests matching

yousafn
2022-06-30 00:27
Pretty sure there is a query param you can set in the withRequest https://github.com/pact-foundation/pact-js/blob/51d2ae2e41c8c40e373f264ac7ba633d258604c2/examples/jest/__tests__/index.spec.js#L72 Can't seem to find it in the readme, on mobile and just about to hit the sack

yousafn
2022-06-30 00:28
But might be enough to help you going. Thanks for sharing the logs

damianruizdev
2022-06-30 00:30
Thanks Yousaf! Looks like that's what I needed. Have a goodnight:slightly_smiling_face:

matt.fellows
2022-06-30 01:00
I wonder if we can detect this situation and complain, letting users know the query string should be in the `query` property? :thinking_face:

tjones
2022-06-30 01:35
absolutely. `?` is not allowed in paths, so it's a trivial check

yousafn
2022-06-30 01:36
that would be lovely, but if we could detect that, we could probably just stick in it the query prop itself, so idk. first start is get it documented on the readme, as it isn't at the mo.

tjones
2022-06-30 01:37
I don't think we should rewrite the path for them - the property is for the path, not the query

yousafn
2022-06-30 01:39
yeah thats gnarly I agree, it depends on how helpful you want be, but that is too opaque. The fact it isn't in the pact-js docs means people don't know that query prop exist unless they look at code or other pact docs, which is why they are putting query in the string in the first place

yousafn
2022-06-30 01:39
and people see query params in strings in their web browser so much confuse

yousafn
2022-06-30 01:40
Glad it was a the right answer for Damien, as I have some outstanding issues around query strings in javascript land, that may be resolved now, from back in the day

yousafn
2022-06-30 01:41
and we can sort out a nice little snag in the docs that should help some folks for the future, and then get the nice DX stuff in the logs. :yellow_heart:

tjones
2022-06-30 03:39
It's hard to be too helpful with query strings because they're not clearly defined. The W3C recommends using `application/x-www-form-urlencoded`, but that recommendation is not required by any standard. An important difference is how spaces work - spaces in `application/x-www-form-urlencoded` are encoded as `+`, but in general URLs, they're URL encoded to `%20`. Also, there's no standard at all for repeat parameters - some implementations will do `key=val1&key=val2`, some will do `key[]=val1&key[]=val2`, and some will do `key[1]=val1&key[2]=val2`. I think `key[]` is what pact does (and the most common interpretation), but I don't actually know. The W3C recommendation is just to treat it as a list of pairs, and doesn't say that the keys need to be unique.

oliviawalsh1
2022-06-30 09:49
has joined #pact-js

greg.tyler
2022-06-30 14:22
Hello, I have a few questions about https://github.com/pact-foundation/pact-js/issues/626: ? As a Karma + pact user, am I right in thinking that my two options are (1) use a different test runner (and rewrite tests) or (2) pin pact-web to 9.17.x? ? Will patch releases of 9.17.x always support pact-web? ? Will 9.17.x receive any continuing support, e.g. security patches?

abhishek.lamba
2022-06-30 18:24
Hello Team, I am having an issue, Mock server is not starting, following error appears:-[2022-06-30 18:10:11.622 +0000] DEBUG (19956 on): pact-node@10.17.4: Created 'C:\Users\**\node_modules\@pact-foundation\pact-node\standalone\win32-1.89.01-rc1\pact\bin\pact-mock-service.bat' *process with PID: 16468* *ERROR: The process "16468" not found.* [2022-06-30 18:10:12.226 +0000] DEBUG (19956 on ): pact-node@10.17.4: C:/Users/**/node_modules/@pact-foundation/pact-node/standalone/win32-1.89.01-rc1/pact/lib/ruby/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider (LoadError)

yousafn
2022-06-30 20:40
Really good information there Tim! thank you for that. That is indeed going to be awkward, in trying to be proactively helpful. I might use some of that, and w3c's recs, and test out a few combos so we can offer at some guidance on what Pact supports and doesn't support. As unclear as it might be, we can at least provide guidance on what we are able to cover, by ways of tests, my favourite kind of documentation.

tjones
2022-06-30 22:56
I'm not across the maintainer parts of your question (in case this is surprising, I stopped maintaining pact in January to focus on other things) - but unless you're using pact in a kind of integration test-like scenario where you're clicking buttons to cause API requests, it shouldn't require substantial rewrites of tests. You can make introducing a separate test runner straightforward with a pattern like `*.spec.ts` for regular tests and `*.spec.pact.ts` for pact - I sometimes do this if the pact run is large.

tjones
2022-06-30 22:57
Also, you won't have to pin pact-web - pact-js no longer releases pact-web (which only existed to support karma etc)

harris
2022-06-30 23:36
Hello question about `api gateway / service mesh` When services to services interact through api gateway or service mesh, what is the boundary of the consumer test? I think from `consumer <-> api gateway/mesh MOCK` and generate pact then `pact <-> api gateway/mesh + Provider` is that right approach? but for me, api gateway / mesh is just one layer to invoke function or other services. how to write contract for that? for example, most of AWS lambda integrate with API gateway. I can see example of lambda to invoke the function to write contract test, but I am not really sure how to deal with api gateway / service mesh layer boundary. hope it makes a sense lol

tjones
2022-07-01 00:10
You can see examples of ways to use pact-js (which will continue to release) with web apps in the examples folder.

matt.fellows
2022-07-01 01:39
This looks like a Windows long path issue. See the issues on github for why this happens. Your options: 1. shorten the project path (i.e. move closer to `C:`) 2. Use the new beta branch

matt.fellows
2022-07-01 01:45
Hi Greg, > Will patch releases of 9.17.x always support pact-web? I don?t plan on releasing any new versions of Pact Web at this stage, but could be talked out of it for say a critical zero day vulnerability. Realistically, that package actually hasn?t changed significantly for years aside from dependency updates (it?s a thin shim API based on the real Pact JS). All of the functionality it has is actually in other packages (`pact-node` which will definitely still be maintained for a while, likely a year or more given it?s the current main core implementation for Pact JS, and in your case, `karma-pact` is still a thing). Karma pact is still maintained, albeit as you?ll probably have noted it receives very little attention and we don?t have any plans to support it during the next major upgrade of Pact JS (and the core module that powers it - `pact-core` )

matt.fellows
2022-07-01 01:50
Not saying it?s a _good_ idea, but Pact Web could easily be pulled out of the current Pact JS project into it?s own module (as I said, it?s a fairly small API) and could be left in a separate repo/package that is then made to be compatible with `pact-karma` and `pact-node` if updates are really needed. As far as Pact is concerned, these packages have never really felt like first class citizens and don?t have a bunch of features that we?d like to have for parity and consistency. The idea of taking away something definitely pains me, but the maintenance burden has been weighing on us (it?s not just the code to manage, but failed builds, issues, community questions etc.) and the more we can focus on the core of the product the better for all. So, apologies I know it?s probably frustrating, but I hope you can appreciate the why now!

matt.fellows
2022-07-01 02:06
I?ve just merged an old PR that was in DRAFT status to https://docs.pact.io/recipes/apigateway. (It might take 5/10 to show up with the content whilst the netlify build runs)

matt.fellows
2022-07-01 02:06
That should give you some ideas

harris
2022-07-01 03:11
oh cool thanks Matt, :+1:

harris
2022-07-01 03:52
`Use a test only controller that is aware of the different public-facing request paths` is that mean we can skip gateway part, but adding gateway like layer for testing purpose? and get request and response?

matt.fellows
2022-07-01 05:09
yes, basically

matt.fellows
2022-07-01 05:09
only if the paths are different (which they often can be)

hiepluong2205
2022-07-01 06:40
has joined #pact-js

abhishek.lamba
2022-07-01 07:45
Thanks Matt :slightly_smiling_face:

greg.tyler
2022-07-01 08:35
Thanks both, that certainly clears things up for me. My project currently involves a bunch of old tech (i.a. AngularJS :hear_no_evil:), which is why we?re a bit trapped in Karma world, so ultimately this is just one more thing to push us towards modernising :muscle:

matt.fellows
2022-07-01 10:28
You?re welcome - best of luck!!

jens.suhr
2022-07-01 11:32
@jens.suhr has left the channel

saleh.elnagar
2022-07-01 13:20
has joined #pact-js

animesh.kumar
2022-07-03 16:54
has joined #pact-js

harris
2022-07-03 23:56
Happy Monday Matt, one extra question, our company uses graphql mesh, so some endpoint were REST(aws lambda) and converted to graphql, is this case I think blackbox approach is better? send graphql request/response? little bit complicated , but I know about your opinions :slightly_smiling_face:

matt.fellows
2022-07-04 00:01
I?m not sure I follow sorry, could you please elaborate?

matt.fellows
2022-07-04 00:01
Are you saying you?ve replaced HTTP/RESTful endpoints with GraphQL?

harris
2022-07-04 00:03
yeap becuz some of services are using REST(legacy) some of them are graphql, so company uses graphql-mesh services to convert REST to graphql (https://www.graphql-mesh.com/) to talk service to service

harris
2022-07-04 00:04
so in this case I think `graphql-mesh` is kind of same as `api gateway` but I am not sure, CDCT should send REST(without mesh) or just include graphql mesh + provider and send graphql call

harris
2022-07-04 00:05
I think graphql request(more like blackbox) is more make a sense, as consumer is looking for graphql response, but I want to know your opinion

matt.fellows
2022-07-04 00:08
Does the mesh run on developer machines or only in environments?

matt.fellows
2022-07-04 00:08
I?d say it?ll be hard to pact test though, because of the way it will want to work

harris
2022-07-04 00:09
we can run in local machine with graph ql mesh

matt.fellows
2022-07-04 00:09
If you do write pact test, you should write them as far as the consumer is concerned - what queries it actually makes (GraphQL). Then you would need to ensure the gateway (graphql mesh) knows how to handle it. But that would require unit tests of the mesh, that also setup contract tests to downstream systems

matt.fellows
2022-07-04 00:10
in theory, contract tests are perfect here because now you have an all-knowing intermediary, and if it gets out of sync things will break. but in practice depending on the tooling it might be difficult

harris
2022-07-04 00:10
in this kind of complicate case, BDCT is better? as it is more like blackbox ?

matt.fellows
2022-07-04 00:12
possibly, but we don?t support GraphQL schemas at this moment

harris
2022-07-04 00:14
yeap looking forward to see it in the future :slightly_smiling_face: I will try to roll out CDCT first with simple direct end points communication then once BDCT graphql release, I will look for other services :slightly_smiling_face:

harris
2022-07-04 00:15
I am in the beginning stage of promo contract testing in my company but so much things to consider lol haha but glad I can ask questions in here thanks Matt

matt.fellows
2022-07-04 00:16
You?re welcome!

omri.benyair
2022-07-04 03:14
has joined #pact-js

harris
2022-07-04 05:48
Hello, me again lol upgrading pact to use V3, from `9.17.2` to `10.0.0-beta.60` it causes GLIBC error ``` /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /app/node_modules/@pact-foundation/pact-core/build/Release/libpact_ffi.so)``` is there any fix / recommendation to work around that?

zhaoyi0113
2022-07-04 05:53
Hello, I am using `jest` for contract testing library. Does anyone know how I can run a single contract test in provider side? It seems every time it runs all contract tests downloaded from the broker. Is there a way to run just one?


matt.fellows
2022-07-04 05:55
There should be terminal output showing how to do that

matt.fellows
2022-07-04 05:55
You?ll need to ensure glibc version 2.25 is installed. Are you running a really new / old OS?

harris
2022-07-04 06:04
maybe perhaps old version causes issue ```root@05bea7a0a1d7:/app/app# apt list libc6 Listing... Done libc6/now 2.24-11+deb9u4 amd64 [installed,local] root@05bea7a0a1d7:/app/app# ldd --version ldd (Debian GLIBC 2.24-11+deb9u4) 2.24 Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.```

harris
2022-07-04 06:04
try to upgrade now

harris
2022-07-04 06:08
the latest stable version of glibc which debian 9 supported is 2.24, do we need to upgrade OS? , if so which one is recommended? it is for CI pipeline

harris
2022-07-04 06:09
`node:14-slim`

harris
2022-07-04 06:12
we are using now, do we need to upgrade?

harris
2022-07-04 06:19
it is little bit weird, we upgrade to node-16 slim `Debian GNU/Linux 10 (buster)` now it complaints ```/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found```

matt.fellows
2022-07-04 06:20
Is is technically (just!) Out of support and end of life.

matt.fellows
2022-07-04 06:20
:thinking_face:

matt.fellows
2022-07-04 06:21
Looks like libc wants a different glib C. You can have both I believe

harris
2022-07-04 06:23
it looks like always complaints version lol when we tried node-14, it installed 2.24 but looking for 2.25 node-16 it installed 2.28 but looking for 2.29 lol

zhaoyi0113
2022-07-04 08:00
yes I have seen this when it fails. The question is how I can run a single one without fail it first?

matt.fellows
2022-07-04 09:25
Same process, just need to set the env var in advance

matt.fellows
2022-07-04 09:29
Interesting. I'll see if I can reproduce. I know we need a specific glib C min but if the OS brings in a new set there will be different transitive dependencies

tjones
2022-07-04 10:30
You can tell gcc to compile against a lower glibc (the default is the highest, I believe). However, I'm confused about why it complains about different requirements on different OS / node combinations. Is this `.so` file compiled on demand? It could be a problem in the toolchain somewhere.

tjones
2022-07-04 10:30
or some complexity that I don't know about :confused:

tjones
2022-07-04 10:31
> The question is how I can run a single one without fail it first? Why do you need to do this?

matt.fellows
2022-07-04 10:38
It is compiled on demand

matt.fellows
2022-07-04 10:38
The FFI is dynamic though, as you know

matt.fellows
2022-07-04 10:39
As an aside, I think an update to the issue template will be warranted here

tjones
2022-07-04 10:41
`libpact_ffi.so` <-- is this compiled by the rust thingy, or by the node-gyp machinery? (I forget)

tjones
2022-07-04 10:45
If the node-gyp machinery, I suspect it is misconfigured. If by rust, then perhaps the glibc requirements can be lowered

matt.fellows
2022-07-04 10:47
That's pre compiled. Good idea, but not sure it explains the problem here? (I think glibc 25 is required from memory)

matt.fellows
2022-07-04 10:47
If you pin to say, glibc 22 my assumption is it's forward compatible?

tjones
2022-07-04 10:48
Yes, I think that's right. I'm confused about why the version changed when the OS (probably the culprit) and node version changed, though.

artur
2022-07-04 10:56
Should it be possible to use matchers in content-types of a request? (V3 .59 & .60) I get `PactffiWithBody(arg 2) expected a string`

matt.fellows
2022-07-04 11:04
As in, a header?

matt.fellows
2022-07-04 11:04
I think so



tjones
2022-07-04 11:09
(in the pact file, at least)

tjones
2022-07-04 11:09
well, maybe not explicitly. They are at least in the examples :sweat_smile:

artur
2022-07-04 11:10
this works for me ```provider.uponReceiving(`as '${user}', a PUT request to upload a file to '${file}'`) .withRequest({ method: 'PUT', ... contentType: 'text/plain; charset=utf-8' }) .willRespondWith(response)``` but this not ```provider.uponReceiving(`as '${user}', a PUT request to upload a file to '${file}'`) .withRequest({ method: 'PUT', ... contentType: MatchersV3.regex('text/plain(;()?charset=(utf|UTF)-8)?', 'text/plain; charset=utf-8') }) .willRespondWith(response)```

matt.fellows
2022-07-04 12:26
It should definitely be supported. Is the error on the consumer or provider side?

matt.fellows
2022-07-04 12:26
I know I tested it with Go so the core supports it at least, so could be a bug/feature in JS land if we haven't added it there

chriswilliamsef
2022-07-04 13:11
has joined #pact-js

rioka68
2022-07-04 13:32
has joined #pact-js

heinenm
2022-07-04 14:01
has joined #pact-js

dave.clissold
2022-07-04 15:18
Thanks Matt, apologies for the delay in replying, had a few days off. Everything is looking good in both branches

zhaoyi0113
2022-07-04 21:32
@tjones that?s because running all contract test takes give a lot of logs, it is hard to find out which log is for which test. Run individual one makes debug much easier.

harris
2022-07-04 22:27
Hello, so should I try glibc 22??

harris
2022-07-04 22:27
and node-14:slim is out of support , right?

tjones
2022-07-04 22:28
Could you make a reproduceable docker container?

harris
2022-07-04 22:31
yeap I hace docker file, but we pull down image from organisation AWS lol I will share brief one, before update to `beta` it was working btw

harris
2022-07-04 22:32
```FROM `{THIS IS ORGANISAION AWS}`/node:14-slim RUN apt-get update -y && \ apt-get install -y git g++ libpq-dev awscli curl && \ curl -L "https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64" \ -o /usr/local/bin/cc-test-reporter && \ chmod +x /usr/local/bin/cc-test-reporter && \ rm -rf /var/lib/apt/lists/* RUN yarn global add aws-cdk@latest typescript ts-node COPY package.json /app/package.json COPY yarn.lock /app/yarn.lock WORKDIR /app RUN yarn```

tjones
2022-07-04 22:33
The stable release doesnt do this compilation, so that's not a surprise. I'm curious why the version error is changing between docker images- probably I just don't understand something

tjones
2022-07-04 22:33
We can't reproduce with that docker image, because we don't have the images or the files it is copying

harris
2022-07-04 22:35
the only change, we did is `"@pact-foundation/pact": "~9.17.2",` to beta version `10.0.0-beta.60` lol

tjones
2022-07-04 22:36
If you can reproduce this with a public docker image and package.json (etc), that would be helpful

harris
2022-07-04 22:36
ok let me try

matt.fellows
2022-07-04 22:54
Great thanks! Really appreciated your help :pray:

john
2022-07-04 23:37
Just a quick question about this Beta js version 3. The provider is written in PHP and from what I can see the issue is that because the org uses Doctrine so that many ids are autogenerated and cannot be inserted into Db with unique ids as the DB does this automatically (we cant know the id before hand). To overcome this Timothy suggested that we use the Beta version with the fromProvideState hook in the consumer test to overcome this issue. To better understand this, we still need to set up a provide state end point in the Provider ? So that the data can be inserted in the database and this will be fetched back to the consumer and injected into the consumer via this fromProviderState? Presumably the provider stuff has to be written in php?

tjones
2022-07-05 01:06
That's a good use case. Carry on :+1:

tjones
2022-07-05 01:08
it depends what you mean by "provider stuff". For php, the easiest thing to do will be to add a state change endpoint (probably written in PHP) that knows how to manipulate the provider state

tjones
2022-07-05 01:12
Alternatively, if you're inserting directly into the DB, you could write your provider verification in anything (eg using pact-js and the state change hooks). But I would not do this because: 1) You're introducing a new language on the provider just for testing 2) It's not best practice for the state change endpoints to know DB insert calls - generally better for them to manipulate the DB though domain objects. This is because it's better for the state to be like `userTenExists = () => users.add(10, {/* whatever user properties */})`, because then: ? Your tests use the same language as the domain ? Your tests happen to cover some of the repository logic by virtue of needing it for the provider state setup ? Your tests aren't assuming particular DB state (if you insert arbitrary stuff into the DB, how do you know the arbitrary stuff is the right arbitrary stuff?)

john
2022-07-05 01:12
by stuff I mean the whole application is written in php

tjones
2022-07-05 01:13
In that case: > we still need to set up a provide state end point in the Provider ? Yes, or the other approach above if it happens to be easier for you (I would do the state change endpoint though)

john
2022-07-05 01:14
so bascially write a state change endpoint in php and the consumer testwriten in say js cant still get that info before it runs correct?

tjones
2022-07-05 01:14
The consumer test never needs that info

tjones
2022-07-05 01:14
The info is only used during provider verification

tjones
2022-07-05 01:15
so you say something like: This request is `GET /users/$userIdFromProvider`, and when it runs on the consumer test you can say "for example, 10"

john
2022-07-05 01:16
1. write the consumer test with that getProviderState hook (javascript) 2. write the producer test in php 3. write the state change endpoint in PHP that twill feed back the consumer

tjones
2022-07-05 01:16
then the provider verification goes like this: 1) Hey provider, please init the state "a user exists" 2) "Ok, your user ID is 123" 3) Great, here's a request `GET /users/123`

john
2022-07-05 01:16
so basically because we use Doctrine

tjones
2022-07-05 01:17
> write the state change endpoint in PHP that twill feed back the consumer No. The provider state change endpoint never sends anything back to the consumer

tjones
2022-07-05 01:17
it sends back data that is used to inform the mock of the consumer that pact runs for you

john
2022-07-05 01:17
so I created all this using python and got it all working

john
2022-07-05 01:18
but the PHP app uses php doctrine which autogenerates the id in the db

john
2022-07-05 01:18
so the contract doesnt know the id

john
2022-07-05 01:18
and neither does the provider before hand

tjones
2022-07-05 01:19
step 3 is: 3. write the state change endpoint in PHP that will tell pact what value to use for the `fromProviderState` bit when mocking the consumer request

tjones
2022-07-05 01:19
> so the contract doesnt know the id Correct > and neither does the provider before hand Correct But, the provider *does* know after the state change endpoint has been called. And it can return that info in the response

john
2022-07-05 01:21
so basically if i have a state change function: ```def pact_add_expected_user: # add the user to the db # return the user id to pact```

john
2022-07-05 01:24
so when the provider contract test is run it will use the returned value from the pact_add_expected_user and both the consumer /provider contract test should be happy

tjones
2022-07-05 01:24
the consumer test should _already_ be happy, otherwise you won't have a contract to verify

john
2022-07-05 01:24
yes thats right

tjones
2022-07-05 01:24
but otherwise, yes

john
2022-07-05 01:25
the consumer test seems to be very easy to m,ake

tjones
2022-07-05 01:25
it is :slightly_smiling_face:

john
2022-07-05 01:25
....once you have navigated the docs that is LOL

tjones
2022-07-05 01:25
so, I can't remember if the response format for the V3 state change endpoint is documented. I remember I had to read the code when we were working on the beta

tjones
2022-07-05 01:26
It would be very useful to split out the docs. If I were still working on pact, that's something I'd like to make a priority

john
2022-07-05 01:26
yeah i think the docs could be streamlined a lot better

john
2022-07-05 01:28
do you meant he response that gets sent back fromt he setup_state_endpoint?


john
2022-07-05 01:32
when i wrote the provider state in python I did somethign. like this:

john
2022-07-05 01:33
so it will have a different format to that right

tjones
2022-07-05 01:35
Aha, it's at least documented in the intellisense: ```/** * Respond to the state setup event, optionally returning a map of provider * values to dynamically inject into the incoming request to test */```

tjones
2022-07-05 01:37
```export interface ProviderState { action: StateAction; params: JsonMap; state: string; } /** * Specifies whether the state handler being setup or shutdown */ export type StateAction = 'setup' | 'teardown';```

tjones
2022-07-05 01:38
The request is a `ProviderState` object

tjones
2022-07-05 01:38
and pact will tell you if it is a setup or a teardown

tjones
2022-07-05 01:39
you might have problems if you don't check the action to determine whether to setup or teardown

tjones
2022-07-05 01:39
I _think_ V3 allows multiple states

john
2022-07-05 02:02
thanks for the info Timothy

tjones
2022-07-05 02:13
Welcome!

harris
2022-07-05 03:13
some reproducible error here ```#9 175.8 make: Entering directory '/app/node_modules/@pact-foundation/pact-core/build' #9 175.8 CXX(target) Release/obj.target/pact/native/addon.o #9 175.8 CXX(target) Release/obj.target/pact/native/ffi.o #9 175.8 CXX(target) Release/obj.target/pact/native/consumer.o #9 175.8 CXX(target) Release/obj.target/pact/native/provider.o #9 175.8 CXX(target) Release/obj.target/pact/native/plugin.o #9 175.8 SOLINK_MODULE(target) Release/obj.target/pact.node #9 175.8 /usr/bin/ld: skipping incompatible /app/node_modules/@pact-foundation/pact-core/ffi/libpact_ffi.so when searching for -lpact_ffi #9 175.8 /usr/bin/ld: cannot find -lpact_ffi #9 175.8 collect2: error: ld returned 1 exit status #9 175.8 make: *** [http://pact.target.mk:152: Release/obj.target/pact.node] Error 1 #9 175.8 make: Leaving directory '/app/node_modules/@pact-foundation/pact-core/build'```

matt.fellows
2022-07-05 03:29
thanks!

matt.fellows
2022-07-05 03:29
For the last bit of the repro, can you please show the steps you used to run the container?

matt.fellows
2022-07-05 03:30
:taco: for @tjones!

matt.fellows
2022-07-05 03:31
thanks for your help!

harris
2022-07-05 03:32
1. download pact-demo.zip 2. upzip then go do unziped folder 3. run `docker build .` command 4. then you can see this error on your terminal :slightly_smiling_face:

john
2022-07-05 03:33
haha taco time

matt.fellows
2022-07-05 03:34
perfect, thanks

harris
2022-07-05 03:34
thanks Matt !

john
2022-07-05 03:34
I think my team will not use this approach though but instead write their provider tests in JS but use graphql mutation to seed the data into the. db instead. Because no one is comfortable will PHP

matt.fellows
2022-07-05 03:35
> /usr/bin/ld: skipping incompatible /app/node_modules/@pact-foundation/pact-core/ffi/libpact_ffi.so when searching for -lpact_ffi that?s the key line. Are you running on M1 by any chance?

artur
2022-07-05 03:39
running the consumer tests I get `PactffiWithBody(arg 2) expected a string`

harris
2022-07-05 03:41
yeap mine is M1

john
2022-07-05 03:41
my worry with that approach is that your setup phase is using endpoints that maybe are being tested in other contract tests. Do you think my concern is unfounded?

harris
2022-07-05 03:42
but FYI original issue starts from CI docker image lol

matt.fellows
2022-07-05 03:42
right, so it works for me when I run like this `docker build --platform linux/amd64 .`

matt.fellows
2022-07-05 03:43
I suspect your CI problem is different (in fact, the logs look different so I think it is)

matt.fellows
2022-07-05 03:43
The issue with the M1 build, is that it?s trying to use a linux x86_64 shared library (pact_ffi) but the OS architecture is actually linux arm because you?re running it on M1

matt.fellows
2022-07-05 03:44
sorry, you did say that Artur

harris
2022-07-05 03:46
oh yeap it works with paltform lol hum, so it looks like beta version with public docker image build well?.

harris
2022-07-05 03:46
maybe it has an sissue with inhouse image(adding extra library built in)

artur
2022-07-05 03:48
If that supposed to be supported and its a limitation I can try to look into it today, let's see what I find

matt.fellows
2022-07-05 03:48
OK just looked. This is the consumer request content type, right? Any reason you need a matcher there? In any case, the `contentType` property cannot be a matcher (see the type definition). It says ?this is the content type of this request?. It?s an optional field though.

matt.fellows
2022-07-05 03:48
for now, you can do it the way you used to - don?t set `contentType` but set the header `Content-Type` and use the matcher there - that should work as you expect

artur
2022-07-05 03:49
I need a matcher there because different versions of the provider answer differently, but both inside of the specs. e.g. upper/lowercase

matt.fellows
2022-07-05 03:49
In your example above it?s the consumer, but I assume you want the provider also? If so, same deal.

artur
2022-07-05 03:50
`'text/xml; charset=utf-8'` is valid but also ```'application/xml; charset=UTF-8'```

matt.fellows
2022-07-05 03:50
e.g. this sort of thing ``` withResponse: { headers: { "Content-Type": MatchersV3.regex('text/plain(;()?charset=(utf|UTF)-8)?', 'text/plain; charset=utf-8') }, },```

artur
2022-07-05 03:51
yes finally its about the provider Thanks I will try that

matt.fellows
2022-07-05 03:51
yep, we do support it - just omit `contentType` all together and use the standard header matching

matt.fellows
2022-07-05 03:51
I?m tempted to remove the `contentType` definition altogether. We can derive it by other means (extract from headers) and default to JSON otherwise.

matt.fellows
2022-07-05 03:51
what do you think?

matt.fellows
2022-07-05 03:52
if you can help repro that, it would be ideal

matt.fellows
2022-07-05 03:53
I?ll update beta docs with the note about M1 above. I think there was a discussion about building for linux/arm but that it was fraught with issues

tjones
2022-07-05 03:53
Personally I'm not terribly worried about a contract break that happens to break other tests- you?ll still detect the problem. (Pact will tell you if its state change fails)

artur
2022-07-05 03:53
yes, why not. at the end of the day its just a header like any other

tjones
2022-07-05 03:54
Oh! Pact V3 is supposed to understand the content type anyway

tjones
2022-07-05 03:54
You can just say it's application/json and it should work even if there's a charset given by the actual code

tjones
2022-07-05 03:54
At least, according to the spec

harris
2022-07-05 03:55
yeap I will keep try to run same ci setup to my local to generate same message ! let you know

tjones
2022-07-05 03:55
Matchers are still supposed to work in headers, so there's still a bug

tjones
2022-07-05 03:55
But, if you only need this for content type, just omit the charset and it is supposed to work

matt.fellows
2022-07-05 03:56
> Matchers are still supposed to work in headers, so there?s still a bug Artur wasn?t using it on the _headers_ but an optional `contentType` field on the response object. That doesn?t take a matcher, but the exact content type of the request / response

artur
2022-07-05 03:56
also with xml?

matt.fellows
2022-07-05 03:56
it should, yes

artur
2022-07-05 04:06
works fine with putting the content-type only in the header. I cannot remember why I started to use the `contentType` parameter maybe it was because of this issue https://github.com/pact-foundation/pact-js/issues/575

matt.fellows
2022-07-05 04:19
might have been! I?m still a little hazy on what should be explicitly set by the user in a pact test (via something like `contentType` - not the header), implicitly via content sniffing in the core, or via the usual header match.

matt.fellows
2022-07-05 04:19
My sense is to use headers, and to not add additional overhead via `contentType`

artur
2022-07-05 04:26
here the next issue, maybe related I have this interaction in the JSON file ```"description": "as 'admin', a POST request to create a user", "request": { "body": "password=1234&userid=testUser1", "headers": { "Content-Type": "application/x-www-form-urlencoded", "authorization": "Basic YWRtaW46YWRtaW4=" }, ......``` with .59 it sends me the data as expected with .60 it converts the body to a JSON string (see wireshark screenshot)

john
2022-07-05 04:37
ok thats good to know I though that is kind of an anti pattern to use the endpoint your testing to set up state

harris
2022-07-05 05:14
I got it, so what I did 1. download pact-demo.zip 2. upzip then go do unziped folder 3. run `docker build --platform linux/amd64 -t test-pact-beta .` 4. after build image, run `docker run test-pact-beta`

harris
2022-07-05 05:14
```/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.29' not found (required by /app/node_modules/@pact-foundation/pact-core/build/Release/libpact_ffi.so) at Runtime._loadModule (node_modules/jest-runtime/build/index.js:893:29) at bindings (node_modules/bindings/bindings.js:112:48) at Object.<anonymous> (node_modules/@pact-foundation/pact-core/src/ffi/index.ts:6:21)```

harris
2022-07-05 05:14
exact same error from CI

harris
2022-07-05 06:15
another additional info `node:18-slim` it does not cause error lol so only node 14, and 16

omri.eyal
2022-07-05 06:22
has joined #pact-js

shen-yu
2022-07-05 15:35
has joined #pact-js

ben.foster
2022-07-05 15:42
has joined #pact-js

maarten.gryp
2022-07-05 16:20
has joined #pact-js

john
2022-07-05 23:59
so just a quick question, this beta 3 version "fromProviderState" is the only platform that is available on is JS?

uglyog
2022-07-06 00:09
It is also available for JVM

john
2022-07-06 00:27
ah thanks uglyog good to know my next try out of this(pact) will be with rust i think

uglyog
2022-07-06 00:31
With Rust, you can use the verifier CLI, but it will need to have the provider state handlers deployed with a HTTP proxy server.

john
2022-07-06 00:33
cool ill have to give that a go. i dont think ive used the verifier CLI before

john
2022-07-06 00:33
ive only used pact with python and js

megha.t
2022-07-06 06:56
has joined #pact-js

ravindra.dhaka
2022-07-06 07:08
has joined #pact-js

mrigendra.ranjan
2022-07-06 07:08
has joined #pact-js

deepak.bhoria
2022-07-06 07:11
has joined #pact-js

cjenkins
2022-07-06 07:17
has joined #pact-js

cjenkins
2022-07-06 07:19
Hey everyone! I just encountered this error with the most recent version (4 hours ago) of pact-node 10.17.5: ```$ yarn add @pact-foundation/pact-node@10.17.5 yarn add v1.22.19 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... [4/4] Building fresh packages... error /tmp/tmp.CovE6vLZ5q/node_modules/@pact-foundation/pact-node: Command failed. Exit code: 1 Command: node postinstall.js Arguments: Directory: /tmp/tmp.CovE6vLZ5q/node_modules/@pact-foundation/pact-node Output: Installing Pact Standalone Binary for linux. Downloading Pact Standalone Binary v1.89.02-rc1 for platform linux from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.89.02-rc1/pact-1.89.02-rc1-linux-x86_64.tar.gz Please note: we are tracking this download anonymously to gather important usage statistics. To disable tracking, set 'pact_do_not_track: true' in your package.json 'config' section. Downloaded 26.57%... Downloaded 84.62%... Finished downloading binary to /tmp/tmp.CovE6vLZ5q/node_modules/@pact-foundation/pact-node/standalone/pact-1.89.02-rc1-linux-x86_64.tar.gz Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error: Error while installing binary: Checksum file missing from standalone directory. Aborting. at throwError (/tmp/tmp.CovE6vLZ5q/node_modules/@pact-foundation/pact-node/standalone/install.js:42:11) at /tmp/tmp.CovE6vLZ5q/node_modules/@pact-foundation/pact-node/standalone/install.js:327:16 at processTicksAndRejections (internal/process/task_queues.js:95:5) info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.```

cjenkins
2022-07-06 07:20
`yarn add @pact-foundation/pact-node@10.17.4` one patch before that:point_up: runs without issues

abubics
2022-07-06 07:23
Might be good to know what hardware you're running on, in case it's a xcompiled arch problem

cjenkins
2022-07-06 07:24
ah, yes I am running on Linux Mint with processor arch x86_64

abubics
2022-07-06 07:24
so, not M1, then :yay:

cjenkins
2022-07-06 07:25
nope


cjenkins
2022-07-06 07:25
so maybe that tarball is missing a checksum file

cjenkins
2022-07-06 07:25
or the checksum for the tarball is missing

abubics
2022-07-06 07:25
yeah, `rc1-linux-x86_64.tar.gz` should've been a giveaway, hiding in the middle there :upside_down_face:

abubics
2022-07-06 07:26
If you don't get any answers here in a while, maybe check #pact-js-development ig

cjenkins
2022-07-06 07:28
I see the checksum in there, I wonder what's going on...

gustavo.chain
2022-07-06 08:04
has joined #pact-js

tobias.friedrich
2022-07-06 08:31
has joined #pact-js

yousafn
2022-07-06 10:37
Hmm yeah something funny is going down. Looks like pact-js `npm install @pact-foundation/pact@9.17.3` fails `npm install @pact-foundation/pact@9.17.2` passed Release 9.17.3 https://github.com/pact-foundation/pact-js/releases/tag/v9.17.3 ? brings in an update to upgrade to latest pact-node (https://github.com/pact-foundation/pact-js/commit/0d9b1270d4dc03e761941ae060b2a75db0bab24d) https://github.com/pact-foundation/pact-js/commit/0d9b1270d4dc03e761941ae060b2a75db0bab24d#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R97 `"@pact-foundation/pact-node": "^10.17.2",` `pact-js-core` released https://github.com/pact-foundation/pact-js-core/releases/tag/v13.6.2 which is on npm as ? pact-core - https://www.npmjs.com/package/@pact-foundation/pact-core ? pact-node - https://www.npmjs.com/package/@pact-foundation/pact-node which pact-js uses, the latest release is 10.17.5 so will be picked up by the caret in the pact-node dep in pact-js. Looking at the changes in https://github.com/pact-foundation/pact-ruby-standalone/commits/master the latest release brought in an addition of some azure env vars from this https://github.com/pact-foundation/pact_broker-client/issues/113 https://github.com/pact-foundation/pact_broker-client/commit/889f83f3d24dfa4db2824a0049e11ec97a391ab2 so pretty innocuous.

yousafn
2022-07-06 10:37
Thanks for raising this @cjenkins - We will take a look today and try and resolve as soon as possible

yousafn
2022-07-06 10:39
Thank you as well @abubics! :yellow_heart:

billal.patel
2022-07-06 10:44
Hello. I?m not sure if this is the correct channel but when running the verify job, I am getting this error: `No pacts were found for the consumer versions selected` - This is totally fine however, the job still passes. Is there a way to make it fail in such cases? Once again, apologies if this is in the wrong place :slightly_smiling_face:

matt.fellows
2022-07-06 11:44
sorry folks, this is fixed now. My guess is that a manual step in https://github.com/pact-foundation/pact-js-core/blob/master/RELEASING.md#releasing-pact-node-manually release process (`pact-node`) failed and somebody (me) didn?t notice. We should be back to an automated release process soon - the beta branch is very close to being stable with support for all major features (and some), and I hope to release that in about 2 weeks. This week it?s getting a green build, next week I?m away in the states, and the week after is tidy up, docs, socialising and working with Yousaf and co (assuming all is well, of course).

yousafn
2022-07-06 11:48
Working for me now buddy :hooray: thanks Matt for taking the time this evening and enjoy a nice :whiskey: after that. Looking forward to catching up in person, helping iron out the kinks over the upcoming months and getting a proper smooth Pact release train, so that we can all kick back and relax like Paxton:pactflow-platypus-slack:

ganesh.panchagnula-no
2022-07-06 11:50
has joined #pact-js

matt.fellows
2022-07-06 12:25
Can?t wait for next week!

morten.gejl
2022-07-06 13:02
has joined #pact-js

varunthaper
2022-07-06 15:17
has joined #pact-js

jwheatley
2022-07-06 17:12
has joined #pact-js

noor.hashem
2022-07-06 20:23
has joined #pact-js

tjones
2022-07-07 00:24
Those instructions are not right

tjones
2022-07-07 00:25
This is probably my fault, as I never documented the release process before I left. Sorry

tjones
2022-07-07 00:27
Although, maybe you're right - following the instructions wouldn't have caused this specific problem. The instructions need (at least): delete all previous checksums and downloads

harris
2022-07-07 04:18
sorry somehow, I cannot make anymore thread comment to original post lol has anyone have idea? `GLIBC_2.25` version complaints from `node-14,16:slim` docker image for pact `v3 beta`?

cjenkins
2022-07-07 06:04
Thanks for this everyone, it's working for me now :thumbsup:

matt.fellows
2022-07-07 06:42
Could you please raise a Pact JS issue for this Harris? This will help create visibility of the issue to a wider audience, and give us a place to track activity against it

matt.fellows
2022-07-07 06:42
Thanks for your digging so far, it?s much appreciated

cjenkins
2022-07-07 07:38
Hey again all, sorry for another end-of-day issue (and sorry for not providing more detail with it) but something is not quite right with `@pact-foundation/pact` version `9.18.1`. My provider tests are failing because the incoming request body is being mangled. Rather then sending through this: ```{ "foo": "bar" }``` it's sending through this: ```{ "{\"foo\":\"bar\"}": "" }``` This happens in `9.18.1` but not `9.17.3`. I have to stop for the day but I can provide more details on this tomorrow (including pacts and more detail on what versions are affected). I thought at least posting this might jog someone's memory about something

dormeiri
2022-07-07 09:41
has joined #pact-js

matt.fellows
2022-07-07 10:02
Thanks Cody. this, is strange indeed. I?ll check out the diff to see what could be different, but we have regression tests in both Pact JS and in the core that would include this in at least ?normal? situations. So I wonder if there is an edge case we?re running into here

matt.fellows
2022-07-07 10:02
I?ll take a look after this call

andreaschung1
2022-07-07 12:28
has joined #pact-js

matt.fellows
2022-07-07 13:34
This PR is the most likely candidate in the Pact JS side of things: https://github.com/pact-foundation/pact-js/pull/875/files

matt.fellows
2022-07-07 13:35
There is a middleware that listens to all provider requests, with the primary purpose of providing provider state middleware, and also ?request filters? (the ability to modify requests prior to verification for certain cases)(

matt.fellows
2022-07-07 13:36
This PR added ability to modify the bodies, which includes consuming the incoming body, storing it aside, and then rehydrating it back in as if nothing happens. It certainly has the smell. This being said, there are integration tests that cover provider verification and request filters, so I would have thought that case would be picked up

prasadsolanki
2022-07-07 16:07
Hello All, I am trying to write an interaction where I need to provide custom headers. But this doesn't seem to be working. Am I doing something wrong here?

abudi.hijazi.01
2022-07-07 16:19
Quick q: Are there any ways you can add objects in the pact file?

abudi.hijazi.01
2022-07-07 16:19
If I wanted to add another object, without actually writing it in manually, would I be able to do it in the spec file

parvatshiva
2022-07-07 22:05
has joined #pact-js

harris
2022-07-07 22:22
Ok will do thanks!


matt.fellows
2022-07-07 23:05
why do you want to do that? You could, but then you run the risk that what?s in the pact file is not what your code actually does

matt.fellows
2022-07-07 23:06
also, the next time you run your pact tests, they could be overwritten

matt.fellows
2022-07-07 23:06
You?re saying to Pact ?I expect my test to make a call to the mock server with these headers? but it?s failing, because you are not making a request that has those headers and it?s not a multi part form request

prasadsolanki
2022-07-07 23:41
Agree. My bad. Solved this error . Thanks a lot! But now I am unable to make multipart request from Pact. I am doing this but it doesn't work

prasadsolanki
2022-07-07 23:44
I have tested my mock service and it works fine. It uploads the file using formdata. But when I replicate the request in Pact interaction it throws error. Here is my mock service

cjenkins
2022-07-07 23:47
hey @matt.fellows thanks for having a look, I just got settled at my desk. What are some pieces of information that would be helpful to get to the bottom of this? I imagine: ? Specific version where the break happens ? Pact file which is being used by the provider ? Sample HTTP requests from the pact verifier?

abudi.hijazi.01
2022-07-08 08:48
I want to version my pact files

abudi.hijazi.01
2022-07-08 08:48
What would you recommend is the best way to go about that

prasadsolanki
2022-07-08 09:08
Hello All, Anyone has example of writing interaction for mulitpart/form-data upload?

jonathan.dowling
2022-07-08 11:37
has joined #pact-js

matt.fellows
2022-07-08 11:46
The pact broker does this

matt.fellows
2022-07-08 11:46
There is a whole guide on versioning at http://docs.pact.io, I'd definitely recommend starting there!

matt.fellows
2022-07-08 11:47
I think there's an example in the pact JS repo. If not masters definitely in the be branch

alex423
2022-07-08 13:59
has joined #pact-js

alex423
2022-07-08 14:23
Hello All, I'm trying the sample of https://github.com/pactflow/example-bi-directional-consumer-mountebank on windows 10. It run fines, but the pact file produce by the test does not contains any interactions in it, and eventually the publish scripts submit a blank contract on the pact-broker ```{ "consumer": { "name": "pactflow-example-bi-directional-consumer-mountebank" }, "provider": { "name": "pactflow-example-bi-directional-provider-dredd" }, "interactions": [], "metadata": { "pactSpecification": { "version": "2.0.0" } } }``` Do you know how to fix ? :slightly_smiling_face:

alex423
2022-07-08 14:26
also I tried to debug the `mountebankSerialiser.js` and `imposter.matches` contained in `imposter.stubs` are undefined

prasadsolanki
2022-07-08 15:06
Sorry, I tried to find one but couldn't

francis.williams
2022-07-08 19:52
has joined #pact-js

dmitry.sarkisov
2022-07-08 20:07
has joined #pact-js

jbecker
2022-07-08 21:01
Hey! Sorry if this is a somewhat novice question, but I'm very new to JS/TS and trying to help another team out: We are using axios to perform REST requests in our client classes, and the base_url is populated via an import from another module that handles environment variables (as constants). So what's the best way to change the base_url to point at the pact mock server?

neokree
2022-07-09 10:50
has joined #pact-js

tjones
2022-07-10 03:58
Depends on your test library. With jest you can mock the import. See the jest docs for more

lynn.alhaimy
2022-07-10 18:20
has joined #pact-js

matt.fellows
2022-07-10 21:25
Hey Cody, apologies have been traveling to the states. I should get a good wifi this week to look into it.

matt.fellows
2022-07-10 21:26
Example pact file is all I should need. You've provided the version already. It shouldn't be hard to repro from there.

matt.fellows
2022-07-10 21:26
If you could please raise an issue on the GH repo for pact JS that would be great

cjenkins
2022-07-10 21:51
Will do, thanks Matt!

cjenkins
2022-07-11 00:02
I created this issue for the situation I am experiencing: https://github.com/pact-foundation/pact-js-core/issues/383

harris
2022-07-11 02:08
Hello quick question about `stateHandler` , we will use real provider side API to generate data, however, when stateHandler is failed, it does not execute the other tests, what is good practice workaround in here? for example, some verifier from provider side doesnt need stateHandler, if state handler somehow error/fail, shall we execute rest of them? any good tip for jest setup for provider? we use `jest-each` to loop all contract in provider side. ```each(needToBeVerified).it('should verify the expectations of %p Graphql', contractName => { return new Verifier(createOptions(`${contractName}-provider`)).verifyProvider().then(output => { if (output.includes('Diff')) { console.log(output) throw new Error(`${contractName} contract test error`) } })```

tjones
2022-07-11 06:18
I'm a bit confused here - what does the `createOptions` function do? If the state handler fails, Pact assumes that the test is a failure, because the state was not correctly setup.

tjones
2022-07-11 06:19
it should execute the contracts where the failing state handler is not used successfully.

tjones
2022-07-11 06:20
Also, I don't think this is a good check `if (output.includes('Diff')) {` - Diff happens to be in the output of a failed test, but it's not part of the contract

tjones
2022-07-11 06:21
`each(needToBeVerified).it(` <-- I'm not familiar with this construct - the one that is in the jest docs is `it.each(table)(name,fn,timeout?)`

tjones
2022-07-11 06:22
that might not be a problem (jest contains lots of things that aren't documented exactly)

abudi.hijazi.01
2022-07-11 09:07
Hey I've read the linked docs, the pact broker seems to be doing the versioning for you, only thing is, I'm using my own pact broker so I need to do my own versioning.

abudi.hijazi.01
2022-07-11 09:07
The only way I can think of to version the files, is to change the names of the consumers or providers in the pact file to their respective versions. That way the file is named with the versions

jbecker
2022-07-11 12:22
Okay thanks! We are in fact using Jest, so it sounds like I just need to dive into Jest a bit more

eirikval
2022-07-11 15:08
has joined #pact-js

alex423
2022-07-11 15:12
I tried the same code on a unix environment and it works as expected, but I need to make it works on windows

harris
2022-07-11 22:42
`createOptions` is just verifier config, such as ``` { provider: providerName, providerBaseUrl: , pactBrokerUrl: } ```

harris
2022-07-11 22:42
> Diff happens to be in the output of a failed test, but it?s not part of the contract OK that is good to know thanks! I will add failure

harris
2022-07-11 22:43
and `each` is `jest-each` library https://www.npmjs.com/package/jest-each :slightly_smiling_face:

harris
2022-07-11 22:44
> it should execute the contracts where the failing state handler is not used successfully. yeap that is what I expected lol, I will try different way! thanks a lot.


matt.fellows
2022-07-12 03:35
you don?t version the _pact files._ The Pact Broker (which you are running) does this

matt.fellows
2022-07-12 03:35
you version the applications (consumer or provider)

matt.fellows
2022-07-12 03:35
> Users of Pact never need to worry about pact contract versions, since this is done automatically by the pact broker. However, consumer and provider application numbers need to be set in a principled way, even in pre-production.

sahil.jain
2022-07-12 10:21
has joined #pact-js

kyriacos.elia
2022-07-12 15:43
has joined #pact-js

fabricio.mendes.ti
2022-07-12 16:33
has joined #pact-js

cameron.allan853
2022-07-12 23:18
has joined #pact-js

harris
2022-07-13 01:44
Hello , for pact-js `v3` config, ```publishVerificationResult: true``` it seems even we set `false` it always pushed to the pactflow(broker) is that known issue? or only me lol ?

harris
2022-07-13 01:46
v2 work as expected

matt.fellows
2022-07-13 02:51
It should respect the flag, but if not, Can you please raise a bug?

harris
2022-07-13 03:02
Ok I will raise bug Matt

jeroen.lamain
2022-07-13 08:49
has joined #pact-js

programmingwithbangal
2022-07-13 12:48
has joined #pact-js

rohitkeshwani07
2022-07-13 13:28
has joined #pact-js

ravindra.dhaka
2022-07-13 15:50
Hi All, did anyone integrated the pact-js in gitlab/github ci/cd pipeline (node project)??

noor.hashem
2022-07-13 17:39
Hi All, i'm new here to pact and am very excited to get using it!! I am curious however about authentication. I have already created a contract from a react consumer side and published the contract to pactflow. I am now on the provider side (Nest JS) and need to confirm that the provider can provide what is in the contract. The exact Interaction is simply getting a users information, but the user needs to be logged in for us to get the information. So how would I be able to have pact authenticate so that it can reach the endpoint on the provider side and confirm the contract is good? Please let me know if you would like me to provide any additional information.

gjvengelen
2022-07-13 18:18
has joined #pact-js

tjones
2022-07-14 01:36
Yes, pact will work with any CI / CD process. See the examples in the pact-js repo on github.

ravindra.dhaka
2022-07-14 02:59
@tjones can you share your stage code .


matt.fellows
2022-07-14 03:16
There is also an e2e example project in the repo that shows how you can deal with auth

matt.fellows
2022-07-14 03:16
also the JS workshop :point_down: (howtolearn)

2022-07-14 03:16
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

tjones
2022-07-14 03:29
There are examples in the pact-js repo on github

ravindra.dhaka
2022-07-14 03:30
i follow those step but still giving ```err Error: /builds/panamera/fcg/service/auction/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.89.02-rc1/pact/lib/ruby/bin/ruby: line 6: /builds/panamera/fcg/service/auction/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.89.02-rc1/pact/lib/ruby/bin.real/ruby: No such file or directory at ChildProcess.<anonymous> (/builds/panamera/fcg/service/auction/node_modules/@pact-foundation/pact-node/src/verifier.js:187:64) at Object.onceWrapper (events.js:520:26) at ChildProcess.emit (events.js:412:35) at ChildProcess.emit (domain.js:470:12) at maybeClose (internal/child_process.js:1055:16) at Socket.<anonymous> (internal/child_process.js:441:11) at Socket.emit (events.js:400:28) at Socket.emit (domain.js:470:12) at Pipe.<anonymous> (net.js:675:12) at Pipe.callbackTrampoline (internal/async_hooks.js:131:17) ? validates the expectations of Dealer-Service (89ms) 1 passing (236ms) Uploading artifacts for successful job```

ravindra.dhaka
2022-07-14 03:30
@tjones

ravindra.dhaka
2022-07-14 03:32
@tjones i am using image : node:14.17-alpine in gitlab stage


tjones
2022-07-14 03:32
``` you'll need to ensure the following dependencies are met: Bash (it's not enough to have Ash) Standard CAs for TLS network communication glibc```

tjones
2022-07-14 03:33
Looks like your issue is because bash is missing

ravindra.dhaka
2022-07-14 03:34
can we connect so that easily understand the issue ?i am struggling last 10 days?

tjones
2022-07-14 03:35
I'm sorry, I'm a volunteer, and have limited time. Your issue is because alpine linux does not come with bash. You will need to install bash in your image. See the reference image at the bottom of that page I linked

ravindra.dhaka
2022-07-14 03:35
@tjones need to use `runPactTests:` `image: pactfoundation/pact-cli:latest` `stage: pacts-tests` `services:`

ravindra.dhaka
2022-07-14 03:35
image for gitlab stage?

tjones
2022-07-14 03:35
In the alpine linux image

tjones
2022-07-14 03:35
gitlab is unrelated

ravindra.dhaka
2022-07-14 03:36
got it but this docker file i am using ```FROM node:8-alpine RUN apk add --no-cache --virtual build-dependencies build-base RUN apk --no-cache add ca-certificates wget bash \ && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \ && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk \ && apk add glibc-2.29-r0.apk WORKDIR /app COPY package*.json /app/ RUN npm install COPY . /app/ RUN npm test```

ravindra.dhaka
2022-07-14 03:38
@tjones i am using node 14.17 but in documentation mention node:8-alpine

tjones
2022-07-14 03:38
```RUN npm install COPY . /app/``` This might need to be in the other order

tjones
2022-07-14 03:38
npm install will install the relevant binaries for pact-js, but possibly the copy command is clobbering them

ravindra.dhaka
2022-07-14 03:39
can you check this

tjones
2022-07-14 03:40
Sorry, I can't check your production dockerfile - even if I could, I can't build that without access to the images.

tjones
2022-07-14 03:41
But I don't think that's the dockerfile where your error is coming from.

tjones
2022-07-14 03:41
The error you have is typically because bash is not installed on the image it is running on.

tjones
2022-07-14 03:41
That's all I can tell you, sorry.

ravindra.dhaka
2022-07-14 03:42
i m adding `SHELL ["/bin/bash", "-c"]` in my DockerFile

ravindra.dhaka
2022-07-14 03:42
is it correct?

tjones
2022-07-14 03:43
No. See the documentation I linked above.

lorenz.ammon
2022-07-14 08:52
has joined #pact-js

remigijus.mazulis
2022-07-14 08:53
has joined #pact-js

noor.hashem
2022-07-14 14:24
Thank you! They have helped a bit still reading into them :slightly_smiling_face:

seanruffatti
2022-07-14 14:40
has joined #pact-js

nico.neirinck
2022-07-15 06:10
has joined #pact-js

k.bangarusamy
2022-07-15 14:36
has joined #pact-js

harinder.kaur
2022-07-15 17:19
has joined #pact-js

mahidasp
2022-07-16 17:30
has joined #pact-js

juan.aa.espiritu
2022-07-17 08:39
has joined #pact-js

thomas.loudon
2022-07-18 11:05
has joined #pact-js

david.hayden
2022-07-18 11:12
has joined #pact-js

hakan.b.jansson
2022-07-18 14:04
has joined #pact-js

jakehowden
2022-07-18 15:54
has joined #pact-js

chrstnklb
2022-07-19 10:58
has joined #pact-js

marcello.rigan335
2022-07-19 13:33
Hello while running tests in our git pipeline i ran into this "[2022-07-19 12:12:19.353 +0000] INFO (579 on runner-9srzqayz-project-119-concurrent-2): pact@9.18.1: Setting up Pact with Consumer "BBX" and Provider "INT" https://gitlab.willhaben.at/willhaben/chapter/frontend/barbarix/-/jobs/623065#L134 using mock service on Port: "2134" https://gitlab.willhaben.at/willhaben/chapter/frontend/barbarix/-/jobs/623065#L135[2022-07-19 12:12:19.357 +0000] ERROR (579 on runner-9srzqayz-project-119-concurrent-2): pact@9.18.1: error making http request: axios_1.default is not a function"

matt.fellows
2022-07-19 13:58
Could you please share the code that reproduces this?

andrew.favaloro
2022-07-19 19:36
has joined #pact-js

tarun.gulati1988
2022-07-19 19:41
has joined #pact-js

boweixu
2022-07-19 20:39
has joined #pact-js

harris
2022-07-20 00:32
has anyone had an issue with JS memory issue? with `pact v3 node 18 slim` container? It kept getting memory issue from 2gb so I had bumped up to 4gb, but still get some issues. I did not face any issue with `pact v2 with node 14 slim` from 2gb memory, all tests are running passed but getting memory error ``` <--- JS stacktrace ---> FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 0xb65a10 node::Abort() [/usr/local/bin/node] 2: 0xa761b5 node::FatalError(char const*, char const*) [/usr/local/bin/node] 3: 0xd5713e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node] 4: 0xd574b7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node] 5: 0xf34545 [/usr/local/bin/node] 6: 0xf35448 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node] 7: 0xf45953 [/usr/local/bin/node] 8: 0xf467c8 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node] 9: 0xf2112e v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node] 10: 0xf224f7 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node] 11: 0xf02a40 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node] 12: 0xefa4b4 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [/usr/local/bin/node] 13: 0xefc768 v8::internal::FactoryBase<v8::internal::Factory>::NewRawOneByteString(int, v8::internal::AllocationType) [/usr/local/bin/node] 14: 0xf05d2d v8::internal::Factory::NewStringFromUtf8(v8::base::Vector<char const> const&, v8::internal::AllocationType) [/usr/local/bin/node] 15: 0xd661a3 v8::String::NewFromUtf8(v8::Isolate*, char const*, v8::NewStringType, int) [/usr/local/bin/node] 16: 0xbba616 v8::MaybeLocal<v8::Value> node::ToV8Value<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(v8::Local<v8::Context>, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, v8::Isolate*) [/usr/local/bin/node] 17: 0xc0f4b5 [/usr/local/bin/node] 18: 0xc1597a [/usr/local/bin/node] 19: 0x167e06f [/usr/local/bin/node] Aborted (core dumped)``` so I bumped up memory to 4gb but it still sometimes got error ``` spawn ENOMEM at spawn (node_modules/cross-spawn/index.js:12:24) at Spawn.Object.<anonymous>.Spawn.spawnBinary (node_modules/@pact-foundation/pact-core/src/spawn/spawn.ts:46:22) at Server.Object.<anonymous>.AbstractService.spawnBinary (node_modules/@pact-foundation/pact-core/src/service.ts:245:18) at Server.Object.<anonymous>.AbstractService.start (node_modules/@pact-foundation/pact-core/src/service.ts:165:28) at node_modules/@pact-foundation/src/httpPact/index.ts:277:19 at Pact.Object.<anonymous>.Pact.startServer (node_modules/@pact-foundation/src/httpPact/index.ts:276:12) at node_modules/@pact-foundation/src/httpPact/index.ts:94:24``` ``` The pact mock service wasn't running when verify was called at Pact.Object.<anonymous>.Pact.verify (node_modules/@pact-foundation/src/httpPact/index.ts:145:9) at Object.<anonymous> (node_modules/jest-pact/index.js:26:45)``` anyone had same issue?

tjones
2022-07-20 01:28
I haven't. Could it be something else taking up the memory during the test, and it just happens that the failure happens during pact's spawn?

harris
2022-07-20 01:29
yeap, not always happening though but most of the time I would say 70~80%

tjones
2022-07-20 01:30
I would profile your app and see where the memory is going

harris
2022-07-20 01:30
ok I will try, but weird thing is when I use v2 with node 14 I have never had an issue

tjones
2022-07-20 01:31
(If it is pact, we're very sorry)

harris
2022-07-20 01:31
same docker file just node version and pact version changed lol

harris
2022-07-20 01:31
dont need to sorry haha , just want to check if someone has same issue lol we really want to use providerstate from v3 that is why

harris
2022-07-20 01:32
btw any tips to get profile memory leak info?

tjones
2022-07-20 03:48
You can run node in debugging mode and attach a profiler

tjones
2022-07-20 03:49
I would be surprised if there is a memory leak in pact that is sufficient to cause this problem. I would guess it is something in your test setup or code under test (or possibly a bug in node).

harris
2022-07-20 05:05
yeap Timothy, I am testing v2 with differ node version? lol it is really deal breaker for me now. what is the best way to achieve `providerState` in v2?? any suggestion example?

tjones
2022-07-20 05:09
Wait, are you saying you're using the beta? A memory leak is much more possible in the beta, but the stack trace you posted doesn't look like the beta.

tjones
2022-07-20 05:10
For examples of provider state, have a look in the pact-js examples folder in the pact-js repo on GitHub

harris
2022-07-20 05:10
yeap memory leaks from beta lol it is only works in node 18 , https://github.com/pact-foundation/pact-js/issues/888

harris
2022-07-20 05:14
the reason I want to use v3 beta is, all of ID is randomly generate it from provider, but v2 https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js looks like consumer already know id will be `1`

tjones
2022-07-20 05:17
If the result of your profiling says this is pact, please open an issue. It will be important to fix

tjones
2022-07-20 05:17
As far as I am aware, this is the first time such an issue has been reported though

harris
2022-07-20 05:18
yeap , I wonder how others use v3, it seems only works in node18 slim lol

juanalvarezarquillos
2022-07-20 05:46
has joined #pact-js

harris
2022-07-20 05:54
okay, even v2 I got memory issue with node18-slim so I can say it is node issue lol

jkaur
2022-07-20 06:32
has joined #pact-js

marcello.rigan335
2022-07-20 07:20
alright will do.

marcello.rigan335
2022-07-20 08:10
Hi, im afraid im having troubles sharing my code due to restrictions on our side. I can confirm that it has something to do with the pact version. Pact Version 9.17.3 works fine locally and in the Pipeline. But Pact Version 9.18.1 doesn't seem to work locally and in the Pipeline.

tjones
2022-07-20 09:06
it might not be node, it could be your code, or pact (but I don't think it is pact)

steve.heasman
2022-07-20 09:08
has joined #pact-js

je.alvinez
2022-07-20 11:17
has joined #pact-js

matkruse
2022-07-20 14:53
has joined #pact-js

2billy
2022-07-20 16:56
has joined #pact-js

jbecker
2022-07-20 19:41
Sorry, this is probably a super basic question, but I cannot figure out how to get Matchers to work with my typescript consumer contract test. I have a contract test that is working, but I'm manually setting a UUID which the provider will generate, so I need the contract to accept any valid UUID. But when I change the element in my expected body from ```id: "ce118b6e-d8e1-11e7-9296-cec278b6b50a"``` to ```id: Matchers.uuid("ce118b6e-d8e1-11e7-9296-cec278b6b50a")``` I am now getting: ``` Object { - "id": Object { - "data": Object { - "generate": "ce118b6e-d8e1-11e7-9296-cec278b6b50a", - "matcher": Object { - "json_class": "Regexp", - "o": 0, - "s": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$", - }, - }, - "getValue": [Function getValue], - "json_class": "Pact::Term", - }, + "id": "ce118b6e-d8e1-11e7-9296-cec278b6b50a", } > 92 | expect(response).toEqual(responseData) | ^``` This is all inside a `pactWith` block, because this is using the jest-pact library.

jbecker
2022-07-20 20:01
Like, it looks like pact simply isn't interpreting the matcher as a matcher and it's just comparing the matcher object to the uuid, which of course doesn't match because they're completely different types

jbecker
2022-07-20 20:20
Oh, I'm a dummy... I bet I can't use the matcher in my expected response, huh?

mike.key
2022-07-20 21:03
Apologize if this isn't the right channel, just picked one of the 2 in play....I am having an issue between a consumer using pact-js:0.9.4 and a provider using junit5spring:4.3.7 where the verification is failing saying: ```Header: Content-Type: Expected a header 'Content-Type' but was missing Body: Expected a response type of 'application/json' but the actual type was 'null'``` I have verified that the header is in the contract on the consumer, and that the provider *is* producing a content-type...any insight what might be going on here?

matt.fellows
2022-07-20 22:18
Are you sure that's the right version of JS client? Strange though. If you could share debug logs of the JVM run and ideally the pact file (redacted as necessary) that'd help

matt.fellows
2022-07-20 22:18
Hmm no that doesn't look like your fault. You can use marchers in most places. Ive seen it before where that happens but we've never been able to track it down reliably. I think removing the pact file and running again might help

harris
2022-07-20 22:32
I did not get profile but I am doing middle of conversion v2 to v3, and pact was v3 when I tried to run v2 and v3 altogether in jest-pact, it got memory issue, but when I run only v3 it has no issue, I assume maybe v2 v3 combination issue ?

harris
2022-07-20 22:32
buy anyway it seems all good now :slightly_smiling_face:

tjones
2022-07-20 22:33
There should be no problem combining the two.

tjones
2022-07-20 22:33
If it's a memory issue, we?ll need the profiling to look into it

harris
2022-07-20 22:38
yeap I will have try profiling later, and let you know

tjones
2022-07-20 23:14
> I bet I can't use the matcher in my expected response, huh? This is where you're supposed to use them

tjones
2022-07-20 23:16
Can you share your whole test? You might be passing the matcher to the `expect` call, and you're not supposed to do that

tjones
2022-07-20 23:16
The matcher is for pact. You use jest's `expect` to verify that the object you got out of the API call is correct - so it won't have matchers

tjones
2022-07-20 23:18
If your `responseData` object has the matchers, you can remove them with `extractPayload(responseData)` - so you would do: ```expect(response).toEqual(extractPayload(responseData))```

mike.key
2022-07-21 03:09
Thanks Matt, I?ll share more in the morning my time as I?m not on a work computer at the moment?the under-documented question was in hopes this was a simple oversight on our part

matt.fellows
2022-07-21 07:58
no probs! It might well be, or it could be a bug (hopefully not :wink: )

matt.fellows
2022-07-21 08:01
We don?t need to see your code, just code that reliably reproduces the problem

matt.fellows
2022-07-21 08:02
If you can whittle down a test that breaks, and then transpose into a dummy project with just the bits that cause the failure, that would be :ok_hand:

christopher.forbes
2022-07-21 09:27
has joined #pact-js

jbecker
2022-07-21 12:58
I should have followed up, this was exactly what I was doing. I was trying to use the same response data object in my pact mock response as in my jest `toEqual` expectation. Making separate objects for the two of them fixed it. I didn't know about `extractPayload` though, that's a really handy tip! Thank you

jbecker
2022-07-21 13:25
is `extractPayload` documented anywhere?

sandy.oberoi
2022-07-21 18:57
has joined #pact-js

adelamarre
2022-07-21 19:37
has joined #pact-js

harris
2022-07-21 23:48
I found the issue, it was from `redis` from client code lol and it makes hang Jest lol thanks for your help Timothy :slightly_smiling_face:

harris
2022-07-22 00:03
actually, it is more like `jest` issue lol, I had checked with node 16 , no issue lol https://github.com/facebook/jest/issues/7874 I think node 18 in Jest having an issue

husamhindustani
2022-07-22 06:52
has joined #pact-js

zhaopeng
2022-07-22 08:34
Hey team, may I ask pact-js is in v4 pact or v3 pact? in pact-jvm it mentioned that from v4.3.x it can support pact plugin, may I ask for pact-js do we also support plugins? thanks a lot . (since we need to add our gRPC plugin) cc: @vadim

matt.fellows
2022-07-22 09:01
The JS core has support for plugins and V4 sync pact now and there is a protobuf test there, but it's not yet in the Pact JS lib yet. The plan will be first to release the 10.x.x branch which should be in the next week or two, and then plugins etc will be added in a month or so after that

mike.key
2022-07-22 16:00
Ok, finally getting back to this @matt.fellows The pact file: ```{ "consumer": { "name": "partner-signup-fe" }, "provider": { "name": "campaign-manager" }, "interactions": [ { "description": "a request for campaigns", "providerState": "list of available campaigns is returned", "request": { "method": "GET", "path": "/" }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": [ { "active": true, "campaignName": "Campaign Name", "createdDate": "2022-06-24T17:23:57.232253Z", "endDate": "2022-06-24T17:23:57.232253Z", "id": "ce118b6e-d8e1-11e7-9296-cec278b6b50a", "startDate": "2022-06-24T17:23:57.232253Z", "updatedBy": "SomeUser", "updatedDate": "2022-06-24T17:23:57.232253Z" } ], "matchingRules": { "$.body": { "min": 1 }, "$.body[*].*": { "match": "type" }, "$.body[*].active": { "match": "type" }, "$.body[*].campaignName": { "match": "type" }, "$.body[*].createdDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body[*].endDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body[*].id": { "match": "regex", "regex": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$" }, "$.body[*].startDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body[*].updatedBy": { "match": "type" }, "$.body[*].updatedDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" } } } }, { "description": "a request for a campaign that exists", "providerState": "the campaign is returned", "request": { "method": "GET", "path": "/ce118b6e-d8e1-11e7-9296-cec278b6b50a" }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "active": true, "campaignName": "Campaign Name", "createdDate": "2022-06-24T17:23:57.232253Z", "endDate": "2022-06-24T17:23:57.232253Z", "id": "ce118b6e-d8e1-11e7-9296-cec278b6b50a", "startDate": "2022-06-24T17:23:57.232253Z", "updatedBy": "SomeUser", "updatedDate": "2022-06-24T17:23:57.232253Z" }, "matchingRules": { "$.body.active": { "match": "type" }, "$.body.campaignName": { "match": "type" }, "$.body.createdDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.endDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.id": { "match": "regex", "regex": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$" }, "$.body.startDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.updatedBy": { "match": "type" }, "$.body.updatedDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" } } } }, { "description": "a request to create a campaign", "providerState": "campaign is created", "request": { "method": "POST", "path": "/", "body": { "active": true, "campaignName": "Campaign Name", "endDate": "2022-06-24T17:23:57.232253Z", "startDate": "2022-06-24T17:23:57.232253Z", "updatedBy": "Some User" } }, "response": { "status": 200, "headers": { }, "body": { "active": true, "campaignName": "Campaign Name", "createdDate": "2022-06-24T17:23:57.232253Z", "endDate": "2022-06-24T17:23:57.232253Z", "id": "ce118b6e-d8e1-11e7-9296-cec278b6b50a", "startDate": "2022-06-24T17:23:57.232253Z", "updatedBy": "SomeUser", "updatedDate": "2022-06-24T17:23:57.232253Z" }, "matchingRules": { "$.body.active": { "match": "type" }, "$.body.campaignName": { "match": "type" }, "$.body.createdDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.endDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.id": { "match": "regex", "regex": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$" }, "$.body.startDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.updatedBy": { "match": "type" }, "$.body.updatedDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" } } } }, { "description": "a request to update a campaign", "providerState": "the campaign is updated", "request": { "method": "PUT", "path": "/ce118b6e-d8e1-11e7-9296-cec278b6b50a", "body": { "active": true, "campaignName": "Campaign Name", "endDate": "2022-06-24T17:23:57.232253Z", "startDate": "2022-06-24T17:23:57.232253Z", "updatedBy": "Some User", "id": "ce118b6e-d8e1-11e7-9296-cec278b6b50a" } }, "response": { "status": 200, "headers": { }, "body": { "active": true, "campaignName": "Campaign Name", "createdDate": "2022-06-24T17:23:57.232253Z", "endDate": "2022-06-24T17:23:57.232253Z", "id": "ce118b6e-d8e1-11e7-9296-cec278b6b50a", "startDate": "2022-06-24T17:23:57.232253Z", "updatedBy": "SomeUser", "updatedDate": "2022-06-24T17:23:57.232253Z" }, "matchingRules": { "$.body.active": { "match": "type" }, "$.body.campaignName": { "match": "type" }, "$.body.createdDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.endDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.id": { "match": "regex", "regex": "^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$" }, "$.body.startDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" }, "$.body.updatedBy": { "match": "type" }, "$.body.updatedDate": { "match": "regex", "regex": "^\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d\\.\\d+([+-][0-2]\\d(:?[0-5]\\d)?|Z)$" } } } }, { "description": "a request to delete a campaign", "providerState": "campaign-manager can delete a campaign", "request": { "method": "DELETE", "path": "/ce118b6e-d8e1-11e7-9296-cec278b6b50a" }, "response": { "status": 204, "headers": { } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }```

mike.key
2022-07-22 16:01
Debug output of one of the provider calls (the rest are the same, delete passes): ```09:55:42.674 [Test worker] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@331d645a 09:55:42.674 [Test worker] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Detected org.springframework.web.servlet.support.SessionFlashMapManager@49b7eb3 09:55:42.674 [Test worker] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data 09:55:42.674 [Test worker] INFO org.springframework.test.web.servlet.TestDispatcherServlet - Completed initialization in 2 ms 09:55:42.676 [Test worker] DEBUG au.com.dius.pact.provider.junit5.PactVerificationStateChangeExtension - beforeEach for interaction 'a request for campaigns' 09:55:42.677 [Test worker] INFO au.com.dius.pact.provider.junit5.PactVerificationStateChangeExtension - Invoking state change method 'list of available campaigns is returned':SETUP Verifying a pact between partner-signup-fe (53d2605be7c514206dfae6909caa2d658f254f5d) and campaign-manager [PENDING] Notices: 1) The pact at https://pax8.pactflow.io/pacts/provider/campaign-manager/consumer/partner-signup-fe/pact-version/c719ba4772ec6631e6fb052e8ef165153207b0b6 is being verified because the pact content belongs to the consumer version matching the following criterion: * latest version of partner-signup-fe that has a pact with campaign-manager (53d2605be7c514206dfae6909caa2d658f254f5d) 2) This pact is in pending state for this version of campaign-manager because a successful verification result for a version of campaign-manager with tag 'local' has not yet been published. If this verification fails, it will not cause the overall build to fail. Read more at https://docs.pact.io/go/pending [from Pact Broker https://pax8.pactflow.io/pacts/provider/campaign-manager/consumer/partner-signup-fe/pact-version/c719ba4772ec6631e6fb052e8ef165153207b0b6/metadata/c1tdW2xdPXRydWUmc1tdW2N2XT01MTAmcD10cnVl] Given list of available campaigns is returned a request for campaigns 09:55:42.792 [Test worker] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - GET "/", parameters={} 09:55:42.795 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to com.pax8.campaignmanager.endpoint.CampaignEndpoints#getAllCampaignsByFilter(Optional, Optional, Pageable) 09:55:42.838 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Using 'application/json', given [*/*] and supported [application/json] 09:55:42.862 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Nothing to write: null body 09:55:42.863 [Test worker] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Completed 200 OK 09:55:42.864 [Test worker] DEBUG au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget - Received response: 200 09:55:42.867 [Test worker] DEBUG au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget - Response: ProviderResponse(statusCode=200, headers={}, contentType=application/json, body=) 09:55:42.876 [Test worker] DEBUG au.com.dius.pact.core.matchers.Matching - matchBody: context=MatchingContext(matchers=MatchingRuleCategory(name=body, matchingRules={$=MatchingRuleGroup(rules=[MinTypeMatcher(min=1)], ruleLogic=AND, cascaded=false), $[*].*=MatchingRuleGroup(rules=[au.com.dius.pact.core.model.matchingrules.TypeMatcher@4c829699], ruleLogic=AND, cascaded=false), $[*].active=MatchingRuleGroup(rules=[au.com.dius.pact.core.model.matchingrules.TypeMatcher@4c829699], ruleLogic=AND, cascaded=false), $[*].campaignName=MatchingRuleGroup(rules=[au.com.dius.pact.core.model.matchingrules.TypeMatcher@4c829699], ruleLogic=AND, cascaded=false), $[*].createdDate=MatchingRuleGroup(rules=[RegexMatcher(regex=^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d(:?[0-5]\d)?|Z)$, example=null)], ruleLogic=AND, cascaded=false), $[*].endDate=MatchingRuleGroup(rules=[RegexMatcher(regex=^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d(:?[0-5]\d)?|Z)$, example=null)], ruleLogic=AND, cascaded=false), $[*].id=MatchingRuleGroup(rules=[RegexMatcher(regex=^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$, example=null)], ruleLogic=AND, cascaded=false), $[*].startDate=MatchingRuleGroup(rules=[RegexMatcher(regex=^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d(:?[0-5]\d)?|Z)$, example=null)], ruleLogic=AND, cascaded=false), $[*].updatedBy=MatchingRuleGroup(rules=[au.com.dius.pact.core.model.matchingrules.TypeMatcher@4c829699], ruleLogic=AND, cascaded=false), $[*].updatedDate=MatchingRuleGroup(rules=[RegexMatcher(regex=^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d(:?[0-5]\d)?|Z)$, example=null)], ruleLogic=AND, cascaded=false)}), allowUnexpectedKeys=true, pluginConfiguration={}) returns a response which has status code 200 (OK) includes headers "Content-Type" with value "application/json" (FAILED) has a matching body (FAILED) Pending Failures: 1) Verifying a pact between partner-signup-fe and campaign-manager - a request for campaigns includes headers "Content-Type" with value "[application/json]" 1.1) header: Expected a header 'Content-Type' but was missing 1.2) body-content-type: Expected a response type of 'application/json' but the actual type was 'null' 09:55:42.886 [Test worker] DEBUG au.com.dius.pact.provider.DefaultTestResultAccumulator - Received test result 'Failed(results=[{attribute=header, description=Expected a header 'Content-Type' but was missing, identifier=Content-Type, interactionId=b1b9d02b26684cf6bf742ad95229d7485b42f006}, {attribute=body-content-type, description=Expected a response type of 'application/json' but the actual type was 'null', interactionId=b1b9d02b26684cf6bf742ad95229d7485b42f006}], description=Headers had differences, Body had differences)' for Pact campaign-manager-partner-signup-fe and a request for campaigns (Pact Broker https://pax8.pactflow.io/pacts/provider/campaign-manager/consumer/partner-signup-fe/pact-version/c719ba4772ec6631e6fb052e8ef165153207b0b6/metadata/c1tdW2xdPXRydWUmc1tdW2N2XT01MTAmcD10cnVl) 09:55:42.889 [Test worker] DEBUG au.com.dius.pact.provider.DefaultTestResultAccumulator - Number of interactions #5 and results: [Failed(results=[{attribute=header, description=Expected a header 'Content-Type' but was missing, identifier=Content-Type, interactionId=b1b9d02b26684cf6bf742ad95229d7485b42f006}, {attribute=body-content-type, description=Expected a response type of 'application/json' but the actual type was 'null', interactionId=b1b9d02b26684cf6bf742ad95229d7485b42f006}], description=Headers had differences, Body had differences)] 09:55:42.889 [Test worker] WARN au.com.dius.pact.provider.DefaultTestResultAccumulator - Not all of the 5 were verified. The following were missing: 09:55:42.889 [Test worker] WARN au.com.dius.pact.provider.DefaultTestResultAccumulator - a request for a campaign that exists 09:55:42.889 [Test worker] WARN au.com.dius.pact.provider.DefaultTestResultAccumulator - a request to create a campaign 09:55:42.889 [Test worker] WARN au.com.dius.pact.provider.DefaultTestResultAccumulator - a request to update a campaign 09:55:42.889 [Test worker] WARN au.com.dius.pact.provider.DefaultTestResultAccumulator - a request to delete a campaign 09:55:42.889 [Test worker] DEBUG au.com.dius.pact.provider.junit5.PactVerificationStateChangeExtension - afterEach for interaction 'a request for campaigns' 09:55:42.895 [Test worker] DEBUG _org.springframework.web.servlet.HandlerMapping.Mappings - c.p.c.e.CampaignEndpoints: {POST [/], consumes [application/json], produces [application/json]}: createCampaign(CampaignDTO) {DELETE [/{id}]}: deleteCampaign(String) {POST [/populate-campaigns]}: populateWithContractorData() {GET [/], produces [application/json]}: getAllCampaignsByFilter(Optional,Optional,Pageable) {GET [/{id}], produces [application/json]}: getCampaignById(String) {PUT [/{id}], consumes [application/json], produces [application/json]}: updatePartner(CampaignDTO,String) 09:55:42.896 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - 6 mappings in org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping 09:55:42.900 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter - ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice 09:55:42.901 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice 09:55:42.901 [Test worker] INFO org.springframework.mock.web.MockServletContext - Initializing Spring TestDispatcherServlet ''```

harley
2022-07-23 02:15
has joined #pact-js

harley
2022-07-23 02:22
Hey team, In my application, I require request headers that are derived from the current date/time and a private key. I am now experiencing intermittent timing issues in my consumer tests because of this, I set `withRequest` with a header that is calculated at run time, but then my actual application code executes a second or two later, and generates a slightly different header since the time is off by a second or two. I tried to use Matchers, but then those matches get sent to my provider within provider verification and fail since it is a malformed header and the service denies the request. Is there a workaround here? Can I specify a Matcher within `withRequest` but use the actual header from the application code to verify against the provider? New to pactflow and contract testing in general so apologies in advance! Any help would be greatly appreciated.


matt.fellows
2022-07-23 02:44
Have a read of that

harley
2022-07-23 03:08
Thanks @matt.fellows, I have added a request filter on the provider side to add the required headers.

matt.fellows
2022-07-24 23:21
Thanks @mike.key Looking at the above, it seems like it got a null body and no `content-type`t header (I?m not sure what `contentType` is there in the debug log, whether it?s the expected type or detected, but you can see the headers map is empty) ```9:55:42.792 [Test worker] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - GET "/", parameters={} 09:55:42.795 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped to com.pax8.campaignmanager.endpoint.CampaignEndpoints#getAllCampaignsByFilter(Optional, Optional, Pageable) 09:55:42.838 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Using 'application/json', given [*/*] and supported [application/json] 09:55:42.862 [Test worker] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor - Nothing to write: null body 09:55:42.863 [Test worker] DEBUG org.springframework.test.web.servlet.TestDispatcherServlet - Completed 200 OK 09:55:42.864 [Test worker] DEBUG au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget - Received response: 200 09:55:42.867 [Test worker] DEBUG au.com.dius.pact.provider.spring.junit5.MockMvcTestTarget - Response: ProviderResponse(statusCode=200, headers={}, contentType=application/json, body=)```

mike.key
2022-07-25 02:00
That's the part that blows my mind, I can use curl or postman and make the same call and I get the right headers back

mike.key
2022-07-25 02:01
And body

japlavaren
2022-07-25 09:21
has joined #pact-js

alasdair.ryan
2022-07-25 10:45
has joined #pact-js

hui.supat
2022-07-25 13:22
has joined #pact-js

mike.key
2022-07-25 16:56
not in the contract test, but in the normal endpoint functional test we also ensure the header is set: ``` }.andExpect { status { isOk() } content { contentType(MediaType.APPLICATION_JSON) }```

balaramvineethvenugop
2022-07-25 17:06
has joined #pact-js

alan.still
2022-07-25 18:18
has joined #pact-js

yshkedi
2022-07-25 21:16
has joined #pact-js

yshkedi
2022-07-25 21:21
:wave: Hello, team! I defined ?@greet_bot/pact?: ?9.18.1", on my package json, install it, wrote some tests, run and all is great. I am using mac. in my CI, the npm install (also for the pact) happens inside docker (node:16.16.0-bullseye-slim), In the installation I am getting the following error npm ERR! code 1 npm ERR! path /usr/src/app/node_modules/@pact-foundation/pact-node npm ERR! command failed npm ERR! command sh -c node postinstall.js npm ERR! Installing Pact Standalone Binary for linux. npm ERR! Downloading Pact Standalone Binary v1.89.02-rc1 for platform linux from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.89.02-rc1/pact-1.89.02-rc1-linux-x86_64.tar.gz npm ERR! Please note: we are tracking this download anonymously to gather important usage statistics. To disable tracking, set ?pact_do_not_track: true? in your package.json ?config? section. npm ERR! Error: Error while installing binary: Postinstalled Failed Unexpectedly: Error downloading binary from https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.89.02-rc1/pact-1.89.02-rc1-linux-x86_64.tar.gz: Error: Error while installing binary: Error: EACCES: permission denied, open ?/root/.npmrc? npm ERR! at throwError (/usr/src/app/node_modules/@pact-foundation/pact-node/standalone/install.js:42:11) npm ERR! at /usr/src/app/node_modules/@pact-foundation/pact-node/standalone/install.js:327:16

yshkedi
2022-07-25 21:21
I looked into the .npmrc permission and I don?t see any issue there (for the worst case, i gave it 777 access)

yshkedi
2022-07-25 21:22
i tried to downgrade the version to 9.17.3 and getting the same error

yshkedi
2022-07-25 21:22
locally, it works great

yshkedi
2022-07-25 21:22
didn?t see any usful answer on the internet, would like to get your help

apapia
2022-07-26 02:27
has joined #pact-js

matt.fellows
2022-07-26 03:40
any ideas @uglyog? Am I reading the output correctly?

matt.fellows
2022-07-26 03:40
my guess is proxies. Albeit, not sure why it?s looking at `.npmrc`


uglyog
2022-07-26 03:55
I think this issue is being caused by MockMVC. MockMVC creates a mock request or response environment, and it seems to not be setting the content type header (as a real response would have).

matt.fellows
2022-07-26 03:56
ah!


uglyog
2022-07-26 04:01
The content type is an attribute on the mock response. We could try force a content type header is there is not one set

yshkedi
2022-07-26 04:24
there isn?t anyproxy that I know about, I can reproduce it frrom my computer as well

yshkedi
2022-07-26 04:26
on my computer it works well, but when I run it inside the container, the issue happens (like our CI)

yshkedi
2022-07-26 04:27
it was weird to me as well why should it looks

matt.fellows
2022-07-26 04:46
Can you please share a repro container definition so we can investigate?


yshkedi
2022-07-26 08:18
After investgation, i found the root cause of the issue. In my env, i have a node project that Installed over a container. in the docker file, was define the home project in the root folder (maybe a mistake) on the root folder (/root), and the project on the project folder (src/app). when doing npm install inside the container, the pact trying to read the user npmrc, that exist by default on the home folder, and it get an access denied. in my side, the workaround for this, is to change the root folder (home) permission, or to change the home directory. but maybe it should be considered as a bug (corner case) and to try to strat read over the huracrchey, and if get an excaption got to the parent (project, uuser, global), in this case, because the home hasn?t permission, it breaks the installation.

rziembicki
2022-07-26 10:47
has joined #pact-js

dpal
2022-07-26 10:58
has joined #pact-js

dgrace
2022-07-26 11:02
has joined #pact-js

dgowdappa
2022-07-26 11:02
has joined #pact-js

matt.fellows
2022-07-26 12:12
Nice digging Yair! If you could please raise an issue we'll get it looked at, I know why we load that file and I think we can improve the error handling if not found

yshkedi
2022-07-26 12:17
thanks for your answer. pls send me a link and I will open

sascha_pactflow
2022-07-26 20:29
has joined #pact-js


hunsolitude
2022-07-26 22:34
has joined #pact-js

harris
2022-07-27 00:14
hello, can I get some reference document point to resolve this error? `The property 'all' is not a valid property of ConsumerVersionSelector. Allowed properties are tag, latest, consumer, deployedOrReleased, deployed, released, environment, fallbackTag, branch, mainBranch, matchingBranch)` after I update to v3, I got this message, can I get some guideline please?


matt.fellows
2022-07-27 01:14
You probably want `latest: false`

matt.fellows
2022-07-27 01:16
The next version of the beta won?t fail with an error and will allow you to specify invalid keys, but will still log a warning (this is to support bleeding edge selectors that the broker supports that clients don?t support).

matt.fellows
2022-07-27 01:16
But in your case, this isn?t a valid selector and isn?t doing anything useful

harris
2022-07-27 01:21
oh yes Matt, `latest: false` works :slightly_smiling_face: thanks!

harris
2022-07-27 05:44
for provider side verification, I got ```has status code 200 (OK) includes headers "Content-Type" with value "application/json" (OK) has a matching body (OK)``` then failure ``` 1.1) has a matching body expected 'application/json;charset=utf-8' body but was 'application/json' 1.2) includes header 'Content-Type' with value 'application/json; charset=utf-8' Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'application/json'``` I am little bit confused. lol consumer pact response and request headers are ```"headers": { "Content-Type": "application/json" },```

harris
2022-07-27 05:46
where should I look at to fix?

matt.fellows
2022-07-27 06:10
set logs to `debug` and see if they help understand the issue

matt.fellows
2022-07-27 06:10
what does the contract look like?

harris
2022-07-27 06:17
`You can change the log levels using the LOG_LEVEL environment variable.`

harris
2022-07-27 06:18
so is that mean set in provider opt?

matt.fellows
2022-07-27 06:18
Ah, that should be a property on the Verifier I think

harris
2022-07-27 06:25
```logLevel: "DEBUG",```

harris
2022-07-27 06:25
is that right way to set?

matt.fellows
2022-07-27 06:25
are you using an IDE? Most IDEs should be able to show you the available types

matt.fellows
2022-07-27 06:25
that looks close, albeit I think the log level is lower case e.g. `debug`

harris
2022-07-27 06:26
`Types of property 'logLevel' are incompatible.` `Type 'string' is not assignable to type 'LogLevel'.`

harris
2022-07-27 06:26
let me try debug


tjones
2022-07-27 07:19
> Type 'string' is not assignable to type 'LogLevel'. This is because LogLevel isn't a string, it's a type literal. You can address this with `logLevel: 'debug' as const`


maksym_odanets
2022-07-27 08:07
has joined #pact-js

alanbos
2022-07-27 08:18
Hi running beta58 and trying to debug a consumer contract test where the URL path is matching when it shouldn't be ```[2022-07-27T08:00:39Z INFO pact_mock_server::hyper_server] Received request HTTP Request ( method: GET, path: /foo/1/bar, query: None, headers: Some({"accept": ["application/json"], "authorization": ["Bearer undefined"], "user-agent": ["node-fetch/1.0 (+https://github.com/bitinn/node-fetch)"], "accept-encoding": ["gzip", "deflate"], "connection": ["close"], "host": ["127.0.0.1:52198"]}), body: Empty ) [2022-07-27T08:00:39Z INFO pact_matching] comparing to expected HTTP Request ( method: GET, path: /fooBlah/1/bar, query: None, headers: Some({"Accept": ["application/json"]}), body: Missing ) [2022-07-27T08:00:39Z INFO pact_mock_server::hyper_server] Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(266 bytes, application/json) )``` I'm looking for strings like `comparing to expected HTTP Request` in the pact and pact-core codebase but not having any luck - could someone point me at where these are? [Some GLIBC-related blockers prevent me moving to beta62 at this time]

alanbos
2022-07-27 08:22
P.S. ^^^ I think the issue is related to using `fromProviderState('/fooBlah/{id}/bar', '/fooBlah/1/bar')` when specifying a path matcher, as using a raw matcher causes the URL to not be matched (as expected)

matt.fellows
2022-07-27 08:23
Just dropped off for the day, but the core matching is all in here: https://github.com/pact-foundation/pact-reference/tree/master/rust

matt.fellows
2022-07-27 08:23
:dragon:

alanbos
2022-07-27 08:23
Thanks @matt.fellows!

alanbos
2022-07-27 08:42
I'm a bit stuck as no idea how to debug Rust code when running Webstorm on a nodejs project, but I can see that it will end up in the `match_path()` function and do this: ```match_values(&path, &context.select_best_matcher(&path), expected.to_string(), actual.to_string())``` All I can guess is that this works as expected unless the `fromProviderState` matcher was used on the path; maybe something to do with the `select_best_matcher` function?

andrew.january
2022-07-27 09:03
has joined #pact-js

davidf
2022-07-27 09:17
has joined #pact-js

matt.fellows
2022-07-27 12:09
Interesting. My assumption is that the path should match exactly (on the consumer side), as I didn?t think it was a matcher

matt.fellows
2022-07-27 12:10
@uglyog any thoughts? The request is going to `/foo/1/bar` but the `fromProviderState` matcher is configured as fromProviderState(?/fooBlah/{id}/bar?, ?/fooBlah/1/bar?)

mrigendra.ranjan
2022-07-27 13:28
So I have been trying to run pact-verify stage in my gitlab pipeline and I am facing below errors. Has anyone faced anything similar? `Error: Error relocating /builds/app/node_modules/@pact-foundation/pact-core/build/Release/libpact_ffi.so: __vsnprintf_chk: symbol not found` I have tried with beta60 and beta62 as well but I don?t think its an issue with the version.

tjones
2022-07-27 14:47
What operating system and node version are you using?

mrigendra.ranjan
2022-07-27 18:17
This is happening during the pipeline stage. os: alpine linux node version: v16.14.2

matt.fellows
2022-07-27 22:12
I don't believe we currently support Alpine Linux

tjones
2022-07-27 23:30
Alpine is missing things it needs for glibc. You might get some mileage from apk adding the gcompat package to your alpine image

harris
2022-07-28 00:03
I found it, actual issue was request failed from provider side lol ``` outgoing response: {"body":"{\"errors\":[{\"message\":\"Not found\",\"extensions\":{\"category\":\"notFound\",\"code\":\"NOT_FOUND\"},\"locations\":[{\"line\":2,\"column\":5}],\"path\":[\"deleteLink\"]}],\"data\":{\"deleteLink\":null}}"``` do you know why pact generate this message? is that becuz of empty body? I am not sure others, but it make me really confused lol ```has a matching body expected 'application/json;charset=utf-8' body but was 'application/json' 1.2) includes header 'Content-Type' with value 'application/json; charset=utf-8'```

matt.fellows
2022-07-28 00:06
What header is your provider returning?

harris
2022-07-28 00:15
`DEBUG pact_verifier::provider_client] Received native response:` `"content-type": "application/json"`

matt.fellows
2022-07-28 00:20
So looks to be missing the charset

harris
2022-07-28 00:27
my consumer contract is ```"headers": { "Content-Type": "application/json" }```

harris
2022-07-28 00:28
so it should be fine?

matt.fellows
2022-07-28 00:28
Can you please share the whole logs?

harris
2022-07-28 00:29
Failures log?

tjones
2022-07-28 00:39
He's asking for the whole log of the test run - often the problem is more easily visible from the whole log rather than just snippets.

matt.fellows
2022-07-28 00:39
Yes, exactly. I can?t tell from above whether it _thinks_ the content type is JSON or it was explicitly told that (via the presence of the `content-type` header)

tjones
2022-07-28 00:40
if you could also share the whole contract test, that would be helpful too.

harris
2022-07-28 01:29
I fixed it, it was all about confusion between v2 and v3 providerState mixed up from pactflow, it was my mistake lol haha anyway all good now :slightly_smiling_face:

harris
2022-07-28 01:29
thanks for your help

harris
2022-07-28 01:29
`debug` was really useful

matt.fellows
2022-07-28 01:29
Great to hear you got to the bottom of it!

matt.fellows
2022-07-28 01:30
That sounds like maybe we could improve messaging / DX somewhere. Would you mind please elaborating on the problem a bit further?

harris
2022-07-28 01:31
yeap so the error message (wrong content type `content-type`)was right , because I did not change provider to look at v3, it was look at v2 version but I did not know

harris
2022-07-28 01:32
so what I did is generate pact v3(consumer) from my local and added tag `test` and publish to pactflow

harris
2022-07-28 01:33
then go back to provider to look at tag `test` and ran test

harris
2022-07-28 01:36
human error tbh lol

harris
2022-07-28 01:38
initially, I manually published from my consumer, and set provider ```consumerVersionSelectors: [ { tag: 'feature', latest: true }``` I thought provider will look at my latest published pact but it was not

harris
2022-07-28 01:38
that all started my confusion

harris
2022-07-28 01:38
so I had to change tag to `test` and find out provider was looking at wrong pact lol

harris
2022-07-28 01:40
maybe in debug mode, if it shows what consumer version I am looking at it now? it will be much easier to debug?

matt.fellows
2022-07-28 01:48
Thanks for the update. So, the verification process should print out which pact it is verifying and why. If you drop the log level back to info, there should be a notice printed out before the verification

harris
2022-07-28 03:02
thanks Matt

akash.sharma5253
2022-07-28 07:51
Hi guys, at Provider sider verification I have two requests to be verified. One is Post and other is get. I want to read ?id? from Post response and fed it to get request (get by id). How do I read response using requestFilter?

greg.tyler
2022-07-28 09:25
@greg.tyler has left the channel

mrigendra.ranjan
2022-07-28 09:57
its working fine for another service which also uses docker alpine. not sure why its not working for me. Although the node version as well as the pact version is different over there.

ankit.mittal
2022-07-28 10:00
has joined #pact-js

vishal.kukreja
2022-07-28 10:22
has joined #pact-js

tjones
2022-07-28 10:25
The request filter is for requests. Why do you want to read the response?

tjones
2022-07-28 10:25
Pact should read and validate the response for you

akash.sharma5253
2022-07-28 10:35
Actually the post request to create a user gives me back the user Id which I want and pass it to Get request to retrieve the user

tjones
2022-07-28 11:27
I would not recommend using pact that way. It's better to treat each request as independent

matt.fellows
2022-07-28 11:27
You should read up on provider states. In Pact testing we want to avoid this kind of test coupling. Each test should be able to be tested in isolation, and provider states is the primary mechanism to achieve this

tjones
2022-07-28 11:27
Pact does not guarantee the order of interaction

matt.fellows
2022-07-28 11:28
Always with the timing Tim :rolling_on_the_floor_laughing:

matt.fellows
2022-07-28 11:32
Which version of pact? The 9.x.x line should, but the 10.x.x won't

mrigendra.ranjan
2022-07-28 11:37
Verification step works fine with 9.x but fails during match as the consumer is a JAVA application having v3 spec pacts.

mrigendra.ranjan
2022-07-28 11:40
Is there any plan for stable release for v3 spec for pact js anytime soon?

matt.fellows
2022-07-28 11:41
You can generate a v2 pact from Pact JVM if that's your issue


pollet_22
2022-07-28 14:46
hi guys , can any one advice me .. i am new in pact and i want to make a contract testing between two micro-services which is in go language it's ok to write pact in Javascript as i experience in javascript not in go ?

robert.henzel
2022-07-28 19:50
has joined #pact-js

mike.key
2022-07-28 20:02
do I need to have `@SpringBootTest` to use MockMVC like this? Guessing because I don't is why the header doesn't show there

matt.fellows
2022-07-28 22:54
:wave:

matt.fellows
2022-07-28 22:55
As Pact tests are intended to be as close to a unit test as possible, it?s best for them to be written in the language they are testing. So in your case, they should be written in Go

matt.fellows
2022-07-28 22:55
Can you pair with the developers of the Go services?

pollet_22
2022-07-29 00:42
Yes i can do that

adrianminnock123
2022-07-29 08:53
has joined #pact-js

massimiliano.devivo
2022-07-29 12:12
has joined #pact-js

yshkedi
2022-07-29 13:17
I have 2 questions: 1 - I saw that there isn?t an option to verify an empty array, but I think there are some cases that it should be checked, for example: Assume you have the following get request: getFieldsByCountry the response is `[{ l1: fields[{k1, v1}] ,` `l2: fields[]}` In other words, what about the case of API that has children that has attrbiute as value with array type, but some of the array could be an empty array, I think this is a common case saw this post as well https://stackoverflow.com/questions/61772433/how-to-verify-pact-when-data-returns-items-with-or-without-children-filled-in-o and I understood the issue if min value would be 0, but from the other case, i think it is a common case that couldn?t be checked 2 - How can I verify a request with a dynamic id (url param). I looked into the documentation, and didn?t see a way to do that. For example, I have an api that generate some request and the response is the id, then I want to call to a get request, by the id (the id is a url param) (the id is created dynamically)

tjones
2022-07-29 14:06
there is absolutely an option to verify an empty array

tjones
2022-07-29 14:06
you just specify an empty array

tjones
2022-07-29 14:07
there isn't an option to say "like this type, but minimum none", because that means that empty arrays that never return the right type might inappropriately pass. For full verification, you need to test both the empty and the non-empty array cases

tjones
2022-07-29 14:08
question 2 - stackoverflow seems to be down (!) so I can't answer that now, sorry :disappointed:

tjones
2022-07-29 14:11
Ah, wait - yes, you can do that with provider states. Have a look at `fromProviderState` Remember that in a pact test, each interaction is independent - you use provider state to set any preconditions.

hareesh.dj
2022-07-30 12:01
has joined #pact-js

yshkedi
2022-07-31 05:58
@tjones thanks I will try this.

yshkedi
2022-07-31 05:59
@aram pls take a look on the ?fromProviderState?

heera
2022-07-31 08:00
has joined #pact-js

harris
2022-08-01 04:42
Hello, as v3 is no longer beta, is it changed to `jest-pact` as well? https://github.com/pact-foundation/jest-pact/blob/pact-js-v3/README.md#pact-js-v3 what is right usage for jest-pact now?

matt.fellows
2022-08-01 04:55
We haven't updated that yet. The Pact JS API hasn't changed so it should still work though

harris
2022-08-01 05:36
I dont know where to post rust error , but `thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', pact_matching/src/headers.rs:22:45` what is meaning?

matt.fellows
2022-08-01 05:40
Perhaps tells us what you're doing to get this problem and we can help

harris
2022-08-01 05:41
jsut run provider test, but just want to confirm that can I use single provider state for multiple test?

harris
2022-08-01 05:42
for example, providerState: create user id and return `id`

harris
2022-08-01 05:42
and consumer test getUser, updateUser, deleteUser like this?

harris
2022-08-01 05:44
using all same `id` for all of the tests?

harris
2022-08-01 05:44
or each test should have an unique provider state?

harris
2022-08-01 05:46
btw the Rust error happens after `comparing to expected response: HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json;"]}), body: Present(39 bytes) )`

harris
2022-08-01 05:48
`JSON -> JSON: Comparing '2' to '3' using Type -> Ok(())` `compare_values: Comparing 'Number(2)' to 'Number(3)' at path '$.data.setLinkGatingRule.id' -> Ok(())` then `thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', pact_matching/src/headers.rs:22:45` happening

matt.fellows
2022-08-01 05:49
Yes, you should definitely be able to do that!

matt.fellows
2022-08-01 05:50
It sounds like a bug to me. Could you please raise an issue with: ? The version of jest-pact / pact-js you?re using ? The pact file that causes the issue (or a minimal reproducable example we can use) ? The actual provider response causing the issue You should be able to run just the test that is failing, but setting the `PACT_DESCRIPTION` environment variable to the one that?s exploding to isolate the problem

harris
2022-08-01 06:01
I cannot really share live pact in public repo, I have compared with passed test, so below message were missing when I got Rust error ```INFO pact_verifier] Running provider state change handler 'A new link will be created' for 'a deleteLink request'``` `DEBUG pact_verifier::provider_client] Sending HTTP Request ( method: POST, path: /, query: None, headers: Some({"Content-Type": ["application/json"]}), body: Present(70 bytes, application/json) ) to state change handler`

harris
2022-08-01 06:01
so I assume, some how, provider state step got wrong?

matt.fellows
2022-08-01 06:29
Perhaps. It's going to be hard to provide advice without a repro

matt.fellows
2022-08-01 06:29
We don't need your work code, we just need an example that can reproduce the problem

matt.fellows
2022-08-01 06:30
See howtorepro


matt.fellows
2022-08-01 06:31
It looks like the failure is during parsing charset characters. So that might be a clue

matt.fellows
2022-08-01 06:31
(charset in the content type header I'm guessing)

matt.fellows
2022-08-01 06:33
If you could even just share the pact file bits that have the content-type expectations and what your provider responds that will help

adam.redlisiak
2022-08-01 10:18
has joined #pact-js

altan.demirkiran846
2022-08-01 14:38
has joined #pact-js

nick080
2022-08-01 14:44
has joined #pact-js

ali.ustek
2022-08-01 15:09
has joined #pact-js

dimundo
2022-08-01 16:17
hi! i?m getting `Timeout waiting for verification process to complete` i found this https://docs.pact.io/slack/pact-js.html#1586998747.127100 do i get it right, i need something like this ? ``` return new MessageProviderPact({ ... timeout: 60000, ... }).verify() }```

momarquez
2022-08-01 19:37
has joined #pact-js

matt.fellows
2022-08-01 22:46
It would be interesting to know why it?s timing out - but yes, you should be able to extend the timeout process

harris
2022-08-02 03:47
yeap it looks like a bug, I have send request to provider directly(without pact setup) it is working as expected lol my problem is I have no idea how to share repro code ..

harris
2022-08-02 03:48
as I got big fat complicated monolith provider setup lol

matt.fellows
2022-08-02 03:57
Great!

harris
2022-08-02 03:57
I got rust backtrace log, do you think it will help you?

matt.fellows
2022-08-02 03:57
Probably

matt.fellows
2022-08-02 03:58
But simplest is to just create a tiny little express app that returns a canned JSON (or whatever it is) with the appropriate that produces the fault. That, and the minimal pact file with the single interaction (ideally just the bits of the interaction) that elicit the failure

harris
2022-08-02 03:58
```thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', pact_matching/src/headers.rs:22:45 stack backtrace: 0: rust_begin_unwind at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5 1: core::panicking::panic_fmt at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14 2: core::panicking::panic_bounds_check at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5 3: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold 4: pact_matching::headers::match_parameter_header 5: pact_matching::headers::match_header_value 6: pact_matching::headers::match_headers 7: pact_verifier::verify_response_from_provider::{{closure}} 8: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll 9: <futures_util::future::future::flatten::Flatten<Fut,<Fut as core::future::future::Future>::Output> as core::future::future::Future>::poll 10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll 11: <futures_util::stream::stream::then::Then<St,Fut,F> as futures_core::stream::Stream>::poll_next 12: pact_verifier::verify_provider_async::{{closure}}::{{closure}} 13: <tokio::task::task_local::TaskLocalFuture<T,F> as core::future::future::Future>::poll 14: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll 15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll 16: std::thread::local::LocalKey<T>::with 17: tokio::park::thread::CachedParkThread::block_on 18: tokio::runtime::thread_pool::ThreadPool::block_on 19: tokio::runtime::Runtime::block_on 20: pact_ffi::verifier::handle::VerifierHandle::execute 21: pact_ffi::error::panic::catch_panic 22: pactffi_verifier_execute 23: _ZN4Napi11AsyncWorker18OnAsyncWorkExecuteEP10napi_env__Pv [2022-08-02 03:56:39.291 +0000] DEBUG (236 on 3b0d5f3b16db): pact@10.0.0-beta.60: outgoing response: {"body":"{\"data\":{\"setLinkGatingRule\":{\"id\":1}}}","headers":{"x-powered-by":"PHP/7.4.20","server":"nginx","content-type":"application/json","transfer-encoding":"chunked","connection":"close","set-cookie":["PHPSESSID=a79ad1a03d57970dedfb0d9a392fd4b9; path=/; HttpOnly; SameSite=lax"],"cache-control":"max-age=0, must-revalidate, private","date":"Tue, 02 Aug 2022 03:56:38 GMT","x-cache-debug":"1","x-debug-token":"bbbc3d","x-debug-token-link":"http://nginx/_profiler/bbbc3d","x-robots-tag":"noindex","expires":"Tue, 02 Aug 2022 03:56:39 GMT"},"status":200} 24: worker at /home/iojs/build/ws/out/../deps/uv/src/threadpool.c:122:5 25: start_thread 26: clone note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. [2022-08-02T03:56:39Z DEBUG pact::matching::ffi] pact_ffi::verifier::pactffi_verifier_shutdown```

matt.fellows
2022-08-02 04:00
are you testing a PHP app from JS?

matt.fellows
2022-08-02 04:01
oh, are you pointing at a live server?

harris
2022-08-02 04:02
> are you testing a PHP app from JS? yes

matt.fellows
2022-08-02 04:02
:laughing:

harris
2022-08-02 04:02
> oh, are you pointing at a live server? yes local docker compose build

harris
2022-08-02 04:03
yeap this is not a best practice but, we have some issue with old monolith? so I had to build everything lol with live DB too

dimundo
2022-08-02 11:02
sadly it fails ?sometimes? w/o any meaningful log :disappointed:

matt.fellows
2022-08-02 11:29
Might be worth setting logs to debug to see how long each request is taking

dpal
2022-08-02 13:58
Hi, I'm doing a POC on pactflow for js with SQS. The sample I'm following https://github.com/pactflow/example-consumer-js-sns/blob/master/__tests__/unit/handlers/product.service.pact.test.js. But everything is not very clear to me. Can anyone please help me. Thanks

matt.fellows
2022-08-02 14:02
How can we help?

matt.fellows
2022-08-02 14:02
I'd suggest reading the section on non-http testing at http://docs.pact.io and also the YouTube videos on how it works, which includes message pact.

matt.fellows
2022-08-02 14:03
There is also a series of AMAs (can find on the docs) and one talks about how to do this sort of testing

dpal
2022-08-02 14:03
Hey Matt, I'm new to Pact flow as well on SQS and Js. did not get the below code block:

dpal
2022-08-02 14:03
describe("product event handler", () => { const messagePact = new MessageConsumerPact({ consumer: "pactflow-example-consumer-js-sns", dir: path.resolve(process.cwd(), "pacts"), pactfileWriteMode: "update", provider: process.env.PACT_PROVIDER ? process.env.PACT_PROVIDER : "pactflow-example-provider-js-sns", logLevel: "info", });

dpal
2022-08-02 14:04
I'm trying to map the same with my service

dpal
2022-08-02 14:04
is there any other github example available for this?

matt.fellows
2022-08-02 14:05
What language are you comfortable with writing unit tests in?

dpal
2022-08-02 14:05
java but I want to do the POC in JS.

matt.fellows
2022-08-02 14:06
There is a java example (howtoexamples)


matt.fellows
2022-08-02 14:06
I'm just heading to bed but will check-in tomorrow

matt.fellows
2022-08-02 14:06
See how you go with the above resources to start with


rubemfsv15
2022-08-02 20:13
has joined #pact-js

rene.klatt
2022-08-03 06:13
has joined #pact-js

imayat
2022-08-03 09:42
has joined #pact-js

mark.shand
2022-08-03 10:15
has joined #pact-js

gunjan.titiya
2022-08-03 11:51
has joined #pact-js

chaitanya.guttula
2022-08-03 12:43
has joined #pact-js

deb.kimnach
2022-08-03 12:48
has joined #pact-js

gibraltor999
2022-08-03 14:19
@matt.fellows How can we say Pact to be a code-first API tool, if we have to have the interactions known between the C and P, before we can add them to unit tests and generate a pact out of it? We do need designs between the two parties before hand right? Or am I missing something here?

dpal
2022-08-03 15:27
Hi, can anyone give me some example of aws SQS event pact provider examples. How do I generate the pacts for such events. Thanks

yousafn
2022-08-03 15:58
Hey, You can take a look at https://docs.pactflow.io/docs/examples/aws/sns/consumer/ and its associated provider for a message based example :thumbsup:

kaiquan.shi
2022-08-04 03:38
has joined #pact-js

aalexandrumihai
2022-08-04 10:15
has joined #pact-js

alex.makdessi
2022-08-04 13:03
has joined #pact-js

ynechaieva
2022-08-04 14:11
has joined #pact-js

dineshh.wot2021
2022-08-05 10:17
has joined #pact-js

fernandapontual5
2022-08-05 11:34
has joined #pact-js

sridhar140895
2022-08-05 11:58
has joined #pact-js

glenn
2022-08-06 18:13
has joined #pact-js

matt.fellows
2022-08-07 12:13
It?s code first in that the tests are written in code, not in a spec/design first methodology (e.g. authoring an OAS or GraphQL schema before code is written)

matt.fellows
2022-08-07 12:15
> We do need designs between the two parties before hand right? No, you can definitely write the consumer code and it?s expectations of a provider, without ever having ?designed? the API. Usually, we?d expect a https://docs.pact.io/pact_nirvana/step_2 before code is written, but we don?t need an OAS or other design (if that?s what you mean)

yshkedi
2022-08-07 16:36
@tjones when I tried to set min to none, I got ERROR pact@9.18.1: error making http request: Request failed with status code 500 Also in the docamantion I saw that the min is 1. maybe this is only in the new version

tjones
2022-08-07 21:41
For the reasons I mentioned above, you can't set the min as none. You just use an empty array literal. No matcher is necessary

sandy.mechie
2022-08-07 21:46
has joined #pact-js

qingyuliu
2022-08-08 05:40
Hi team, can I test the communication between a nodejs project and spring project? Is there any sample project about testing in different code stacks?

matt.fellows
2022-08-08 05:42
Yes they can. Pact generates language agnostic contract files which you publish to a pact broker.

matt.fellows
2022-08-08 05:42
Each language only deals in these and not language specific contracts.

remigijus.mazulis
2022-08-08 05:45
Good morning, could anyone help me to add more interactions on consumer side? I've done according to example and it works with one interaction, but I cannot figure out the way to add more interactions :thinking_face:

remigijus.mazulis
2022-08-08 05:45
``` beforeAll(() => provider // Start the mock server .setup() // add interactions to the Mock Server, as many as required .then(() => provider.addInteraction({ state: 'I have employee details', uponReceiving: 'Request for employee details', withRequest: { method: 'GET', path: term({ generate: 'employee/87034701-3046-47bc-9486-c470b04f66d7', matcher: 'employee/[A-Z0-9-]+', }), }, willRespondWith: { status: 200, body: like(EXPECTED_BODY), }, }) ) );```

matt.fellows
2022-08-08 05:50
Which version are you on? Check the e2e example in the pact JS repo

matt.fellows
2022-08-08 05:50
You only call setup once for a pact session, addInteraction should be done once per test

remigijus.mazulis
2022-08-08 05:59
> Which version are you on? `"@pact-foundation/pact": "^9.18.1",` Ok looking into the e2e example :book:

matt.fellows
2022-08-08 06:01
Cool. Make sure you check the 9.x.x branch and not the current stable as the API has changed subtly

remigijus.mazulis
2022-08-08 07:18
Thanks it seems it is working. Interesting that I have to use beforeAll() and beforeEach() commands instead of before like in example :thinking_face: another question - one provider tests should be in one file? O can I update the pact file using different test files for the same provider?

abubics
2022-08-08 07:23
some libs (e.g. jest-pact) abstract away those test-DSL concerns, if that makes it easier for you

abubics
2022-08-08 07:24
how you break up your tests into files is up to you :slightly_smiling_face: But depending on what you want, you may have to do some manual work to tie the running order in with Pact

prapurna.manda3
2022-08-08 07:38
has joined #pact-js

tjones
2022-08-08 09:21
before is mocha, beforeAll is jest. Jest is significantly more popular than mocha now- it might be worth using it as the default in the examples

laura.cabantous
2022-08-08 11:20
Hi there, I'm trying to run a test scenario where a parameter is passed in an invalid format (and it should throw a 400), but it fails with the error message `with 30000 ms timeout for Pact`. I've tried to increase the timeout (quite significantly but it still fails with the same message). Is there any way to check why it times out? It seems due to a promise that doesn't resolve... Also it seems to be specifically when looking to get the provider to respond with status 400 :thinking_face: Code snippet in :thread:

laura.cabantous
2022-08-08 11:24
```it('should return an error when an invalid UPRN is passed', async () => { await provider.addInteraction({ uponReceiving: 'an invalid UPRN', withRequest: { method: 'GET', path: '/property/m1xf%d5/sales' }, willRespondWith: { status: 400, headers: default_headers, body: { error: 'BadRequest', message: 'Invalid UPRN format', statusCode: 400 } } }); process.env.API_PROPERTY_TRANSACTIONS_URL = provider.mockService.baseUrl; const response = await api().transactionalHistoryByUprn('m1xf%d5'); expect(response).toThrow('400: Bad Request'); });```

laura.cabantous
2022-08-08 11:24
When running the test:

matt.fellows
2022-08-08 11:29
```const response = await api().transactionalHistoryByUprn('m1xf%d5'); <- throws expect(response).toThrow('400: Bad Request'); <- to late, already thrown!```

matt.fellows
2022-08-08 11:30
You can actually see the error in your terminal

matt.fellows
2022-08-08 11:31
You might need to wrap it like this: ```expect(() => { throw Error(); }).toThrow();```

matt.fellows
2022-08-08 11:32
```expect(() => api().transactionalHistoryByUprn('m1xf%d5')).toThrow('400: Bad Request');```

matt.fellows
2022-08-08 11:32
I could be wrong about the jest syntax, so best to check the `toThrow` docs. You might be able to just hand it a promise. But you are `await` ing the promise, so that will always throw before the `expect`

heera
2022-08-08 11:54
Hello, Good Afternoon, I had written one consumer test for `200` status and it worked well for me, my next task is to validate `401 Unauthorised` state, but my consumer test is failing https://codeshare.io/wnEOZD, could anyone point me to right direction.

yousafn
2022-08-08 11:55
https://jestjs.io/docs/asynchronous await expect(fetchData()).rejects.toMatch('error');

yousafn
2022-08-08 11:56
Does your http client throw an error on non 2xx status codes?

yousafn
2022-08-08 11:57
If so please read https://jestjs.io/docs/asynchronous Sample code await expect(fetchData()).rejects.toMatch('error');

heera
2022-08-08 11:57
My test fails with this line `Request failed with status code 401`

yousafn
2022-08-08 11:59
I assume the promise has rejected as the provider is setup to return a 401 await api.getUserSettingsStatus()

heera
2022-08-08 12:00
I feel, it gets the status `401` but does not match the body

heera
2022-08-08 12:01
```async getUserSettingsStatus() { return axios .get(this.withPath("/api/1/user"), { headers: authHeader, }) .then((r) => { return r.data; }); }```

tjones
2022-08-08 12:07
In your test you must catch the failing promise and confirm that it meets the expectations of the calling code

laura.cabantous
2022-08-08 12:32
Thanks Matt, I wrapped it as suggested and it worked :slightly_smiling_face:

heera
2022-08-08 13:15
got it working thanks @tjones

heera
2022-08-08 13:15
```async getUserSettingsStatus() { return axios .get(this.withPath("/api/1/user"), { headers: authHeader, }) .then((r) => { return r.data; }) .catch((error) => { if (error.response.status === 401) { return Promise.resolve(error.response.data); } }); }```

tjones
2022-08-08 14:32
Your code has a bug in that it will swallow errors- you should re-throw an exception if the error is not what you were expecting

heera
2022-08-08 14:40
yeah I changed it later, thanks @tjones

jaroslavburi
2022-08-08 14:44
has joined #pact-js

manumahendran
2022-08-08 16:14
has joined #pact-js

lmendonca
2022-08-08 22:18
has joined #pact-js

jbrauchler
2022-08-08 22:44
has joined #pact-js

matt.fellows
2022-08-08 23:26
I?ve just added an example to the JS troubleshooting guide for others (this exact problem came up in hte very next post :laughing: https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#how-do-i-test-negative-scenarios-such-as-400

matt.fellows
2022-08-08 23:27
Given this question was literally asked in the previous post and does come up a bit, I?ve created a little guide in our troubleshooting doc for this: https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#how-do-i-test-negative-scenarios-such-as-400

aram
2022-08-09 08:41
Hi, is it possible to use `providerState` to change the *body* (or part of it) of a POST request? in the *consumer* side i add: ```body: fromProviderState('${actualyPayload}', samplePayload),``` and in the relevant `stateHandler` on the *provider* side i added: ``` setup: () => { return Promise.resolve({ actualPayload: payload }); },``` But pact still seems to send the original payload

matt.fellows
2022-08-09 08:42
No you can't. What's the use case?

matt.fellows
2022-08-09 08:42
Request filters are possibly your answer

matt.fellows
2022-08-09 08:43
But I'd like to know why, it's a dangerous thing to do

aram
2022-08-09 08:49
i know it?s dangerous.. :confused: i?m testing some post/get api. Now, in the POST i send. a certain payload with several unique identifiers? so if the DB is not cleared the test will fail the 2nd time it is run because it?ll clash So one option was above, change one of the uniques.. another option is clear DB (not ideal) and yet another option would be to mock the DB calls?

cristideacc
2022-08-09 09:05
has joined #pact-js

matt.fellows
2022-08-09 09:08
Yes, I believe they should work on JSON bodies. We may even have an example in the GH repo

matt.fellows
2022-08-09 09:08
Actually what you're asking for isn't very dangerous at all :rolling_on_the_floor_laughing:

heera
2022-08-09 09:08
Hi, when I am trying to access `providerBaseUrl` in provider test by passing value directly `process.env.BASE_URL` it does not recognize it, it says `TypeError: Invalid URL` while passing url in string works https://codeshare.io/BAQW7b, any idea what I am missing.

aram
2022-08-09 09:09
slightly dangerous, since who knows what i?m changing the payload on the provider side :scream:

matt.fellows
2022-08-09 09:09
My guess is that environment variable isn't set

heera
2022-08-09 09:12
its set like this..

matt.fellows
2022-08-09 09:12
And how is that exposed to the test runtime environment?

heera
2022-08-09 09:38
it was my bad

heera
2022-08-09 09:38
`import * as dotenv from "dotenv";` `dotenv.config({` `path: path.resolve(__dirname + "./../../.env"),` `});`

heera
2022-08-09 09:38
this resolved the issue

tjones
2022-08-09 10:46
Matt, does `fromProviderState` do any matching? It probably should.

tjones
2022-08-09 10:46
If not, I agree, it would let you have non-contract contract tests :confused:

aram
2022-08-09 10:48
my work around: on the *provider* side, under `stateHandle` for the create test, i first delete said entity

matt.fellows
2022-08-09 11:23
that?s an approach too

matt.fellows
2022-08-09 11:24
`fromProviderState` can definitely add properties to any place a matcher can be used. See https://github.com/pact-foundation/pact-js/blob/6a38be8610d41fb2e786bbad4b7edf1a8c5355b0/examples/v3/provider-state-injected/consumer/transaction-service.test.js#L43 for an example in a body

matt.fellows
2022-08-09 11:24
(but clearing out state between tests is the recommended way of doing this!)

matt.fellows
2022-08-09 11:25
the other function is really a workaround for times when there is random IDs generated on the provider side that can?t easily be stubbed/mocked out


matt.fellows
2022-08-09 11:28
> Matt, does `fromProviderState` do any matching? It probably should. I think it does as it is a Matcher _and_ a generator

matt.fellows
2022-08-09 11:31
Yep, it does. Modified the provider example above to return a string as an ID instead of a number: ```1) Verifying a pact between TransactionService and AccountService Given Account Test001 exists - a request to get the account details 1.1) has a matching body $.id -> Expected '27' to be an integer value```

aram
2022-08-09 11:31
ahhh? so i can use the `fromProviderState` inside my body/payload object? interesting? that way i can make sure to change just what i need and still use the payload from the pact

matt.fellows
2022-08-09 11:32
Yes. But I?d still advocate clearing state, personally.

aram
2022-08-09 13:04
Hi, so i do i solve this? i?v followed the suggestion on the https://docs.pact.io/docker, but am still getting this error working with latest pact-js on both provider and consumer

matt.fellows
2022-08-09 13:47
Alpine or docker in general? We currently don't officially support alpine


matt.fellows
2022-08-09 13:48
Apologies, that general docker guide needs updating to clarify this for the recent changes to a few of the languages

aram
2022-08-09 13:49
so if not alpine, what would be the recommended base image to use?

matt.fellows
2022-08-09 13:49
Debian or Ubuntu should work just fine

aram
2022-08-09 13:49
ok, will look into it. Thanks @matt.fellows

matt.fellows
2022-08-09 13:49
I'm on mobile, but we build on Linux VMs so whatever the default GH actions Ubuntu image is should work

matt.fellows
2022-08-09 13:50
I'll follow this up tomorrow, thanks for raising

aram
2022-08-09 13:50
just plain, vanilla ubuntu?

matt.fellows
2022-08-09 13:53
obviously with Node on it, it might need the build toolchain too for native dependencies

alison.stuart.contrac
2022-08-09 20:41
has joined #pact-js

matt.fellows
2022-08-10 05:59
I?ve just updated the guidance now. Thanks Arnon!

aram
2022-08-10 15:04
Looks great Matt, thanks :slightly_smiling_face:

tischnerd
2022-08-11 06:49
has joined #pact-js

abudi.hijazi.01
2022-08-11 11:26
Hi, I'm writing pact tests for my team. One of the interactions I'm writing expects a jwt. How do I test that the decoded jwt matches what I expect it to be

matt.fellows
2022-08-11 11:51
howtoauth

2022-08-11 11:51
Approaches to handling authentication in Pact tests: https://docs.pact.io/provider/handling_auth

joel.wochele
2022-08-11 12:53
has joined #pact-js

abudi.hijazi.01
2022-08-11 12:54
I've already read this, it doesn't solve my issue

matt.fellows
2022-08-11 13:00
Right sorry, your question is a bit different

matt.fellows
2022-08-11 13:02
I assume it comes in a header. I think as a general rule, we would recommend excluding this from contract testing. It is usually tested by other means, and is tricky to do in a Pact testt.

matt.fellows
2022-08-11 13:02
I don?t think we have any specific matcher that can extract a JWTs contents and then assert on the contents

matt.fellows
2022-08-11 13:02
(albeit that might be something a Plugin could eventually do, could it @uglyog?)

abudi.hijazi.01
2022-08-11 13:26
Do you think it would be possible for me to create a custom matcher?

abudi.hijazi.01
2022-08-11 13:27
Or can I only use pact matchers

adam.witko
2022-08-11 14:26
Has anyone seen any issues upgrading from v9 to v10, and the TS type changes for customProviderHeaders for the Verifier requires it to now be `customProviderHeaders: { [key: string]: string }` . Not a problem to swap from the v9 array to v10, but this then pumps out an error:

adam.witko
2022-08-11 14:28
The v9 to v10 also states there are no changes but I think this shows there are a couple (providerVersionBranch -> providerBranch is another)

adam.witko
2022-08-11 14:33
`@pact-foundation/pact@10.0.2` `@pact-foundation/pact-core@13.7.1` are the versions for the 2 pact deps

tjones
2022-08-11 14:35
First one is a bug, I think. Can you open an issue on https://github.com/pact-foundation/pact-js-core please

abudi.hijazi.01
2022-08-11 14:36
Another idea i considered was using some sort of of proxy app to decode the jwt

tjones
2022-08-11 14:36
Second one, it looks like those options were independently added to pact-node and pact-js-core, so it would have been missed when the migration guide was written. I?ll make a PR that updates this.

abudi.hijazi.01
2022-08-11 14:37
Also the jwt comes in the body, as it's part of a json response

tjones
2022-08-11 14:38
First one is an easy fix, I think. I don?t think it ever would have worked

adam.witko
2022-08-11 14:41
Sure, will open a bug there. And I get ya about the migration comments, thanks :slightly_smiling_face:

adam.witko
2022-08-11 15:02
Already on it, what a gent @tjones :clap-all: !

tjones
2022-08-11 15:05
It was more fun to fix the bug first :wink:

tjones
2022-08-11 15:05
I?m afraid I?m not a maintainer any more so you?ll have to wait for someone to merge it


adam.witko
2022-08-11 15:17
I can wait a smidge, this was spotted as I was working on some of internal packages using v9 and moved to v10 of pact-js and spotted it. No one is crying for this fix from us other than myself so we can use v10 goodness :slightly_smiling_face:

matt.fellows
2022-08-11 22:44
Can you please explain your scenario in a bit more detail then? If it?s in the body, you might be able to do something. But given the keys will be encoded, we don?t any matchers to decode the key and check the decoded contents so it probably won?t be that helpful

joel.wochele
2022-08-12 06:59
Hi, is it possible to use PactV3 to test GraphQL queries in Pact-JS on the consumer side? According to the https://docs.pact.io/implementation_guides/javascript/docs/graphql (thank you for your effort Matt) this is not possible, but I thought what shouldn't be a problem, is to test the POST method with the plain request body. But as soon as I add a body to the `withRequest` method, I get a 500 from the mock server what makes debugging really hard (pushing https://github.com/pact-foundation/pact-js/issues/909 as it makes it hard to find out whats going on). Is it intended to stick to PactV2 for GraphQL testing or is it possible to create a Pact with a body for the request with PactV3? Just asking here to see if i missed something, otherwise I think I will open a issue with an example.

adam.witko
2022-08-12 10:14
Hey hey has it been spotted that 10.1.0 (similar for all 10.x.x releases) will publish verification results even when `publishVerificationResult` is false :panic-kermit: ?

adam.witko
2022-08-12 10:18
Also, verification fails if there are no pacts to verify when it used to pass with ^9.0.0. The provider does exist, there but given the consumerVersionSelectors there are no pacts to verify yet: ```{ publishVerificationResult: false, provider: 'delivery-promise-service', providerBaseUrl: 'http://localhost:8000', providerVersion: '09fe6815', providerBranch: 'DP-2086-state-handlers-for-rob-contracts', pactBrokerUrl: 'https://pact-broker.dunelm.io/', enablePending: true, consumerVersionSelectors: [ { mainBranch: true }, { deployedOrReleased: true }, { matchingBranch: true } ], customProviderHeaders: { 'x-apigateway-event': '""', 'x-apigateway-context': '""' } }```

joel.wochele
2022-08-12 10:38
Example ```.withRequest({ method: 'POST', path: `/product/graphql`, headers: { 'Content-Type': 'application/json', Accept: "application/json", }, // body: { "query":"{ product { data { idProduct name } } }", "variables": null } // fails // body: MatchersV3.like({ "query":"{ product { data { idProduct name } } }", "variables": null }) // fails })```

matt.fellows
2022-08-12 10:42
Thanks Adam. Could you please raise an issue? We'll get it added to the core so other languages can benefit also

matt.fellows
2022-08-12 10:42
It probably should be an explicit behaviour rather than assumed (it may not be expected to find no pacts)

matt.fellows
2022-08-12 10:43
Umm...no I hope not!

matt.fellows
2022-08-12 10:44
We just need to port the graphql interaction from v2 to v3. Take a look at how it is implemented

yousafn
2022-08-12 10:45
Hey, I can recreate that. I don?t think the option is being passed from pact-js-core to the rust verifier https://github.com/pact-foundation/pact-js-core/blob/c4f60f2e9a4955d744e457c8d47245c3776af2a3/src/verifier/nativeVerifier.ts

matt.fellows
2022-08-12 10:45
There may also be an issue opened for this, and it's possible somebody has uploaded a suggested version of that interface which is just a thin wrapper


yousafn
2022-08-12 10:47
should `opts.publishVerificationResult || false`be set here I would have assumed it would default to not publishing if no value provided ``` if (brokerUrl && opts.provider) { ffi.pactffiVerifierBrokerSourceWithSelectors( handle, brokerUrl, opts.pactBrokerUsername || process.env.PACT_BROKER_USERNAME || '', opts.pactBrokerPassword || process.env.PACT_BROKER_PASSWORD || '', opts.pactBrokerToken || process.env.PACT_BROKER_TOKEN || '', opts.enablePending || false, opts.includeWipPactsSince || '', opts.providerVersionTags || [], opts.providerBranch || '', opts.consumerVersionSelectors ? objArrayToStringArray(opts.consumerVersionSelectors) : [], opts.consumerVersionTags || [] ); }```

yousafn
2022-08-12 10:48
`opts.publishVerificationResult` isn?t passed into when we call `pactffiVerifierSetPublishOptions` ``` // TODO: extract these options into its own subtype, and check keyof if ( opts.publishVerificationResult || opts.providerVersion || opts.buildUrl || opts.disableSslVerification || opts.timeout || opts.providerVersionTags ) { ffi.pactffiVerifierSetPublishOptions( handle, opts.providerVersion || '', opts.buildUrl || '', opts.providerVersionTags || [], opts.providerBranch || '', ); }```

yousafn
2022-08-12 10:50
I?ll get a repro :thumbsup: and will take a look

adam.witko
2022-08-12 10:54
Will raise it now :thumbsup: Where do you want it raising? pact-js, pact-js-core?


yousafn
2022-08-12 10:56
I am going to have to get pact-js-core running locally now, tried to avoid it yesterday, but thankful to Tim for his yak shaving yesterday on getting it running on m1 machines, as I think he has cracked it for me Thanks for the report @adam.witko - happy for you to raise an issue

adam.witko
2022-08-12 10:57
Raise it over in pact-js, yeah?

yousafn
2022-08-12 11:03
yeah pact-js please

yousafn
2022-08-12 11:03
danke

yousafn
2022-08-12 11:04
When Matt is referring to the core, he may be referring to the rust-core rather than pact-js-core. If you raise against pact-js for now, we can sort out any further issues in other repos if req :thumbsup:

yousafn
2022-08-12 11:04
thx again fella

adam.witko
2022-08-12 11:10
Awesome thanks both :slightly_smiling_face:

matt.fellows
2022-08-12 11:12
ok ignore this

matt.fellows
2022-08-12 11:12
When traveling to Boston, I did a whole refactor of the argument mapping for the FFI. It was beautiful, it was great, it was merged into master??..not

matt.fellows
2022-08-12 11:13
When I went back in just now and saw the code, I was a little confused. And realised I never merged it (probably because I was on a long haul flight without wifi and so couldn?t get a GH build to verify said work)

matt.fellows
2022-08-12 11:14
I?ve just rebased on master - because of all of the lovely contributions over the past few days - and this PR should have the fix: https://github.com/pact-foundation/pact-js-core/pull/391

matt.fellows
2022-08-12 11:14
(as well as improved validation)

matt.fellows
2022-08-12 11:15
It?s quite possible this will result in some upstream issues in Pact JS, because it does some additional validation on the arguments that may not have been there before. But they should be useful validations, catching potentially hidden bugs in the config

matt.fellows
2022-08-12 11:23
yep, raise with JS for now and we?ll always move it to the right place. Your raising it is the key thing!

yousafn
2022-08-12 11:26
:joy: thanks matey! I might have a look at triggering an automatic build of pact-js with the updated pact-js-core dependencies on release, so save us having to manually update. I did take a look but couldn?t see anything already there

yousafn
2022-08-12 11:36
> It was beautiful, it was great, it was merged into master??..not This made me laugh :joy: we?ve all got _this_ kind of story

matt.fellows
2022-08-12 11:41
Gah! release failed because we don?t allow ?refactor? as a changelog note. hmmm

yousafn
2022-08-12 11:44
yarrrg, @tjones this is one of those issues with the release process that irked me, I was trying to find you an example before I think a `chore: fdfsd` or `docs: foo` might work, if you update the release process docs :sweat_smile: (even tho the message says fix/feat) Or feat to bump a minor a version change in case the merge does cause further issues (which we want to iron out) I?ve never checked out to cause a breaking change bump in a commit message yet, I am going to go find out now :sweat_smile:

yousafn
2022-08-12 11:45
ahhh nice just seen your addition to the package.json entry :thumbsup:

tjones
2022-08-12 11:53
I really really want my contribution to pact-js to be the release notes practice. We can have really nicely written changelogs if you follow the guidelines in CONTRIBUTING :heart:

tjones
2022-08-12 11:55
Why do you want to release something that isn't a fix or feat?

yousafn
2022-08-12 12:02
This is good, nice one, you have left a good legacy :slightly_smiling_face: https://github.com/pact-foundation/pact-js/blob/master/CONTRIBUTING.md#release-notes The times I have come about it, is when I have been doing tweaks to CI pipelines and the npm builds, say to reduce the size of the compiled build, or npm-ignoring files. Refactors unless they aren?t breaking, wouldn?t allow a release as there wouldn?t be release notes generated, and the refactor might result in a smaller bundle.

yousafn
2022-08-12 12:03
> Examples of `fix` include bug fixes and dependency bumps that users of pact-js may want to know about. Is there bug fixes/dep updates, we wouldn?t want users to know about? as it says _may_ here. wonder what they would be classified as `chore (deps):` ?

yousafn
2022-08-12 12:06
> It?s quite possible this will result in some upstream issues in Pact JS, because it does some additional validation on the arguments that may not have been there before. But they should be useful validations, catching potentially hidden bugs in the config Hmm, so in this instance, would be want a minor bump on pact-js when consuming pact-js-core, but pact-js-core went out as a minor, which would maybe force consumers of it to think it wouldn?t have potential regressions. idk :smile:

matt.fellows
2022-08-12 12:11
> Why do you want to release something that isn?t a fix or feat? It?s an important refactor, why shouldn?t I be able to release a refactor?

matt.fellows
2022-08-12 12:11
the refactor might add better performance, for example

matt.fellows
2022-08-12 12:13
> Hmm, so in this instance, would be want a minor bump on pact-js when consuming pact-js-core, but pact-js-core went out as a minor, which would maybe force consumers of it to think it wouldn?t have potential regressions. idk the types are the same, but the validation under the hood has been improved as has the way the properties are wired in. It?s a potential behavioural breaking change, but we don?t have a regression suite thorough enough to catch that sort of thing

matt.fellows
2022-08-12 12:13
So I?m just? staying vigilant :batman:

matt.fellows
2022-08-12 12:15
btw Tim, we have these in the notes that I wrote yeeeeeeeears ago: ```### Commit messages Pact JS uses the [Conventional Changelog](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md) commit message conventions. Please ensure you follow the guidelines, as they help us automate our release process. You can take a look at the git history (`git log`) to get the gist of it. If you have questions, feel free to reach out in `#pact-js` in our [slack community](https://pact-foundation.slack.com/). If you'd like to get some CLI assistance, getting setup is easy: ```shell npm install commitizen -g npm i -g cz-conventional-changelog ``` `git cz` to commit and commitizen will guide you.``` I actually don?t use that anymore, but keen to know if you do?

evert.vanloo
2022-08-12 12:16
has joined #pact-js

jors.matthys
2022-08-12 13:27
has joined #pact-js

joel.wochele
2022-08-12 13:41
Thank you for the response. Unfortunately I could not find the question mentioned. Acording to the graphql support, I will try to have a look over the weekend. But you would say checking the plain body should be possible? Are there some eaxamples for PactV3 that would show this (examples in `https://github.com/pact-foundation/pact-js/tree/573b00d5def4362914e885c40803a510ad249575/src/v3/pact.ts` don't use body in withRequest)? Or should I create a issue with a code example?

tjones
2022-08-12 14:06
Nope, I never have used that- I don't even have git aliases (no judgement to people who do- I have just never found them useful). On the ?well, this refactor brings a performance increase?- great! Then it is a `fix`, as it fixes something that users want to know about. The point of the commit message guidelines is to be intentional about what goes in the release notes. As a user, it's frustrating to read empty change logs if you're trying to work out what changed- so I forbade them in the release scripts.

tjones
2022-08-12 14:09
If there's no changes that users would want to know about, why are you releasing?

tjones
2022-08-12 14:12
Similarly, the fix and feat commit messages have explicit guidelines, because it's more helpful to have the release notes have clear information on what changed from a user perspective, rather than a code perspective.

adam.witko
2022-08-12 15:55
https://github.com/pact-foundation/pact-js-core/issues/392 created this to fix a validation issue for ^10.x.x of pact-js (13.7.3 of pact-js-core) where the validation for customProviderHeaders fails and doesn't match the types. I think there may be other issues given the test coverage around validateOptions.ts, but I have to finish up for the day so I don't have the time to look at it now @matt.fellows

ricardo.maury
2022-08-12 18:34
has joined #pact-js

matt.fellows
2022-08-13 00:16
Thanks Adam - appreciate your patience (and determination) on this. I?ve just merged and will release another patch now.

matt.fellows
2022-08-13 00:58
Yes in this case it just so happened a refactor fixed an underlying bug, but it was made for other reasons (there were numerous TODOs piling up that eventually got to me :rolling_on_the_floor_laughing:) I don't think we should avoid releasing code because there is no user facing impact for many of the same reasons you should practice continuous delivery, but I do think we should make it clear what is being released, and the wonderful improvements you made to that process help Commit messages are as much for maintainers as they are users of the software.


tjones
2022-08-13 05:30
Yes. The thinking was to force the maintainer to make sure there are release notes, not to prevent releases. A few times I would make commits just for the release notes, which was annoying but still meant that the release notes were high quality

tjones
2022-08-13 05:31
Release-please solves this really nicely- it lets you override the release notes implied by the commits from a PR, which is great because you don't have to squash commits or ask a first time contributor to rewrite their messages

tjones
2022-08-13 05:32
Blank release notes are pretty bad for trust when I'm looking at a new project

matt.fellows
2022-08-13 06:04
I agree. I'll check out release please, that sounds handy for those times

tjones
2022-08-14 23:57
Release please is awesome. It _also_ won?t release if there would be no release notes :wink:

tjones
2022-08-14 23:59
The way it works is it makes a PR with the changelog and bump commit, then keeps that PR up to date as more commits get added. Once the PR is merged, it tags that commit as the release and runs the scripts. This prevents the race condition problem that we had - and means releases won?t fail (as long as the build is repeatable and not brittle)

prateekm33
2022-08-15 00:46
has joined #pact-js

prateekm33
2022-08-15 01:17
hello! not sure if this has been asked here before already, but i?ve been having issues running consumer tests with PactV3. i?ve set up my test file as such: ```const provider = new PactV3({ consumer, provider, dir, port: 1234 }) describe('test 1', () => { test('should pass', () => { provider .given('valid user session') .uponReceiving('request') .withRequest({ method: 'POST', path: '/my-url', headers: { custom_header }, body: reqBody }) .willRespondWith({ status: 200, headers: reponseHeaders, body: like(exampleBody) }) await provider.executeTest(async mockService => { myApi.configureUrl(mockService.url) const apiResp = await http://myApi.post({ headers: { custom_header }, data: reqBody, }) }) }) })``` *however*, the above test fails with `The following request was expected but not received` and then it displays the request that I have defined under `withRequest` i?m not sure what setup i got wrong

tjones
2022-08-15 01:43
The error message means that your request isn't being sent by your code

tjones
2022-08-15 01:44
One problem is that your test has `await` but no `async`, so it's not returning a promise

tjones
2022-08-15 01:44
Replace `await provider.executeTest` with `return provider.executeTest`

tjones
2022-08-15 01:45
Also, it's good practice to assert that your API call returns what you think it does, which you can do with an `expect` call. See the examples in the documentation.

tjones
2022-08-15 01:48
(that's not the problem, though). I suspect the problem is that you're not waiting for that promise. However, if you're still having issues after you've changed the `await` for `return`, then probably your `http://myApi.post` is not sending the request you think it is.

prateekm33
2022-08-15 02:00
my mistake, i type the above by hand. i do have async in the test

tjones
2022-08-15 02:00
can you please share the actual code?

prateekm33
2022-08-15 02:01
the above is as close to the actual code as i am permitted to share (NDA)

prateekm33
2022-08-15 02:01
i have also confirmed that `http://myApi.post` is indeed making a request to the configured url

prateekm33
2022-08-15 02:01
the response that is returned however is not something i recognize

tjones
2022-08-15 02:02
Ok. I can't help you other than tell you that the error message means that your request is not being received by the mock server. Either you're not sending it, or it's not going to the right place, or you are sending it, but it is not what you set up in the test, or your test isn't waiting for the request to be sent before asking pact if it was sent.

tjones
2022-08-15 02:03
> the response that is returned however is not something i recognize What is the response? Is it a 500? Pact will return 500 if it gets a request it wasn't expecting.

prateekm33
2022-08-15 02:03
how do i confirm that the mock server is actually live and receiving requests? am i able to ping it mid-test or some other method?

tjones
2022-08-15 02:04
You don't need to do that.

prateekm33
2022-08-15 02:04
this is what the returned response from the api looks like ```{ status: [Function: status], ok: true, get: [Function: mockConstructor] { _isMockFunction: true, getMockImplementation: [Function], mock: [Getter/Setter], mockClear: [Function], mockReset: [Function], mockRestore: [Function], mockReturnValueOnce: [Function], mockResolvedValueOnce: [Function], mockRejectedValueOnce: [Function], mockReturnValue: [Function], mockResolvedValue: [Function], mockRejectedValue: [Function], mockImplementationOnce: [Function], mockImplementation: [Function], mockReturnThis: [Function], mockName: [Function], getMockName: [Function] }, toError: [Function: mockConstructor] { _isMockFunction: true, getMockImplementation: [Function], mock: [Getter/Setter], mockClear: [Function], mockReset: [Function], mockRestore: [Function], mockReturnValueOnce: [Function], mockResolvedValueOnce: [Function], mockRejectedValueOnce: [Function], mockReturnValue: [Function], mockResolvedValue: [Function], mockRejectedValue: [Function], mockImplementationOnce: [Function], mockImplementation: [Function], mockReturnThis: [Function], mockName: [Function], getMockName: [Function] } }```

prateekm33
2022-08-15 02:04
i?m using `superagent` to make requests

tjones
2022-08-15 02:05
Well. This is why we ask for the actual test code. That is a mock provided by something other than pact. Looks like Jest, probably.

tjones
2022-08-15 02:05
Also, you definitely don't want to send requests with `superagent`. You want to send requests with the code that is under test.

tjones
2022-08-15 02:05
Otherwise you're not testing anything.

prateekm33
2022-08-15 02:06
in the test i am calling the apiclient that we have defined. under the hood, the api client is calling `superagent`

tjones
2022-08-15 02:06
Something is mocking your API layer, and you're not really sending a post request.

tjones
2022-08-15 02:07
Ah, apologies. I was thinking of `supertest`. I guess `superagent` is a regular http framework.

prateekm33
2022-08-15 02:07
ok, i?ll look into that. this test is being run as a standalone test. not sure if jest automagically mocks http requests

tjones
2022-08-15 02:07
it doesn't.

prateekm33
2022-08-15 02:07
then i am stumped :sweat_smile: . we?re not mocking http calls in this test

tjones
2022-08-15 02:08
You're definitely mocking something - that's a mock object that you posted

tjones
2022-08-15 02:08
have a look in your global jest setup files

prateekm33
2022-08-15 02:08
will see what i can find

tjones
2022-08-15 02:08
Sorry I can't be more helpful.

prateekm33
2022-08-15 02:09
all good, this is good enough direction for now. thanks! will explore and let you know if i get anywhere

tjones
2022-08-15 02:09
My guess is somewhere you have something like `jest.mock('superagent')`

tjones
2022-08-15 02:10
> i have also confirmed that http://myApi.post is indeed making a request to the configured url I would guess that you confirmed that your code is being called, but not that it actually is making the request

prateekm33
2022-08-15 02:21
thanks for that direction. that was the issue. `superagent` was being mocked by `jest` automatically because we have a `___mocks___` directory where a custom implementation of `superagent` was defined. just added `jest.unmock('superagent')` to the pact test file and looks like the request is being made as expected

tjones
2022-08-15 02:33
Awesome! In general, I think it's risky to mock your http framework, because you can't check that you're invoking it correctly. If you need to mock the API for unit tests, I would mock `myApi` instead - then you can use pact to ensure that the mock objects that you're using in your unit tests can actually be received by your API.

tjones
2022-08-15 02:34
You can actually use `stripMatchers` to remove the matchers from the pact expectation and use the exact same object in your mock responses :raised_hands:

tjones
2022-08-15 02:37
so you have something like: pact test: ```assert that myApi.createUser({ name: "foo" }) calls with the expected request the expected response is unmarshalled into a returned user object like { ...whatever the user object is }``` Mocks: ```when myApi.createUser({ name: "foo" }), then return { ...whatever the user object is }```

matt.fellows
2022-08-15 02:44
On the ?how can we make this easier for users? front, I wonder if we could detect the use of common tools (like supertest, or jest mocks) and suggest a fix?

matt.fellows
2022-08-15 02:45
We could also have a troubleshooting guide, but in my experience nobody really looks at these (otherwise Tim wouldn?t be an expert in explaining how promises work)

tjones
2022-08-15 02:45
I'm not sure how we could do that. I've wondered about `expect(responseObject).toMatchPactExpectations()` which just does a `stripMatchers`, but I think that might cause more confusion

prateekm33
2022-08-15 02:55
ooh that `stripMatchers` method sounds like a useful one that i am definitely going to use. didn?t know that existed and i just manually stripped them lol. thanks!

prateekm33
2022-08-15 02:58
where is that method defined? is that on the matcher object?

tjones
2022-08-15 02:59
Apologies, it's called extractPayload

prateekm33
2022-08-15 03:00
gotchya, no worries! i was just about to ask that too. found the github commit for that particular conversation regarding renaming it

prateekm33
2022-08-15 03:02
just curious, does `extractPayload` recursively strip matchers?


ahmed.fahmy
2022-08-15 09:10
has joined #pact-js

tpaktopsp
2022-08-15 18:47
has joined #pact-js

joel.wochele
2022-08-16 06:31
Ah, I'm quite new to Pact and wasn't aware of the board. Thank you for the link and with it the PoC.

tpaktopsp
2022-08-16 07:59
Is `V3Interaction` compatible with `ApolloGraphqlInteraction`? I?m getting type errors: ```Type 'ApolloGraphQLInteraction' is not assignable to type 'V3Interaction'. Types of property 'uponReceiving' are incompatible. Type '(description: string) => ApolloGraphQLInteraction' is not assignable to type 'string'.ts(2322)```

tpaktopsp
2022-08-16 08:15
After fiddling with it a bit more it seem that the main problem is types of query object. I tried to manually convert `ApolloGqlInteraciton` to V3 interface but `query` there is a string while `query` in V3 is a record. Hm?

matt.fellows
2022-08-16 08:32
No, we haven't added graphql to the new v3 interface just yet. See the migration notes. Somebody asked about this in the channel yesterday. It should be a simple enough PR to support. Somebody helpfully shared some code on http://pact.canny.io for it you could pull in and/contribute if you're up for it

tpaktopsp
2022-08-16 08:32
I think I already made required changes - can PR it later today

tpaktopsp
2022-08-16 08:32
Its pretty simple as far as I understand

tpaktopsp
2022-08-16 08:33
```const interaction = new ApolloGraphQLInteraction() .uponReceiving(interactionDescription) .withRequest({ path: '/graphql', method: 'POST', headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json', }, }) .withOperation(getOperationName(query)) .withQuery(printQueryToString(query)) .withVariables(variables) .willRespondWith({ status: 200, body: { data: respondWith, }, }) .json(); return { states, uponReceiving: interaction.description, withRequest: { method: interaction.request?.method, path: interaction.request?.path, query: {}, // this is not used on gql interactions body: interaction.request?.body, headers: interaction.request?.headers, }, willRespondWith: { status: interaction.response?.status, body: interaction.response?.body, headers: interaction.response?.headers, }, };```

tpaktopsp
2022-08-16 08:37
kinda took slighly different approach - we have wrapped pack in a think layer ourselves which provides GQL wrapper. So I only need to change wrapper in one place instead of creating full blown separate class. I think.. still testing it

julian.schmidt
2022-08-16 09:03
has joined #pact-js

jack340
2022-08-16 09:11
has joined #pact-js

tjones
2022-08-16 09:28
Nice work. Probably instead of doing this: ``` method: interaction.request?.method,``` You might want to confirm whether the `request` is there and throw an error if it is not - otherwise users might get surprise results if they use the DSL incorrectly.

g.varga
2022-08-16 11:55
has joined #pact-js

matt.fellows
2022-08-16 12:05
nah all good, that probably should be on the Pact JS repo given it?s scoped there and not ecosystem wide. It took me a bit to find also

heera
2022-08-16 14:17
Hi Team, I am using `jest` with `pact-js` and found when I try to run provider tests which has a wrong mapping with consumer contract file or contract file does not exist. It still shows `Test Suites` and `Tests` as passed. Of-course it does not show pact execution status (interaction, provider state, request, response) in run, but I was expecting `Test Suites` and `Tests` status as failed. Is there a way to achieve it? tried to see the logs as well but did not found any Error level logs there.

heera
2022-08-16 14:25
Hi Team, I have one more query to ask here. I wanted to validate one response attribute which is like `"completed": "2022-01-21T07:58:42.196238Z",` I used matcher like `completed: Matchers.iso8601DateTimeWithMillis("2022-01-21T07:58:26.251019Z"),` to validate it. In some cases it gives me value `null` instead of date format string value. I know in pact we should try to get that state in provider states if we want to check exact case. still looking if there is another way to validate it.

lnthai2002
2022-08-16 15:02
has joined #pact-js

sarunas.kavaliauskas
2022-08-16 19:15
has joined #pact-js

matt.fellows
2022-08-17 01:41
Which version are you on Heera? 10.x.x definitely fails if there are no pacts found, because this was raised as a feature request recently

matt.fellows
2022-08-17 01:41
I think you?ve answered your own question, but see also https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes

heera
2022-08-17 05:35
@matt.fellows I am on `"version": "10.1.1"`

matt.fellows
2022-08-17 05:44
can you please share your code?


matt.fellows
2022-08-17 05:55
Thanks, looks like it might be a bug. Could you please raise an issue at https://github.com/pact-foundation/pact-js/issues/new/choose ?

heera
2022-08-17 05:56
sure, I will raise it today. thanks for your help @matt.fellows

tbansal
2022-08-17 10:30
has joined #pact-js

dekkofilms
2022-08-17 21:14
has joined #pact-js

nirajlalr
2022-08-18 09:46
has joined #pact-js

jon669
2022-08-18 11:14
has joined #pact-js

heera
2022-08-18 11:33
Hi Team, Today when I am trying to do `Provider verification` (fetching contracts from pact broker) I gets error message: *ERROR ThreadId(11) pact_verifier: Failed to load pact - Could not load pacts from the pact broker 'https://rain.pactflow.io' - ContentError("Request to pact broker URL 'https://rain.pactflow.io/pacts/provider/ATP_Provider/for-verification' failed - HTTP status client error (400 Bad Request) for url (https://rain.pactflow.io/pacts/provider/ATP_Provider/for-verification)")* To publish the contract I use command `"publish:pact": "pact-broker publish ./pacts --consumer-app-version 1.0.1 --auto-detect-version-properties --broker-base-url=https://**.http://pactflow.io --broker-token=**"` I provide these options to Verifier `const opts = {` `provider: "MY_Provider",` `logLevel: process.env.LOG_LEVEL,` `providerBaseUrl: process.env.BASE_URL,` `stateHandlers: {` `"when no auth passed": () => {` `return Promise.resolve("no token needed");` `},` `},` `pactBrokerUrl: process.env.PACT_BROKER_URL,` `pactBrokerToken: process.env.PACT_BROKER_TOKEN,` `publishVerificationResult: true,` `consumerVersionSelectors: [` `{` `consumer: "10.0.1",` `},` `],` `providerVersion: "1.0.0",` `};` Any clue what I am doing wrong here.

yousafn
2022-08-18 11:44
You are publishing a contract version with a consumer version of `1.0.1` and using the consumerVersionSelector of `10.0.1` in your provider verification task

heera
2022-08-18 11:47
ohh my bad, @yousafn you found it very fast, thanks for pointing it.

yousafn
2022-08-18 11:47
I believe the `consumer` key should have a value which matches the name of the consumer you are interested in. and you should have a key for `version` with `1.0.1` looking at https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors

yousafn
2022-08-18 11:47
but I may be wrong on that, no worries Heera

matt.fellows
2022-08-18 12:05
Can I ask why you're using the consumer version here? It's supported for edge cases but I think it will make your build pipelines very fragile and high maintenance, having to know the versions. Branches and environments are the recommendation

yousafn
2022-08-18 12:11
:point_up: There is no branch, nor tag applied at the point of publishing. The consumer property should be the name of the consumer you are targeting, and you required to provide one of the properties in this list, alongside consumer, be it `branch` , `tag` etc

yousafn
2022-08-18 12:12
More info on the recommended setup :thumbsup: https://docs.pact.io/provider/recommended_configuration

yousafn
2022-08-18 12:14
> you should have a key for `version` with `1.0.1` The docs don't actually show you can specify the consumer name with a version number, or that `version` is a supported key in `consumerVersionSelectors`

tjones
2022-08-18 14:26
doesn?t `--auto-detect-version-properties` apply the branch?

yousafn
2022-08-18 14:30
ahh yes https://github.com/pact-foundation/pact_broker-client#publish ``` [--auto-detect-version-properties], [--no-auto-detect-version-properties] # Automatically detect the repository branch from known CI environment variables or git CLI. Supports Buildkite, Circle CI, Travis CI, GitHub Actions, Jenkins, Hudson, AppVeyor, GitLab, CodeShip, Bitbucket and Azure DevOps.``` just checking in the code now, because I don't think it picks up a version, just branch, going by that description. could that be confusing. Would `--auto-detect-branch-properties` be more appropriate, or for it to also include/infer a version property (say from a SHA), unless `--consumer-app-version` is explicitly stated.

yousafn
2022-08-18 14:34
@heera if you try updating your configuration to one of the recommended https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors#recommended You should find success :slightly_smiling_face: - I wasn't able to pull down a pact with your setup above with the consumer version selector, but after updating to one of the above setups I was able to

tjones
2022-08-18 14:47
I thought auto-detetect-version-properties picked up the sha as the version if you didn?t specify it - but if the code doesn?t say that then I must be mistaken

michael.birchmeier
2022-08-18 19:27
has joined #pact-js

yousafn
2022-08-18 20:17
So ?consumer-app-version always needs to be set, even with the old and new way of publishing pacts. There is a version_required value that gets calculated but doesn?t look to be used in the new way of publishing unless I am mistaking. You can set the old way with a feature flag. In both cases, I am required to pass in the consumer app version flag Just replying on my phone but will pull up some code refs later against the pact broker client repo

jwang
2022-08-18 21:07
has joined #pact-js

msiyaj1
2022-08-18 22:03
has joined #pact-js

tjones
2022-08-18 22:30
oh right. In that case, I think the parameter name is a bit misleading

ben.hansen
2022-08-19 00:44
has joined #pact-js

heera
2022-08-19 03:37
@yousafn you are correct, you need to use it because its required `No value provided for required options '--consumer-app-version',`

heera
2022-08-19 03:41
As I am not using CI now, It worked me with this minimal configuration, publish contract command `pact-broker publish ./pacts --consumer-app-version 1.0.1 --branch branch1 --broker-base-url=https://**.http://pactflow.io --broker-token=**` and in provider test `consumerVersionSelectors: [` `{ consumer: "Order_Consumer", branch: "branch1" },` `],`

heera
2022-08-19 03:41
Thanks everyone!

heera
2022-08-19 03:52
@matt.fellows I logged here https://github.com/pact-foundation/pact-js/issues/927 for for being late..

abudi.hijazi.01
2022-08-19 11:36
In our JS consumer we add a timeout in our http request, is there a way to include this in a pact test? If I leave the timeout the pact test fails because of an "After each hook" error. And if it is commented out the test passes

lottie.kett
2022-08-19 12:08
has joined #pact-js

yousafn
2022-08-19 12:15
Can you share some example code. > In our JS consumer we add a timeout in our http request What do you mean exactly by this? HTTP clients tend to have a default timeout value, do you mean you have modified this to be something different than the default? Test frameworks normally have the ability to set timeouts, which test framework are you referring to?

abudi.hijazi.01
2022-08-19 13:54
Sure. The code below is the method that sends the HTTP request. This method is being called in the pact test to get the actual repsonse. ```const response = await fetchRequest( this.resolveUri(config.SSO_TOKEN_PATH), { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", }, body: createFormBody(reqBody), timeout: config.API_DEFAULT_TIMEOUT, } );``` `config.API_DEFAULT_TIMEOUT` is set to `60000` . When I leave that timeout in, the pact test doesn't work

abudi.hijazi.01
2022-08-19 13:55
Is there a way to add a timeout in the pact test interaction, so that the mock API can expect this timeout

yousafn
2022-08-19 14:00
pass it in the config object when you instantiate your client, or set a timeout in your unit test framework

paul.lynn
2022-08-19 14:18
has joined #pact-js

abudi.hijazi.01
2022-08-19 14:38
Turns out I understood this timeout thing wrong, basically the timeout property specifies the time that the request must be completed in before being terminated. I don't know why this would effect the pact test though. When the property is not there the pact test works and passes, and when it is there the pact test fails

yousafn
2022-08-19 14:40
> Turns out I understood this timeout thing wrong, basically the timeout property specifies the time that the request must be completed in before being terminated. Correct > I don't know why this would effect the pact test though. When the property is not there the pact test works and passes, and when it is there the pact test fails If you can share your test code, it would help, otherwise its hard to guess

yousafn
2022-08-19 14:40
it could be any number of things, is a pact file being generated when the test does pass?

abudi.hijazi.01
2022-08-19 14:40
Yes

yousafn
2022-08-19 14:43
Ok well in order to help it would be useful to follow the guide for asking for help https://docs.pact.io/help/how_to_ask_for_help#4-ask-a-good-question ? A brief description of what you're trying to achieve, what your expected outcome is, and what the actual behaviour is. ? The relevant language and versions of the software you are using. ? Details of the environment you're using (Mac/Window/Linux, Docker). ? Example code. ? Any relevant logs. > If you're trying to demonstrate a problem or diagnose a bug, the best possible thing you can do is provide a https://stackoverflow.com/help/minimal-reproducible-example that doesn't contain any organisational confidential information.


abudi.hijazi.01
2022-08-19 14:44
```mockProvider.addInteraction({ state: "", uponReceiving: "", withRequest: { method: "POST", path: "/token", headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", }, body: request, }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=UTF-8", }, body: like(response), }, }); const expectedToken= jwtBody const actualToken = await retrieveToken(session); // Assert - did we get the expected response assert.deepStrictEqual( actualIdToken, expectedIdToken );```

abudi.hijazi.01
2022-08-19 14:44
This is the code, above the interaction declaration is just variables being added

yousafn
2022-08-19 14:46
I can't run that and reproduce the problem, and it doesn't contain the full test, I don't know what version of pact-js you are using

abudi.hijazi.01
2022-08-19 14:47
I've looked at the logs, the request is matched, and the response is sent back, but when i console log the response it's null

yousafn
2022-08-19 14:47
I can't see how your client is being instantiated. If you can imagine if you were on the other end buddy trying to help someone out

yousafn
2022-08-19 14:48
where are your passing in `config.API_DEFAULT_TIMEOUT`

abudi.hijazi.01
2022-08-19 14:50
So the method `retrieveToken` imports the config file and makes the HTTP request from there, the one I sent earlier

tjones
2022-08-19 15:15
It?s not possible to reproduce this from the examples you?ve sent above.

tjones
2022-08-19 15:16
> I?ve looked at the logs, the request is matched, and the response is sent back, but when i console log the response it?s null If this is the case, then I expect the bug is in the calling code, not pact.

tjones
2022-08-19 15:19
To reproduce the problem, we?d need the implementation of `fetchRequest` (and several other functions and variables). If you can?t compile the snippets on their own, neither can we.

tjones
2022-08-19 15:20
> If I leave the timeout the pact test fails because of an ?After each hook? error. What is the error? This doesn?t sound like it is coming from pact. What after each hooks are you using?

tjones
2022-08-19 15:21
Can you tell us what versions of pact dependencies you are using?

abudi.hijazi.01
2022-08-19 15:42
pact version: `"@pact-foundation/pact": "^10.1.1"` After each error message: ```2) Pact Tests "after each" hook for "user is authenticated, and sends a valid body": Error: Error in native callback at Object.mockServerMismatches (node_modules\@pact-foundation\pact-core\src\consumer\index.ts:94:13) at Pact.verify (node_modules\@pact-foundation\src\httpPact\index.ts:202:39) at Context.<anonymous> (tests\contract\contractTesting.spec.js:20:32) at processImmediate (node:internal/timers:466:21)```

abudi.hijazi.01
2022-08-19 15:48
I can't share my code, as it's company code, I've shared as much as I can. If you cannot help me, then I understand and thank you for your help

tjones
2022-08-19 23:12
Well, that definitely looks like a pact problem :thinking_face:

duynguyenptithcm
2022-08-20 07:22
has joined #pact-js

gaudenz.halter
2022-08-22 07:52
has joined #pact-js

brendan.j.donegan
2022-08-22 08:10
does anyone know should `async` state handler functions be supported in theory? a team has recently upgraded their node version and broken the verification. when i make the state handler function that was async not async (hardcode the needed response) then it works ok

matt.fellows
2022-08-22 08:25
Async should definitely work.

matt.fellows
2022-08-22 08:25
What version?

brendan.j.donegan
2022-08-22 08:34
it was 9.12.1 which i know is really old but even upgrading didn't work

brendan.j.donegan
2022-08-22 08:34
maybe there's something funky with the API we're using to make the network request...

brendan.j.donegan
2022-08-22 08:35
i'll look into that

matt.fellows
2022-08-22 08:36
:+1: let us know if you can share.

brendan.j.donegan
2022-08-22 08:38
:facepalm: *why* did I not check this first...

brendan.j.donegan
2022-08-22 08:38
i'm going to say it's because it was Friday

brendan.j.donegan
2022-08-22 08:39
yep, body is no longer wrapped in 'res' in this node version

matt.fellows
2022-08-22 08:47
Ah, do you mean outside of Pact?

brendan.j.donegan
2022-08-22 08:50
we're using chai.request to make the network request

brendan.j.donegan
2022-08-22 08:50
simply it's response.body now instead of response.res.body

brendan.j.donegan
2022-08-22 08:52
also to be honest this was made doubly hard to debug by the fact that the stupid provider returns a *500* when there's no valid login token

matt.fellows
2022-08-22 08:56
:rolling_on_the_floor_laughing:

abudi.hijazi.01
2022-08-22 10:21
Is there a way to cover a range of expected status code responses? Or can you only expect an exact status code. This would be really useful for all status codes >=400

abudi.hijazi.01
2022-08-22 10:21
This has been solved, it wasn't a pact issue

abudi.hijazi.01
2022-08-22 10:22
Thanks for your help anyways

yousafn
2022-08-22 10:22
Cheers for coming back to us chap, glad you got sorted

matt.fellows
2022-08-22 10:33
It?s available in the next specification version (4) but Pact JS is yet to expose that matcher: https://github.com/pact-foundation/pact-specification/issues/68

harold.robson
2022-08-22 13:07
has joined #pact-js

bentzion.schochet
2022-08-22 13:27
has joined #pact-js

mat.delong
2022-08-22 14:03
has joined #pact-js

harold.robson
2022-08-23 09:01
Hello does anyone know of an existing docker image that already has node and python to run the PACT tests?


harold.robson
2022-08-23 09:14
I was looking t the bottom of the page where it says Here is an example NodeJS container that can be used as a reference to create a working container for your example:

harold.robson
2022-08-23 09:15
Is that available as a precompiled image having both node and python installed?

matt.fellows
2022-08-23 09:15
I don't think so

harold.robson
2022-08-23 09:16
Thanks Matt

harold.robson
2022-08-23 09:24
I am just curious how does the PACT JS package make python calls?

mat.delong
2022-08-23 09:27
@mat.delong has left the channel

matt.fellows
2022-08-23 09:47
It doesn't. But a lot of JS tooling uses node gyp to compile native dependencies and that needs python. Pact has a C++ native dep and uses that package

volker.wengert
2022-08-23 10:59
has joined #pact-js

sathish.sundararajan
2022-08-23 19:32
has joined #pact-js

patrick.lu
2022-08-24 02:12
has joined #pact-js

krishna.cv
2022-08-24 04:38
has joined #pact-js

ravishankar.emc
2022-08-24 06:00
has joined #pact-js

ravishankar.emc
2022-08-24 06:05
Hello team, I am looking for some help to add contract testing on our application. Our microservices communicates using internal API. If I call /api/v1/CreateSession it internally calls another private API /api/private_v1/user/<id>. How to design consumer and provider tests for the same. Any Examples please. Thanks


matt.fellows
2022-08-24 06:50
You would usually stub downstream systems, and then write pacts for them

matt.fellows
2022-08-24 06:50
Also covered in this AMA: https://docs.pact.io/help/amas#apac-1

alan.zhu
2022-08-24 08:54
has joined #pact-js

abudi.hijazi.01
2022-08-24 13:56
In one of my interactions, I stated that the Mock API doesn't return any headers in its response. See below: ``` mockProvider.addInteraction({ state: "", uponReceiving: `An invalid POST request to ${Config.config.SSO_TOKEN_PATH}. Returns 400 status and "invalid_grant_type" message`, withRequest: { method: "POST", path: "/v1/api/token", headers: { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", }, body: createFormBody(request), }, willRespondWith: { status: 400, body: { error: "unsupported_grant_type", error_description: "Invalid grant type INCORRECT_GRANT_TYPE, expected authorization_code", error_uri: null, }, }, });``` But for some reason, when the pact is generated, a header is added in the interaction in the API response ```{ "description": "An invalid POST request to /v1/api/token. Returns 400 status and \"invalid_grant_type\" message", "request": { "body": "grant_type=INCORRECT_GRANT_TYPE&client_id=34343433434&redirect_uri=REDIRECT_URL&code=AUTH_CODE&code_verifier=VERIFIER", "headers": { "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8" }, "method": "POST", "path": "/v1/api/token" }, "response": { "body": { "error": "unsupported_grant_type", "error_description": "Invalid grant type INCORRECT_GRANT_TYPE, expected authorization_code", "error_uri": null }, "headers": { "Content-Type": "application/json" }, "status": 400 } }``` Any ideas on how to stop this from happening

nabil.bourenane
2022-08-24 14:19
has joined #pact-js

tjones
2022-08-24 22:16
Why do you want this? Content-Type is strongly recommended by RFC 7231: > A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender

tjones
2022-08-24 22:17
An aside - this statement isn?t quite right: > I stated that the Mock API doesn?t return any headers in its response. You?ve stated that your client doesn?t care about the headers, not that the response has no headers.

tjones
2022-08-24 22:18
Pact is about verifying that the server sends what you need - see https://docs.pact.io/getting_started/matching/gotchas#pact-follows-postels-law for the rationale

tjones
2022-08-24 22:20
I see why you might be surprised that content-type is required because you didn?t specify that your client needs it - but since you also specified a JSON payload, Content-Type should at least be some form of `application/json`. Is there some reason you need it not to be?

ami.ta
2022-08-25 06:05
has joined #pact-js

me1001
2022-08-25 07:24
has joined #pact-js

nidzgorskiadrian
2022-08-25 08:05
has joined #pact-js

dealandi
2022-08-25 11:50
has joined #pact-js

jreynolds
2022-08-25 12:44
has joined #pact-js

josh.steffensmeier
2022-08-25 13:18
has joined #pact-js

mhtkandpal10
2022-08-26 11:29
has joined #pact-js

edouard.lopez
2022-08-26 15:16
Hello, in https://github.com/pact-foundation/pact-workshop-js#publish-contracts-from-consumer of the JS workshop, you use `npx @pact-foundation/absolute-version` , e.g.: ```"pact:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx @pact-foundation/absolute-version)\" --auto-detect-version-properties --broker-base-url=http://localhost:8000 --broker-username pact_workshop --broker-password pact_workshop"``` But the NPM package is https://www.npmjs.com/package/@pact-foundation/absolute-version in favour of https://www.npmjs.com/package/absolute-version. Should the docs be updated?


dwalleck
2022-08-26 20:51
has joined #pact-js

lijinze01
2022-08-26 22:20
has joined #pact-js

mhaller
2022-08-27 00:19
has joined #pact-js

mvliannoi
2022-08-29 03:41
has joined #pact-js

haobei.ma
2022-08-29 06:06
has joined #pact-js

maram.elsayed
2022-08-29 08:52
has joined #pact-js

helloitsdave
2022-08-29 14:51
has joined #pact-js

mberkowitz
2022-08-29 16:16
has joined #pact-js

matt.bremer
2022-08-29 20:10
has joined #pact-js

dimundo
2022-08-30 08:14
hi! i?ve bumped from `9.17.3` to `10.1.2` and having ```TypeError: includeWipPactsSince``` looks like it cant be `undefined` anymore line triggering error ```includeWipPactsSince: isCI ? new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split("T")[0] : undefined,```

lennart.querter
2022-08-30 09:24
has joined #pact-js

lennart.querter
2022-08-30 09:39
Hello, I am new to contract testing / pact, and am trying to implement a consumer test. I'm having problems with creating a pact with V3, any help would be appreciated. *Setup:* ```Mac M1 pro "@pact-foundation/pact": "^10.1.2" "jest": "^29.0.1", "ts-jest": "^28.0.8",``` *Error:* ``` Error in native callback at Object.mockServerMismatches (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:94:13) at PactV3.<anonymous> (node_modules/@pact-foundation/src/v3/pact.ts:207:39) at step (node_modules/@pact-foundation/pact/src/v3/pact.js:33:23) at Object.throw (node_modules/@pact-foundation/pact/src/v3/pact.js:14:53) at rejected (node_modules/@pact-foundation/pact/src/v3/pact.js:6:65)``` *Github repo for reproduction:* https://github.com/lennartquerter/pact-v3-test *Commands:* `yarn install && yarn test:pactv3`

matt.fellows
2022-08-30 10:00
Can you please raise a bug? We'll get it updated to ignore it if undefined

dimundo
2022-08-30 10:10
looks like some other parts doesnt like `undefined`s as well


matt.fellows
2022-08-30 10:22
thanks. We can probably omit all properties that are undefined before validating, and get them in one sweep. Thanks for raising :pray:

dimundo
2022-08-30 10:37
looks like there are more ( or i didnt migrated well yet :disappointed:) ```The pact consumer core returned false at 'uponReceiving'. This should only happen if the core methods were invoked out of order This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it.``` will check more

matt.fellows
2022-08-30 10:50
Thanks. Let me know if you can get to the bottom of it. This probably means an object is being reused that shouldn?t

veaceslav.gaidarji
2022-08-30 15:29
has joined #pact-js

sharonw
2022-08-30 15:29
has joined #pact-js

grace.quek
2022-08-30 15:32
has joined #pact-js

s.kadium1
2022-08-30 16:12
has joined #pact-js

tjones
2022-08-30 23:31
This isn?t a bug

tjones
2022-08-30 23:31
Although it should be in the release notes

tjones
2022-08-30 23:32
It?s a feature of typescript - typescript is protecting you from passing an invalid value to `includeWipPactsSince`

tjones
2022-08-30 23:33
Sorry, let me clarify - the type error isn?t a bug. The other thing I don?t know about.

tjones
2022-08-30 23:35
do: ```{ ...(someTest ? { optionalParam: value } : {}), }``` instead of ```{ optionalParam: someTest ? value : undefined, }```

tjones
2022-08-30 23:36
We tightened up the types in a few places, and this should have been in the release notes. Apologies.

tjones
2022-08-30 23:50
From memory, I think the release notes should have said: ? Typescript users: Matchers have types now, which will help avoid common matcher mistakes. We?re not expecting any errors with correct matcher use, but please raise an issue if the new types are causing problems. ? Typescript users: Tightened the types in a number of places. This doesn?t affect the behaviour, but there may be cases where users need to update their invocations to match the types more closely.

tjones
2022-08-30 23:52
I think we didn?t fix the enum problem where you can?t say `logLevel: 'INFO'`. I think that?s worth fixing - Matt, I can make a PR if you like

tjones
2022-08-31 00:03
Actually, looking at the code maybe we did fix that. Also I found this, which I did for users who aren?t using typescript: https://github.com/pact-foundation/pact-js-core/commit/7521c6121ec0523795c97ec5c422c3b6d6024dd8 Thinking about it now that the above has been raised, I think there?s a good argument that `foo: someTest ? value : undefined` was/is idiomatic in javascript, but I think warning that ?this might be a mistake? is still valuable.

tjones
2022-08-31 00:25
Also, what version of TypeScript are you using? Are you using `exactOptionalPropertyTypes`? I think the breaking change might be in your TS settings and not in Pact - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#exact-optional-property-types---exactoptionalpropertytypes

sumanta.roy
2022-08-31 01:33
has joined #pact-js

shuying.lin
2022-08-31 05:45
has joined #pact-js

victor.lopez
2022-08-31 10:08
has joined #pact-js

tjones
2022-08-31 13:27
Additionally, this hasn?t changed in 10.x - it was the https://github.com/pact-foundation/pact-js-core/blob/pact-node/src/verifier.ts#L340 back in pact-node, which is what 9.x uses. I think something else has changed, probably your typescript options.

dimundo
2022-08-31 14:46
thank you for such big text/explanation :slightly_smiling_face: what could cause this then, as apart from bumping pact noting changed?

dimundo
2022-08-31 14:46
cant find any `exactOptionalPropertyTypes`

dimundo
2022-08-31 14:47
```"typescript": "4.7.4"```

dimundo
2022-08-31 15:20
so looks like by replacing all `undefined` with `{}` it became better ( which is kinda weird )

nfinley
2022-08-31 15:52
has joined #pact-js

hartror
2022-09-01 06:26
has joined #pact-js

uralsmh
2022-09-01 10:37
has joined #pact-js

uralsmh
2022-09-01 10:43
Hi, Can we use pact for integration tests with mocking rather using mock-server ?

krystof.sykora
2022-09-01 12:34
has joined #pact-js

tjones
2022-09-01 13:28
I don?t think I understand your question, can you elaborate?

tjones
2022-09-01 13:41
I don?t think this is your problem, but you have jest 29 and ts-jest 28

tjones
2022-09-01 13:48
Your example does fail for me in the same way. I think this is one for the maintainers.

lennart.querter
2022-09-01 14:25
Thanks for having a look! I can try with v28 later!

lesa
2022-09-01 14:34
has joined #pact-js

gunesmes
2022-09-01 15:31
has joined #pact-js

uralsmh
2022-09-01 16:13
Actually I am looking an alternative for mock-server

uralsmh
2022-09-01 16:13
Is it possible to do samething with pact like mock-server

helloitsdave
2022-09-01 21:31
Hi! I'm new to contract testing and was following through the js workshop. Great work! The content and format is really nice. I did notice a few things along the way which caused me confusion. One thing I wanted to clarify. On which branches should the user run `npm install`? What caused me problems was the react version on step1 was older than the master branch and resulted in `Attempted import error: 'Routes' is not exported from 'react-router-dom'.` If I had installed from master, it would have been fine. I added this https://github.com/pact-foundation/pact-workshop-js/pull/88 to update those react versions in step1 I was thinking it might make the tutorial easier if the same package.json dependancies were present on each of the step branches? So no matter what step a user opts to run `npm install` on they will be able to run prior or subsequent steps without having to run the install again? Any thoughts on that?

matt.fellows
2022-09-01 23:03
Thanks yes that was the plan. It's probably just a bad merge between steps Dave. I'll look at the PR later

helloitsdave
2022-09-02 13:47
Thanks @matt.fellows Appreciate it!

alanwallaceross
2022-09-02 16:27
has joined #pact-js

alanwallaceross
2022-09-02 16:36
Hi there My organisation is still using pact-node (v10.9.4) as well as pact js (v9.11.0) as part of a contract testing library for our microservices and I'm thinking since https://www.npmjs.com/package/@pact-foundation/pact-node#which-librarypackage-should-i-use states that pact-js includes pact-nodes ability to publish to the pact broker I should be able to remove the pact-node dependency without any issue yes? I'm looking to upgrade our pacts from v2 to v3. I'm assuming I'll also need to be weary of the fact the microservices are being ran on alpine and also that some of the consumer contract testing code will need to be updated to the new stuff?

tjones
2022-09-02 16:56
pact-js depends on pact-node. You don?t need to include it unless you?re importing it somewhere.

tjones
2022-09-02 16:57
I don?t know the answer to your alpine question, sorry

alanwallaceross
2022-09-02 17:13
@tjones thanks for your reply, what do you mean by unless I'm importing it somewhere? Would you be able to describe an example? At the moment in the package.json of our contract testing library there is pact-foundation/pact-node and pact-foundation/pact so I'm assuming you mean that since pact-js already depends on pact-node then I can just remove pact-node from the package.json since pact-node will already be in the package.json of the pact-foundation/pact package that's being installed in our contract testing library?

tjones
2022-09-02 17:21
yes, this is fine, unless you have an `import` or a `require` somewhere that explicitly mentions `pact-node`

tjones
2022-09-02 17:22
(it will still work, but you should put everything you?re directly importing in your package json)

wdridi1
2022-09-02 18:59
has joined #pact-js

matt.fellows
2022-09-02 22:21
The runtime of your application shouldn't impact pact tests that run locally. But note we don't support running tests on alpine itself

matt.fellows
2022-09-02 22:21
We don't support musl

daviseago
2022-09-03 02:16
has joined #pact-js

hsanghavi538
2022-09-06 02:33
has joined #pact-js

lottie.kett
2022-09-06 10:38
Hi all, I am trying to reproduce the example from the courses https://testautomationu.applitools.com/pact-contract-tests I have written tests for the Consumer, but they are failed with errors Could you please help me how to fix it? I do not understand, how to debug them

tpaktopsp
2022-09-06 10:39
It looks like something was changed in the last version our `pact_verify` setup broke. In prev. version `pact-js` used to publish based on env variable `PACT_BROKER_PUBLISH_VERIFICATION_RESULTS` . In the latest version(pact-core: 13.7.8, pact: 10.1.2) option needs to be specified manually in pact config `publishVerificationResult: process.env.PACT_BROKER_PUBLISH_VERIFICATION_RESULTS === 'true'` However, now it leads to errors as even after specifying `PACT_BROKER_URL` pact cannot publish results. See logs in thread

tpaktopsp
2022-09-06 10:40
Publishing of verification results failed with an error: Link/Resource was not found - Request to pact broker path ?/pacticipants/conpago-backend-nodejs? failed: 404 Not Found. URL: ?https://conpago.pactflow.io/pacts/provider/conpago-backend-nodejs/consumer/conpago-re

tpaktopsp
2022-09-06 10:41
Looks like pact is trying to publish to PACT_URL instead of using PACT_BROKER_URL

thibaut.bodart
2022-09-06 10:41
has joined #pact-js

bastien.decroix
2022-09-06 11:45
has joined #pact-js

matt.fellows
2022-09-06 12:23
Hi @tpaktopsp, looks like you?re running into: https://github.com/pact-foundation/pact-net/issues/417. I?ll get support for `PACT_BROKER_PUBLISH_VERIFICATION_RESULTS` in the next version of the core, thanks for spotting this

pabcagi
2022-09-06 12:28
has joined #pact-js


matt.fellows
2022-09-06 12:34
When the upstream issue is fixed, i?ll get a fix for it out ASAP.

matt.fellows
2022-09-06 13:14
I think I can see the issue Lennart. There is a logic error for the specific set of failures in your test, that meant it actually shut the mock service down before reporting the errors.

lennart.querter
2022-09-06 13:15
let me check if I can keep it open a bit longer


lennart.querter
2022-09-06 13:16
aha, so it's in the core service, thank you so much! :smile:

matt.fellows
2022-09-06 13:24
You?re welcome. An error an a native callback was a giveaway, and then I noticed the mock server was shutting down before the test had finished wrapping up and telling you what happened

matt.fellows
2022-09-06 13:25
Fixed locally, the test fails as follows: ``` RUNS src/tradeLanes/tradelanes.test.pactv3.ts 2022-09-06T13:11:35.813403Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 4 headers 2022-09-06T13:11:35.813409Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is empty 2022-09-06T13:11:35.813423Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Creating pact request from hyper request 2022-09-06T13:11:35.813425Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Extracting query from uri /trade-lanes?page=1&pageSize=10 2022-09-06T13:11:35.813450Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request HTTP Request ( method: GET, path: /trade-lanes, query: Some({"pageSize": ["10"], "page": ["1"]}), headers: Some({"connection": ["close"], "user-agent": ["axios/0.27.2"], "host": ["127.0.0.1:49298"], "accept": ["application/json", "text/plain", "*/*"]}), body: Empty ) 2022-09-06T13:11:35.813477Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /trade-lanes, query: Some({"page": ["1"], "pageSize": ["10"]}), headers: Some({"Accept": ["application/json"]}), body: Missing ) 2022-09-06T13:11:35.815818Z DEBUG tokio-runtime-worker pact_matching: body: '' 2022-09-06T13:11:35.815822Z DEBUG tokio-runtime-worker pact_matching: matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }, QUERY: MatchingRuleCategory { name: QUERY, rules: {} }, HEADER: MatchingRuleCategory { name: HEADER, rules: {} }} } 2022-09-06T13:11:35.815829Z DEBUG tokio-runtime-worker pact_matching: generators: Generators { categories: {} } 2022-09-06T13:11:35.815840Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '/trade-lanes' to '/trade-lanes' ==> true cascaded=false matcher=Equality 2022-09-06T13:11:35.815846Z DEBUG tokio-runtime-worker pact_matching: expected content type = '*/*', actual content type = '*/*' 2022-09-06T13:11:35.815862Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }' 2022-09-06T13:11:35.816095Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '1' to '1' ==> true cascaded=false matcher=Equality 2022-09-06T13:11:35.816105Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '10' to '10' ==> true cascaded=false matcher=Equality 2022-09-06T13:11:35.816117Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: [] 2022-09-06T13:11:35.816139Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Test context = {"mockServer": Object {"href": String("http://127.0.0.1:49298"), "port": Number(49298)}} 2022-09-06T13:11:35.816150Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(44 bytes, application/json) ) console.log TypeError: Cannot read properties of undefined (reading '0') at /private/tmp/pact-v3-test/src/tradeLanes/tradelanes.test.pactv3.ts:47:36 at processTicksAndRejections (node:internal/process/task_queues:95:5) at PactV3.<anonymous> (node_modules/@pact-foundation/src/v3/pact.ts:204:15) RUNS src/tradeLanes/tradelanes.test.pactv3.ts 2022-09-06T13:11:35.840716Z 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 2022-09-06T13:11:35.840729Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID 1e3fa86f-14ad-4f9e-9063-101ae57a2181 - MockServerMetrics { requests: 1 } FAIL src/tradeLanes/tradelanes.test.pactv3.tspact_mock_server::mock_server: Mock server 1e3fa86f-14ad-4f9e-9063-101ae57a2181 shutdown - MockServerMetrics { requests: 1 } GET /dogs ? returns an HTTP 200 and a pagination result of docs (34 ms) ? GET /dogs ? returns an HTTP 200 and a pagination result of docs TypeError: Cannot read properties of undefined (reading '0') 45 | 46 | // Assert: check the result > 47 | expect(response.results[0]).toEqual(tradeLaneExample); | ^ 48 | }); 49 | }); 50 | }); at src/tradeLanes/tradelanes.test.pactv3.ts:47:36 Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 2.436 s Ran all test suites. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.```

patrickbadley
2022-09-06 13:25
has joined #pact-js

lennart.querter
2022-09-06 13:25
that makes so much more sense :smile: I should have spotted it! Thanks again :slightly_smiling_face: This will build a new version of pact-js?

matt.fellows
2022-09-06 13:40
yep! I?ll get a release out tomorrow, if not earlier (there is a build running now, but we realised there is a flakey test that needs addressing)

lennart.querter
2022-09-06 13:41
check, thanks for the quick action!

matt.fellows
2022-09-06 13:41
np - thanks for the repro, that always makes things a TONNE easier!

matt.fellows
2022-09-06 13:44
P.S. I think you want the response to be: ```{ results: [...] }``` right? Where each item in `results` is of the same shape?

matt.fellows
2022-09-06 13:44
If so, ```const EXPECTED_BODY = MatchersV3.eachLike({ results: [tradeLaneExample] });``` should be ```const EXPECTED_BODY = { results: MatchersV3.eachLike(tradeLaneExample) };```

lennart.querter
2022-09-06 13:45
yeah, I had already found that one :smile: and that allowed me to generate the pact without issues

matt.fellows
2022-09-06 13:45
OK cool! Just checking :slightly_smiling_face:

matt.fellows
2022-09-06 13:45
OK that flakey test (well, it?s reliable in a way) broke the release - I?ll fix it tomorrow and get a release out when I?m more awake

matt.fellows
2022-09-06 13:45
:wave:

lennart.querter
2022-09-06 13:46
haha, sure sure :smile: thanks again!

yousafn
2022-09-06 17:03
Should be rocking now Lennart, PR here https://github.com/lennartquerter/pact-v3-test/pull/1

yousafn
2022-09-06 17:04
cc @lennart.querter :raised_hands:

james.grubb
2022-09-06 19:19
has joined #pact-js

snehasingh291506
2022-09-06 19:42
has joined #pact-js

patrickbadley
2022-09-06 19:54
@patrickbadley has left the channel

senchu.pampoorickal
2022-09-06 20:15
has joined #pact-js

matt.fellows
2022-09-07 01:05
Thanks for getting the release out Yousaf. Let us know how you go Lennart!

abubics
2022-09-07 02:19
I've never seen this course material, and it has some dubious standards/practices. Nevertheless . . . "Chapter 2 - setting up Pact" should be setting the `global.provider` up, so it works in the tests. The error "The pact mock server wasn't configured when addInteraction was called" is a hint that it might not be set up. The rest of the warnings also hint that the mock server has failed to start up.

abubics
2022-09-07 02:20
Not sure if any of the maintainers are familiar with this content, but they might have more specific advice.

tpaktopsp
2022-09-07 05:06
Thanks @matt.fellows will be testing as it as it out

tpaktopsp
2022-09-07 05:06
It does seem that there are some issue with new validation

tpaktopsp
2022-09-07 05:07
When I get publish to work I cannot specify pactBrokerUrl as it requires provider.

tpaktopsp
2022-09-07 05:07
But when I?m using pactUrls there should be no need to specify provider I?m not correct?

matt.fellows
2022-09-07 05:58
That's true I think. So the issue is the constraints, it should allow you to publish if provider and the broker URL is not set, only if pact urls is set

matt.fellows
2022-09-07 05:58
Could you please raise a ticket?

tpaktopsp
2022-09-07 05:58
right i removed pactBrokerUrl and it seem to be working now

tpaktopsp
2022-09-07 05:59
just specify pactUrl - I think I was following prev examples.

matt.fellows
2022-09-07 06:11
Ahh ok. The older lib probably wasn't quite as strict with the validation. Let me know if you do encounter other issues and we'll fix them ASAP

tpaktopsp
2022-09-07 06:12
Its working for us now, thanks for the quick fix

lennart.querter
2022-09-07 06:52
Thanks guys! I will test it right away :smile:

nagasrinivas.thota
2022-09-07 06:56
has joined #pact-js

remigijus.mazulis
2022-09-07 07:18
I remember trying this course too, but had the same issues and were not able to fix them :shrug: then I switched to a bit different approach and set up a provider in the same test file instead of globally setting it. Something like in this example https://www.npmjs.com/package/@pact-foundation/pact-web/v/8.1.0#example

mahinsyeda99
2022-09-07 09:40
has joined #pact-js

matt.fellows
2022-09-07 11:46
You?re welcome

snehasingh291506
2022-09-07 13:30
Getting the below error while running pact test in the consumer side... i might be doing something really stupid but just can't figure out what... ```'use strict' process.env.REACT_APP_ENGINE_SERVICE_URL = 'http://localhost:8992' import { expect } from 'chai' import path from 'path' import { Pact } from '@pact-foundation/pact' import { fetchACEFields } from '../api/index' describe('fetch ACE fields', () => { const port = 8992 const objectType = 'dummy' const provider = new Pact({ port: port, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), dir: path.resolve(process.cwd(), 'pacts'), spec: 2, consumer: 'webapp', provider: 'engine-service', pactfileWriteMode: 'merge', }) const expectedBody = { status: true, data: [{ fullName: 'dummy' }] } before(() => provider.setup()) after(() => provider.finalize()) afterEach(() => provider.verify()) describe('request to fetch fields', () => { before(done => { const interaction = { state: 'fetch ace fields', uponReceiving: 'a request to get all ace fields', withRequest: { method: 'GET' as const, path: `/ace-fields?object_type=${objectType}`, headers: { Accept: 'application/json', }, }, willRespondWith: { status: 200, headers: { 'Content-Type': 'application/json', }, body: expectedBody, }, } provider.addInteraction(interaction).then(() => { done() }) }) it('verify it returns the correct response', async () => { const res = await fetchACEFields(objectType) expect(res).equal(expectedBody) }) }) }) Error: ReferenceError: navigator is not defined at Object.<anonymous> (/Users/snehasingh/Documents/webapp/node_modules/flags/node_modules/supports-color/browser.js:3:58) at Module._compile (internal/modules/cjs/loader.js:1068:30) at Module._extensions..js (internal/modules/cjs/loader.js:1097:10) at Object.require.extensions.<computed> [as .js] (/Users/snehasingh/Documents/webapp/node_modules/ts-node/src/index.ts:1445:43)```

lisnychyis
2022-09-07 14:00
has joined #pact-js

marek.czerwinski
2022-09-07 16:07
has joined #pact-js

tjones
2022-09-08 01:41
I don't know either, but that error is not coming from pact

xiaofeng02111
2022-09-08 03:20
has joined #pact-js

xiaofeng02111
2022-09-08 04:22
Has anyone run into `pino` is not a function error? TypeError: pino is not a function ```at Object.createLogger(../../node_modules/@pact-foundation/pact-core/src/logger/pino.ts at Object.createLogger(../../node_modules/@pact-foundation/pact-core/src/logger/index.ts at Object.createLogger(../../node_modules/@pact-foundation/pact-core/src/service.ts``` I got this error when I tried to do ```const provider = new PactV3({consumer:"foo",provider:"bar"});```

tjones
2022-09-08 04:31
what version?

xiaofeng02111
2022-09-08 04:48
```jest: 28.1.3 @pact-foundation/pact: 10.1.3 typescript: 4.8.2 ts-jest:28.0.8 @types/jest: 28.1.3```

matt.fellows
2022-09-08 04:51
I've seen it with an old version of create react app which bundles an old version of babel

matt.fellows
2022-09-08 04:52
(or at least, similar errors where it can't transpile newer modules)

xiaofeng02111
2022-09-08 04:52
this is a pure node project

xiaofeng02111
2022-09-08 04:52
and it uses typescript only and no babel

matt.fellows
2022-09-08 04:52
Strange

xiaofeng02111
2022-09-08 04:53
any jest and ts config can cause this?

matt.fellows
2022-09-08 04:55
I'm not sure sorry

matt.fellows
2022-09-08 04:55
If you could share a repro project and raise an issue we could take a look

xiaofeng02111
2022-09-08 04:56
ok , i will give it a try to see if i can reproduce that with a brand new project

xiaofeng02111
2022-09-08 04:57
thank you

matt.fellows
2022-09-08 05:01
:+1:

tjones
2022-09-08 05:04
This part is suspicious - `../../` - are you installing your node_modules somewhere custom? Are you running your tests from a non-root directory?

tjones
2022-09-08 05:04
Can you share your tsconfig?

tjones
2022-09-08 05:06
Also that error is very suspicious - it's naming the .ts files, but it should be running the JS files :confused:

xiaofeng02111
2022-09-08 05:06
```folder structure my-project -node_modules -src -__tests__ -mytest.pact.ts```

tjones
2022-09-08 05:08
what does `npm ls pino` do?

xiaofeng02111
2022-09-08 05:10
```module.exports = { roots: ['<rootDir>/src'], transform: { '^.+\\.tsx?$': 'ts-jest', }, testRegex: '(/__tests__/.*|(\\.|/))\\.(test|spec|pact)\\.tsx?$', moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], collectCoverage: true, collectCoverageFrom: ['src/**/*.ts'], coveragePathIgnorePatterns: ['index.ts'], moduleDirectories: ['node_modules', '.', '../../utils'], coverageThreshold: { global: { statements: 80, }, }, };```

xiaofeng02111
2022-09-08 05:10
tsconfig ```{ "compilerOptions": { "baseUrl": "./", "module": "commonjs", "moduleResolution": "node", "outDir": "./dist", "allowJs": false, "declaration": true, "esModuleInterop": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "noImplicitAny": true, "target": "es2018", "lib": ["es2018", "esnext.asynciterable"], "sourceMap": true, "strict": true, "strictNullChecks": false, "paths": { "src/*": ["src/*"] } }, "exclude": ["node_modules"], "include": ["src", "*.d.ts", "mocks"] }```

tjones
2022-09-08 05:11
`moduleDirectories: ['node_modules'` <-- node_modules definitely should not be here

tjones
2022-09-08 05:11
`'../../utils'` <-- this is also suspicious, since it suggests there's a package above you

xiaofeng02111
2022-09-08 05:13
this project lives in a monorepo (yarn workspace)

tjones
2022-09-08 05:15
1) The monorepo isn't in your folder structure diagram :P 2) I was wrong about moduleDirectories (the documentation https://jestjs.io/docs/configuration#moduledirectories-arraystring). However, this is still your problem - you're loading ts files before js files. Don't do that.

tjones
2022-09-08 05:15
`moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],` <-- change this `moduleFileExtensions: [ 'js', 'jsx', 'ts', 'tsx','json', 'node'],` <-- to this

tjones
2022-09-08 05:15
You're currently asking ts-jest to transpile node_modules which is definitely wrong

tjones
2022-09-08 05:16
so the require is failing because your tsconfig has different settings to the one that pact was compiled with

tjones
2022-09-08 05:17
This is a jest config problem, not a pact problem. I'm surprised only pact broke

tjones
2022-09-08 05:17
@matt.fellows Pact could prevent this mistake from being a problem by not including the .ts files in the bundle

xiaofeng02111
2022-09-08 05:17
yea, this project has other jest tests e.g some ajv validation stuff that work just fine

tjones
2022-09-08 05:18
(you'd have to make sure the `.d.ts` files are still included of course)

tjones
2022-09-08 05:18
Sure. However, the problem is in the jest config, which is being asked to transpile node_modules, which you are not supposed to do.

xiaofeng02111
2022-09-08 05:20
when i tried to remove that node_modules from it then it starts to complain about `cannot-find-module-source-map-support` (probably i can take look at this ) .

tjones
2022-09-08 05:21
`ajv` avoids this problem by putting the compiled files in a `dist` folder, so imports don't get confused

tjones
2022-09-08 05:21
Yes, as I said above, I was wrong about removing node_modules

tjones
2022-09-08 05:21
but you need to correct `moduleFileExtensions`

xiaofeng02111
2022-09-08 05:22
i did but that doesnt not seem to fix it

xiaofeng02111
2022-09-08 05:23
same error

tjones
2022-09-08 05:31
I don't know, sorry. I suspect there's something going on with your monorepo setup - maybe a config file from the root repo is overriding something?

tjones
2022-09-08 05:32
this isn't a pact problem, it's a jest/typescript config problem

tjones
2022-09-08 05:32
you can tell because the error message is talking about typescript files inside pact.

xiaofeng02111
2022-09-08 05:37
okay, anyway, i appreciate for all your help, i will dig a little bit into it to see if i have any luck:laughing:

xiaofeng02111
2022-09-08 06:11
surprisingly , the old version works

xiaofeng02111
2022-09-08 06:11
@pack-foundation/pact v9.18

xiaofeng02111
2022-09-08 06:11
nothing changes in terms of my config

tjones
2022-09-08 06:12
I think 9.18 didn't use pino but I don't remember

jayvdb
2022-09-08 06:22
has joined #pact-js

tjones
2022-09-08 08:31
Update: I checked, not only did it still use Pino, but it still used that specific import line. I suspect yarn monorepo weirdness

vvarunbajpai1988
2022-09-08 12:13
has joined #pact-js

david342
2022-09-08 12:18
I am not sure I understand why you cannot have an Either matcher saying its empty or it must contain something with a shape that has been defined

tjones
2022-09-08 12:29
because those are different cases

tjones
2022-09-08 12:30
If we say the pact is: ```{ optionalArray: either([], { /* some object */ }) }``` then `{ optionalArray: [] }` passes that test every single time

tjones
2022-09-08 12:30
Pact is not about describing what is possible

tjones
2022-09-08 12:31
it's about testing that your provider and your consumer can actually talk to each other

tjones
2022-09-08 12:32
so, the correct practice is to have two interactions ```state: "no arrays" GET /arrays responds with { optionalArray: [] }``` and ```state: "some arrays" GET /arrays responds with { optionalArray: eachLike( { /* some object */ } ) }```

tjones
2022-09-08 12:33
"Ah" you say - "but my consumer doesn't actually care about the contents of that array" Right, then it doesn't go in the pact test. Pact will ignore contents that isn't in the pact.

tjones
2022-09-08 12:33
You only test what you are expecting to be there

tjones
2022-09-08 12:33
and if you're allowed to have optionals, you don't necessarily test that it is going to be there

zakir
2022-09-08 12:55
has joined #pact-js

gregory.hanson
2022-09-08 12:56
has joined #pact-js

matt.fellows
2022-09-08 13:34
Pact is a tool that implements https://en.wikipedia.org/wiki/Specification_by_example. It?s not that schemas are bad, it?s that they are just abstract, and with Pact we are trying to reduce ambiguity. As Tim points out, we?re not trying to build a schema of what?s possible (that?s the provider?s job). We?re trying to get out all of the uses cases of the consumer as clearly as we can. We are also unit testing the consumer, and by doing so providing evidence that the consumer actually does need the data and can deal with it, and build out the surface a?ea of the provider that's actually used. Logical conditions tend to increase ambiguity rather than reduce it.

matt.fellows
2022-09-08 13:35
(I?m not sure why that link is funny, but every time I pasted it in, I couldn?t type in the box without all sorts of weird things happen - so know that I desperately want to remove the `'` but can?t :laughing: . I think I might be in a late digital-era Saw movie??)

snehasingh291506
2022-09-08 13:41
Even though my test is passing but the contract is not getting created... pact creates a contract in json file after the test has executed?? ```'use strict' import { setupServer } from 'msw/node' import { rest } from 'msw' import { fetchFields } from '../api/index' import provider from './provider' import interactions from './interactions/interactions' describe('fetch fields', () => { const expectedBody = { status: true, data: [{ fullName: 'dummy' }] } const server = setupServer( rest.get( `http://localhost:8992/fields?object_type=dummy`, (req, res, ctx) => res( ctx.status(200), ctx.json(expectedBody) ) ) ) beforeAll(() => server.listen()) afterEach(() => server.resetHandlers()) afterAll(() => server.close()) describe('request to fetch ACE fields', () => { beforeAll(async () => { await provider.setup(); await provider.addInteraction(interactions.fetchAceFields); }); test('verify it returns the correct response', async () => { const res = await fetchFields("dummy") expect(res.data).toEqual(expectedBody) }) }) })```

yousafn
2022-09-08 13:43
you are mocking out the provider calls with msw, but pact should be setup to act as the provider in your test you shouldn?t be using msw, but instead using pact directly to mock out your provider.

yousafn
2022-09-08 13:44
You could use msw, with pact-msw-adapter, to convert the msw matches into pact contracts, but you lose out on provider states and matchers so is only suited to bi-directional contract testing https://docs.pactflow.io/docs/bi-directional-contract-testing/tools/msw

xiaofeng02111
2022-09-08 14:32
mystery solved: for the jest config , we included `"."` in the moduleDirectories field and that causes the pino failure

xiaofeng02111
2022-09-08 14:56
it seems to be a bug that cause by the co-existence of `module-alias` and the pact package

snehasingh291506
2022-09-08 16:19
i made the changes to use pact-msw-adapter.. but it is failing with the below error.. i have strictly follow the example mentioned in the doc.. ```'use strict' import { setupServer } from 'msw/node'; import { rest } from 'msw'; import { fetchFields } from '../api/index'; import interactions from './interactions/interactions'; import provider from './provider'; import { setupWorker } from "msw"; import {API} from './app' import { setupPactMswAdapter } from "@pactflow/pact-msw-adapter"; const expectedBody = { status: true, data: [{ fullName: 'dummy' }] } const server = setupServer(rest.get("http://localhost:8229"+"/fields?object_type=dummy", (req, res, ctx) => { return res(ctx.status(200), ctx.json(expectedBody)); })); const pactMswAdapter = setupPactMswAdapter({ server, options: { consumer: "webapp", providers: { ['service']: ['/fields'], }, debug: true, includeUrl: ['/fields'], }, }); describe('fetch fields', () => { beforeAll(async () => { server.listen(); }); beforeEach(async () => { pactMswAdapter.newTest(); }); afterEach(async () => { pactMswAdapter.verifyTest(); server.resetHandlers(); }); afterAll(async () => { await pactMswAdapter.writeToFile(); pactMswAdapter.clear(); server.close(); }); test('verify it returns the correct response', async () => { const respProducts = await fetchFields("dummy"); expect(respProducts).toEqual(expectedBody); }) })```

yousafn
2022-09-08 16:27
can you either share a full repro or provide the file `import { fetchFields } from '../api/index';` so we can see how your client is configured.

snehasingh291506
2022-09-08 16:35
i wish i could... i can share the function though ```export const API = axios.create(); export const fetchFields = (objectType: string) => API.get(`${serviceUrl}/ace-fields?object_type=${objectType}`)```

yousafn
2022-09-08 16:37
You are mocking an endpoint for the path `/fields` ```const server = setupServer(rest.get("http://localhost:8229"+"/fields?object_type=dummy", (req, res, ctx) => { return res(ctx.status(200), ctx.json(expectedBody)); }));``` but your client is using `/ace-fields` ```export const API = axios.create(); export const fetchFields = (objectType: string) => API.get(`${serviceUrl}/ace-fields?object_type=${objectType}`)``` How is your `serviceUrl` being set?

snehasingh291506
2022-09-08 16:44
Do not be concerned about the url. I modified the url in the index.ts file after sending the first message, so I have made the necessary change in the test. serviceUrl comes from.env file

snehasingh291506
2022-09-08 16:48
this function is getting called inside useEffect()

yousafn
2022-09-08 16:51
Your test is incorrect, and not mocking out the correct path. you are also not asserting against the data object from the axios response, but the entire axios response object itself This will generate a Pact. I am concerned with how the url is set, to ensure it is the correct URL you are mocking out, there are cases where using pact-js, you need to be able to override this value during your test, which in your current setup, you wouldn?t be able to, which is why I asked. ```"use strict"; const setupServer = require("msw/node").setupServer; const rest = require("msw").rest; const fetchFields = require("./app").fetchFields; const setupPactMswAdapter = require("@pactflow/pact-msw-adapter").setupPactMswAdapter; const expectedBody = { status: true, data: [{ fullName: "dummy" }] }; const server = setupServer( rest.get( "http://localhost:8229" + "/fields?object_type=dummy", (req, res, ctx) => { return res(ctx.status(200), ctx.json(expectedBody)); } ) ); const pactMswAdapter = setupPactMswAdapter({ server, options: { consumer: "webapp", providers: { ["service"]: ["/fields"], }, debug: true, includeUrl: ["/fields"], }, }); describe("fetch fields", () => { beforeAll(async () => { server.listen(); }); beforeEach(async () => { pactMswAdapter.newTest(); }); afterEach(async () => { pactMswAdapter.verifyTest(); server.resetHandlers(); }); afterAll(async () => { await pactMswAdapter.writeToFile(); pactMswAdapter.clear(); server.close(); }); test("verify it returns the correct response", async () => { const respProducts = await fetchFields("dummy"); expect(respProducts.data).toEqual(expectedBody); }); });``` `app.js` ```const axios = require("axios"); const API = axios.create(); const serviceUrl = "http://localhost:8229"; const fetchFields = (objectType) => API.get(`${serviceUrl}/fields?object_type=${objectType}`); module.exports = { API, fetchFields, };```

yousafn
2022-09-08 16:52
Took 5 mins to create a minimal reproducible example?



snehasingh291506
2022-09-08 17:00
I'm sorry I wasn't aware of this. will certainly create a minimal reproducible sample from the next time...

yousafn
2022-09-08 17:10
It?s ok matey, and thank you, it is the best way to get support without the to and fro :slightly_smiling_face: I?ve updated the repro with a working example using pact-msw-adapter, and pact-js, both with the new v3 interface and with the old v2 interface. Good luck in your Pact journey

snehasingh291506
2022-09-08 17:31
Thanks :hugging_face:

ashishmerani
2022-09-08 21:54
has joined #pact-js

tjones
2022-09-09 00:01
I explained above, the problem is that you're transpiling node_modules when you shouldn't be. You can tell because the error is coming from typescript files, which should not be what you are running.

tjones
2022-09-09 00:04
So the package combinations will just change whether or not you see an error, not fix the problem (which as I have already told you, is that you're transpiling node_modules). My current guess is that `node_modules` is by default blocked from being involved in the transpilation, but reincluded when you include `"."` in the modules. Anyway, this isn't a pact problem. It is a problem to do with the strange way that ts-jest is set up in this project.

tpaktopsp
2022-09-09 05:35
Does jest expect suppose to work in `executeTest` ? We are getting weird pact errors:

tpaktopsp
2022-09-09 05:35
Error in native callback at Object.mockServerMismatches (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:94:13) at PactV3. <anonymous> (node_modules/@pact-foundation/src/v3/pact.ts:207:39) at step (node_modules/@pact-foundation/pact/src/v3/pact.js:33:23) at Object.throw (node_modules/@pact-foundation/pact/src/v3/pact.js:14:53 at rejected (node_modules/@pact-foundation/pact/src/v3/pact.js:6:65) at tryCall0ne (node_modules/react-native/node_modules/promise/lib/core.js:37:12) at node_modules/react-native/node_modules/promise/lib/core.js:123:15

matt.fellows
2022-09-09 05:36
it should do

matt.fellows
2022-09-09 05:36
Which version are you on Maxim?

matt.fellows
2022-09-09 05:37
There was an issue for a specific error scenario pre `10.1.3`

tpaktopsp
2022-09-09 05:39
Ah right, just updated - it works :+1:

matt.fellows
2022-09-09 05:39
great!

tpaktopsp
2022-09-09 05:39
thanks for the quick reply

matt.fellows
2022-09-09 05:39
You?re welcome :slightly_smiling_face:

matt.fellows
2022-09-09 05:40
The new JS is a complete rewrite under the hood, so we?re still going to be finding a few things that are different


ramesh.ambastha
2022-09-09 11:06
has joined #pact-js

harwin1494
2022-09-12 06:24
Hi team a general query, lets say there are different environments for a consumer and a provider. So, are there any guidelines in PACT, if we need to verify a QA version of the consumer with the Prod version of the provider, or can we only verify the QA Consumer with QA Provider only?

tjones
2022-09-12 06:47
Remember that your version is not the same as your environment. Eg, you might have v1.2.3 deployed in QA, but when you're verifying "QA", you're not verifying "QA", you're verifying v1.2.3

tjones
2022-09-12 06:48
This doc has some good guidelines https://docs.pact.io/pact_nirvana

tjones
2022-09-12 06:49
I think the ideal setup for multiple environments is to gate deployments with can-i-deploy, but not to fail the build if the verification fails (although to be fair this isn't how I do it, so I don't know for sure)

tjones
2022-09-12 06:52
Note that usually when you have something deployed in QA it must already have been verified

harwin1494
2022-09-12 12:16
Okay, thanks @tjones, going through the document now.

nickm
2022-09-12 17:15
has joined #pact-js

uzma_khan
2022-09-12 18:13
has joined #pact-js

stefan.tertan
2022-09-13 15:28
has joined #pact-js

abdel.akkoub
2022-09-14 02:45
Hello, We are running our consumer contract tests using @ pact-foundation/pact version 10.1.3. The consumer app is Vue where the UI makes GQL calls to the backend GQL providers. We currently run the tests using Jest framework. We are seeing an issue recently after upgrading the Node engine on our local machines from 16.17.0 to 18.9.0. When run with Node 16.17.0, the consumer tests run successfully and a new contract is generated. However, when run under 18.9.0, the consumer test fails, where the ApolloClient that is being referenced in the consumer test is failing with a "request to http://localhost:8992/graphql failed, reason: connect ECONNREFUSED ::1:8992" error. Here is a simplified snipped of the consumer test: ```/* eslint-env jest */ import { Pact, GraphQLInteraction, Matchers } from '@pact-foundation/pact'; import * as path from 'path' import fetch from 'node-fetch' import { createApolloClient } from '../../src/plugins/apollo-vue-setup' import BusinessNeedService from '../../src/services/businessNeedService' import { print } from 'graphql' import { gql } from '@apollo/client/core' const pactTestTimeout = 30000 describe('GraphQL example', () => { const port = 8992 const baseUri = `https://localhost:${port}` const provider = new Pact({ port: port, log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), logLevel: 'debug', dir: path.resolve(process.cwd(), 'pacts'), consumer: 'UI', provider: 'BusinessNeedApollo', }); const accessToken = 'authToken' const environmentLevel = 'qa' const siteName = 'qa026' const clientSiteId = 'siteId' const language = 'en-US' const getAccessTokenAsync = () => accessToken const getBeelineHeaderValues = () => ({ environmentLevel, siteName, clientSiteId, language }) const defaultHeaders = { 'x-beeline-environment-level': environmentLevel, 'x-beeline-site-name': siteName, 'x-beeline-client-site-id': clientSiteId, 'Content-Type': 'application/json', 'accept-language': language, Authorization: `bearer ${accessToken}` } const defaultRequest = { method: 'POST', path: '/graphql', headers: defaultHeaders } const defaultApolloClient = createApolloClient({ baseUri, fetch, getAccessTokenAsync, getBeelineHeaderValues }) beforeAll(() => provider.setup()); afterAll(() => provider.finalize()); describe('query hello on /graphql', () => { beforeAll(() => { const graphqlQuery = new GraphQLInteraction() .uponReceiving('A request to get requests') .given('user has business need requests and is authenticated') .withQuery(print(gql`query{ quickRequests(skip: $skip, top: $top, search: $search, orderBy: $orderBy) { items { clientName cost { billRate estimatedCost __typename } createDate industryId jobDescription jobTitle requestId requestType workLocation __typename } totalCount __typename } }`)) .withVariables() .withOperation() .withRequest(defaultRequest) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: Matchers.like({ data: { quickRequests: { items: [ { clientName: 'QA027', cost: { billRate: '$488.75', estimatedCost: '$320,317.50', __typename: 'Cost' }, createDate: '2020-04-21T19:32:31.000Z', industryId: '12345', jobDescription: 'This is a description', jobTitle: 'Accountant (General)', requestType: 'Staff Aug - Approved Budget With Position ID', requestId: 'e234e7aa-54b7-4735-a170-a08ce280c411', workLocation: 'Plantation, FL', __typename: 'QuickRequest' } ], totalCount: 100, __typename: 'QuickRequestPage' } } }) } ) return provider.addInteraction(graphqlQuery); }); it('returns the correct response', async () => { const businessNeedService = new BusinessNeedService(defaultApolloClient) const requests = await businessNeedService.getQuickRequests(); expect(requests.items).toHaveLength(1) }); //verify with Pact, and reset expectations afterEach(() => provider.verify()); }); });``` I can't post the two output messages in the entire threads, so I saved each output to a text file and attached them to the thread. The major difference in the logs is the lack of reference to the tokio-runtime-worker I am seeing when the tests fails. I have spent the entire day attempting to debug this issue with no luck being able to generate the tests. I also attempted to run Node 18.9.0 with different versions of the @ pact-foundation/pact (8.2.6 and 9.17.2) with no luck! Any advice is highly appreciated!

tjones
2022-09-14 03:40
I don't _think_ this is the problem, but the part where you add the interaction would be better written in a `beforeEach`. I remember in some version of jest `beforeAll`s wouldn't run in the expected order.

tjones
2022-09-14 03:44
At what point does the apollo client try to connect? If it connects during the `createApolloClient` call, then it will be before the provider has setup.

tjones
2022-09-14 03:44
It could be that something changed between node versions that allowed that race condition to succeed/fail

tjones
2022-09-14 03:46
try: ```let defaultApolloClient; beforeAll(async () => { await provider.setup() defaultApolloClient = createApolloClient({ baseUri, fetch, getAccessTokenAsync, getBeelineHeaderValues }); });```

konitzert
2022-09-14 07:11
has joined #pact-js

tpaktopsp
2022-09-14 10:55
Okay lets try to ask here. Is there an example of how to use Pact with `useQuery` Apollo hook? Cannot seem to find any on github or in the docs.

matt.fellows
2022-09-14 12:03
I seemed to recall something about default network adapters prioritising ipv6 between node 16 and 18 (because ipv4 is dead right and now ipv6 rules the world???..) > failed, reason: connect ECONNREFUSED ::1:8992 That is an ipv6 address, but it looks like the server is starting on `127.0.0.1` (the default).. It looks like you might be calling `localhost` but if this resolves to an ipv6 adddress, it won?t work because the mock server is on `127.0.0.1` - could you please try using `127.0.0.1` in your code (there are alternatives, such as modifying your host entries, but that is obviously not ideal)

adam.witko
2022-09-14 12:59
Hey hey, does pact-js-core not support linux x64 env builds yet?

adam.witko
2022-09-14 13:04
I thought it was based on the binding.gyp but I'm seeing issues trying to use pact-js ^10 in Gitlab pipelines that is a linux 64 executor. Basically, make failures on yarn/npm install for the pact-core

abdel.akkoub
2022-09-14 13:39
You are 100% correct. Shortly after I posted this, I came across this ticket on Node's Github page: https://github.com/nodejs/node/issues/40702 and after switching the baseUri to 127.0.0.1, the tests worked! Thank you so much for the help!

daniel.puiu
2022-09-14 13:43
has joined #pact-js

tjones
2022-09-14 15:19
I thought the graphql example did this- does it not?

tpaktopsp
2022-09-14 15:19
Which one?

tjones
2022-09-14 15:19
Oh wait, you mean the react hook?

tpaktopsp
2022-09-14 15:20
yes

tjones
2022-09-14 15:20
There isn't an example with that

tpaktopsp
2022-09-14 15:20
I made it work but it was a deep dive into react :slightly_smiling_face:

tpaktopsp
2022-09-14 15:20
Maybe I can add example to pact-js cause its way more complex than expected

tpaktopsp
2022-09-14 15:20
especially with v3

tjones
2022-09-14 15:21
That hook seems like an anti pattern to me. Typically (whether or not you use graphql or pact) you would separate the API layer from the hooks

tjones
2022-09-14 15:21
Like, how would you test it without pact?

tpaktopsp
2022-09-14 15:21
Using `MockedProvider`

tjones
2022-09-14 15:22
I don't think that part is the hard part

tjones
2022-09-14 15:22
But I've never tried to do it

tjones
2022-09-14 15:22
I'm sure an example would be welcome

tpaktopsp
2022-09-14 15:22
That?s not its all the funk around waitFor I didn?t use before :slightly_smiling_face:


tpaktopsp
2022-09-14 15:23
Cause we need to wait for useQuery to actually do the work


tpaktopsp
2022-09-14 15:23
learned a lot about RTL in the process :slightly_smiling_face:

tjones
2022-09-14 15:24
I?m definitely keen to see what you came up with, because then I?ll learn something too

tjones
2022-09-14 15:24
And people are going to use that hook, whether or not I think it's an anti-pattern

tjones
2022-09-14 15:26
Good eye, Matt.

tjones
2022-09-14 15:27
I believe (but don't know) that it should work on Linux x64. I thought it had trouble with aarch64

matt.fellows
2022-09-14 23:23
it should definitely work on linux x64

matt.fellows
2022-09-14 23:25
Our https://github.com/pact-foundation/pact-js-core/actions/runs/3004560680/jobs/4823949382run on linux 64 bit. Can you share the errors you?re running into?

adam.witko
2022-09-15 07:34
Hopefully I haven't misunderstand the node, yarn, and container image we're using and sharing inaccurate information

tjones
2022-09-15 07:43
Ok, I think that's complaining that it doesn't have gcc (or at least, doesn't have g++). I don't know how the dependency management for node-gyp works, but try installing a c++ tool chain

tjones
2022-09-15 07:44
Also: so many peer dependency warnings! That isn't the problem, buuuut it's not *not* a problem :sweat_smile:

adam.witko
2022-09-15 07:46
@tjones ha I know about the peer dependency warnings :smile: Hmm, oh I have assumed something then as we do have `gcc` installed in our gitlab runner image but not `g++`. I shall give it a try, thanks @tjones

adam.witko
2022-09-15 08:21
Thank you @tjones adding in g++ did the trick :heart:

tjones
2022-09-15 09:22
Awesome! Glad to help

l.heluszko
2022-09-15 13:12
has joined #pact-js

alecat88
2022-09-16 10:25
has joined #pact-js

alecat88
2022-09-16 10:35
:wave: Hello, team! Nice to meet you all! I?ve stumble upon the nestjs pact examples (https://github.com/pact-foundation/pact-js/tree/master/examples/nestjs-consumer) and I?ve noticed that the official package for nestjs and pact tests (https://www.npmjs.com/package/nestjs-pact) is installed but not used at all in those examples Also, from the official nest-pact readme, when we follow the example link (https://www.npmjs.com/package/nestjs-pact#example) we don?t find what we?re looking for, which is examples of the nestjs-pact library been used. I?ve created the examples locally for how to use correctly the nestjs-pact library and I?m ready to open a PR/MR, can somebody allow me to push a branch so I can raise it? Many thanks!

matt.fellows
2022-09-16 11:42
Thanks so much for the offer, it's much appreciated!

matt.fellows
2022-09-16 11:42
The best way is to push to your own public fork, and then raise a pull request against out repo

matt.fellows
2022-09-16 11:44
This way we don't need to grant you write permissions

chris.armbrester
2022-09-16 11:45
has joined #pact-js

zohaibse011
2022-09-16 13:28
has joined #pact-js

nvenkataraman
2022-09-16 17:17
has joined #pact-js

zach.davis
2022-09-16 20:18
has joined #pact-js

jorbraken
2022-09-16 20:29
has joined #pact-js

tjones
2022-09-16 22:51
The nest-js consumer examples don't have it because it's not necessary- the additional wrapper is only useful for provider testing

tjones
2022-09-16 22:53
The package should be removed from the consumer example- good catch

paul.ologeh
2022-09-16 23:25
has joined #pact-js

mvliannoi
2022-09-19 05:06
Hello! We are using https://github.com/pact-foundation/jest-pact/#readme _adapter_ library for writing our contract tests and want to rewrite one of them to https://github.com/pact-foundation/pact-js. But, after updating package `pact-foundation/pact` to version `"^10.1.3"`, - all our tests (that are written on jest-pact library) failed with Axios Network Error and following stack trace. So, even if I want to rewrite one of them on pact-js library, errors never go away. So, tell me please, what is going wrong? ``` Network Error at createError (node_modules/axios/lib/core/createError.js:16:15) at XMLHttpRequest.handleError (node_modules/axios/lib/adapters/xhr.js:117:14) at XMLHttpRequest.invokeTheCallbackFunction (node_modules/jsdom/lib/jsdom/living/generated/EventHandlerNonNull.js:18:28) at XMLHttpRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/create-event-accessor.js:35:32) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3) at XMLHttpRequestImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9) at fireAnEvent (node_modules/jsdom/lib/jsdom/living/helpers/events.js:18:36) at requestErrorSteps (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:131:3) at dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:60:3) at validCORSHeaders (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:75:5) at validCORSPreflightHeaders (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:89:8) at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:374:12) at Request._processResponse (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:228:12) at ClientRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:101:12)```

mvliannoi
2022-09-19 05:14
Interesting, after a downgrade to 10.1.2, an error seems more informative ``` console.error Error: Cross origin http://localhost forbidden at dispatchError (C:\...\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:63:19) at validCORSHeaders (C:\...\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:75:5) at validCORSPreflightHeaders (C:\...\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:89:8) at Request.<anonymous> (C:\...\node_modules\jsdom\lib\jsdom\living\xhr\xhr-utils.js:374:12) at Request.emit (node:events:390:28) at Request._processResponse (C:\...\node_modules\jsdom\lib\jsdom\living\helpers\http-request.js:228:12) at ClientRequest.<anonymous> (C:\...\node_modules\jsdom\lib\jsdom\living\helpers\http-request.js:101:12) at Object.onceWrapper (node:events:510:26) at ClientRequest.emit (node:events:390:28) at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:623:27) undefined at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45) at dispatchError (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:66:53) at validCORSHeaders (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:75:5) at validCORSPreflightHeaders (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:89:8) at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xhr/xhr-utils.js:374:12) at Request._processResponse (node_modules/jsdom/lib/jsdom/living/helpers/http-request.js:228:12)```

mvliannoi
2022-09-19 05:47
It seems like breaking changes that have been on upgrading from version 9.18.1 to 10.0.0 and upper

mvliannoi
2022-09-19 06:19
It seems like that is already a known https://github.com/pact-foundation/pact-js/issues/943

tjones
2022-09-19 07:08
Thanks for flagging this. I put a note on the issue that points at the problem.

mvliannoi
2022-09-19 08:28
Thank you, Timothy!

purushothamv02
2022-09-19 14:19
has joined #pact-js

matt.fellows
2022-09-19 14:37
Hey folks sorry I'm late to the party, I'm out at a conference. Looks like there is a bug with the cors options passing and/or core behaviour. We'll dig into this next week when I'm back.

lcruz
2022-09-19 23:05
has joined #pact-js

sweiba
2022-09-20 07:26
has joined #pact-js

zohaibse011
2022-09-20 11:07
Hi, I have a question regarding use of `eachKeyLike`. Is it possible to use `eachKeyLike` for nested (up-to 3 levels) dynamic keys? It seems that it only works on one level but in my use case, we can have nested dynamic keys and I just want to ensure the shape of the request/response payload. Any help would be appreciated. An example payload is as follows: ```{ "john-doe1": { "brown-fox": { "jumps": "over", "the": "lazy dog" } }, "john-doe2": { "brown-fox2": { "jumps": "over", "the": "lazy dog" } } }``` And the matcher which I am trying to use is as follows (roughly). It skips checking the first level of the keys (as expected) but then it compares the other keys literally: ```Matchers.eachKeyLike("some string", Matchers.eachKeyLike("some-string", Matchers.eachKeyLike("some-string", Matchers.string())))```

adam910
2022-09-20 12:32
has joined #pact-js

p.pommerencke
2022-09-20 14:00
has joined #pact-js

uglyog
2022-09-20 23:12
Unfortunately, eachKeyLike was designed to only work at the current level, and not propagate to children.

tjones
2022-09-20 23:23
This isn't asking for propagation, though - if the contract is `eachKeyLike(<key definition>, <value definition>)`, wouldn't we expect nested calls to match the example given here?

tjones
2022-09-20 23:25
https://docs.pact.io/implementation_guides/javascript/docs/matching say: > eachKeyLike(key: string, template: any) > Object where the keys itself is ignored, but the values must match a particular shape. Variants may be objects containing matching rules So, wouldn't we expect the example above to work?

uglyog
2022-09-20 23:30
Matchers for nested calls are enabled via propagation.

tjones
2022-09-20 23:47
Hmm ok. That feels like an implementation detail that users shouldn't need to know - but either way, the current documentation suggests that this case should be possible. I'm not sure what the correct update to the docs would be

tjones
2022-09-20 23:48
I would expect the nested call to only be "at the current level" as in at that level of nesting

tjones
2022-09-20 23:50
Like, for arbitrary keys where the values are typed arrays, I'd expect it to be written `Matchers.eachKeyLike("exampleKey", Matchers.eachLike(exampleArrayEntry))`

uglyog
2022-09-21 00:11
Coming back to the original question, if it is nested, how do you know when to stop? If the rule is eachKeyLike `\w+\-\w+`, then `"jumps"` and `"the"` are invalid keys.

uglyog
2022-09-21 00:12
How do you know to only apply the rule to the first two levels and not the third?

tjones
2022-09-21 00:15
Because that's all that is specified in the example: ```Matchers.eachKeyLike( // top level object has keys that are // any string, for example "some string", // and values that are Matchers.eachKeyLike( // objects with keys that are // any string, for example: "some-string", // and values that are: Matchers.eachKeyLike( // objects with keys that are: // any string, for example "some-string", // and values that are Matchers.string() // also any string )))```

tjones
2022-09-21 00:17
My understanding - from the docs - is that it's not possible to specify rules on what the keys are

uglyog
2022-09-21 00:17
Ah! Ok, that might be the DSL is just not setting up the matchers correctly, the each key matcher should work if it is specified at each level.

tjones
2022-09-21 00:18
```export const eachKeyLike = <T extends AnyTemplate>( keyTemplate: string, template: T ): Matcher<AnyTemplate> => ({ 'pact:matcher:type': 'values', value: { [keyTemplate]: template, }, });```

uglyog
2022-09-21 00:19
Yeah, that is not even setting up the eachKey matcher, only the eachValue one which ignores the keys

tjones
2022-09-21 00:20
Yes, that's what the documentation says

tjones
2022-09-21 00:20
This is expected to match the values only

tjones
2022-09-21 00:21
What @zohaibse011 is saying is that it doesn't do that beyond the first level, when it should.

tjones
2022-09-21 00:23
I can't find any documentation on what the format is supposed to be for the object


tjones
2022-09-21 00:23
it's not in here, but I suppose this is actually a different format for talking to the FFI?

tjones
2022-09-21 00:26
according to V4, https://github.com/pact-foundation/pact-specification/tree/version-4 there's `eachKey` and `eachValue`, but those were introduced later than V3's `eachKeyLike`, which I think is correctly the values matcher? I'm a bit confused

uglyog
2022-09-21 00:29
I haven't had a chance to document that format yet. It is the intermediate format that gets translated into the actual Pact format via the FFI call

uglyog
2022-09-21 00:31
So, yes, V3's `eachKeyLike` only works on values, and it should be able to apply to multiple levels, however, I imagine the matcher paths are not being setup correctly. It will need some time to investigate what is going on.

tjones
2022-09-21 00:32
Got it. Should we file an issue somewhere?

uglyog
2022-09-21 00:32
It's more than likely an FFI issue, lets start there. It may also be Pact-JS DSL issue, but less likely


uglyog
2022-09-21 00:46
Thank you!


anhtvuong
2022-09-21 01:39
has joined #pact-js

zohaibse011
2022-09-21 08:01
Thanks @tjones for being so active. I just woke-up and it is so good to see such level of support :blob-clap:

tjones
2022-09-21 08:03
You're welcome!

timothee.ville
2022-09-21 08:09
has joined #pact-js

tymoschuk.jane
2022-09-21 12:38
has joined #pact-js

tony.nguyen
2022-09-21 13:41
has joined #pact-js

matt.fellows
2022-09-21 13:42
:taco: for @tjones because :100:

sashi.kandru
2022-09-21 13:45
has joined #pact-js

matt.fellows
2022-09-21 13:50
:point_up: thanks Tim!

edouard.lopez
2022-09-21 14:12
When working a team to implement a provider verification, just installing `@pact-foundation/pact` trigger this message: ```[ERROR] 15:54:14 TypeError: destination.on is not a function``` We are using our `yarn dev` to start the app instead of what you do in the workshop that do as follow: ```"dev": "NODE_ENV='development' yarn generate-routes && yarn just-build && tsnd --inspect -r dotenv/config --respawn --files src/index.js",```

khaled.bali
2022-09-21 18:01
has joined #pact-js

m.mertens
2022-09-21 18:41
has joined #pact-js

he
2022-09-21 19:17
Hello there! Running some tests in node, but getting a surprising error: `pact-core@13.9.0: !!!!!!!!! PACT CRASHED !!!!!!!!!` After many pages of errors suggesting I file a bug, there is finally this line: `2022-09-21T19:09:23.148756Z ERROR ThreadId(02) pact_ffi::mock_server: Failed to start mock server - Could not start server: error creating server listener: Address already in use (os error 48)`. Anyone have any thoughts? It this indeed a bug that needs filing? ```@pact_foundation/pact 10.1.4 @pact_foundation/pact-core 13.9.0 node 16.17 mac os x```

he
2022-09-21 22:35
Eventually tracked it down! it appears I was failing to call `provider.verify()` ! Thanks!

matt.fellows
2022-09-21 23:46
ah!

matt.fellows
2022-09-21 23:47
So my guess is you?re using the old interface on the new upgrade (which is totally fine!) One of the reasons I like the new interface is that these lifecycle methods disappear along with this class of problem

matt.fellows
2022-09-21 23:48
This also suggests to me you?re hard coding a port - i?d usually opt to avoid doing that if you can and let the OS pick one for you (you can do this by not passing `port` and getting back a port from `setup()` )

matt.fellows
2022-09-22 00:06
Can you share a little more on the setup?

matt.fellows
2022-09-22 00:07
If it's a typescript project it could be a typescript config issue where the import order is incorrect


mforsman
2022-09-22 09:13
has joined #pact-js

edouard.lopez
2022-09-22 09:42
We workaround the issue by starting the server from within the test file, like you do in the workshop. We used the `yarn dev` as the team wasn't sure how to do it programmatically

shivendra.singh1
2022-09-22 10:04
has joined #pact-js

vaibhav.tiwari
2022-09-22 10:04
has joined #pact-js

akshaythakur2905
2022-09-22 10:06
has joined #pact-js

sukriti.kumari
2022-09-22 10:07
has joined #pact-js

p.kowalska
2022-09-22 10:35
has joined #pact-js

mazin.inaad
2022-09-22 13:21
has joined #pact-js

tjones
2022-09-23 03:54
Pact should detect a port conflict and not do the PACT CRASHED message, I think

tjones
2022-09-23 03:54
because it?s not a crash, it?s a misconfiguration

he
2022-09-23 04:10
Very insightful! Thanks bit of you! I?ll try to find the time to update those tests!

mastahfreak
2022-09-23 09:47
has joined #pact-js

kellie.persson
2022-09-23 17:50
has joined #pact-js

kbon
2022-09-26 13:58
has joined #pact-js

edouard.lopez
2022-09-26 14:24
How should one match a response value of `null` OR `string` with the matchers?

tjones
2022-09-26 15:04
1) To match null, just use `null`, no matcher is required 2) To match any string, use `string()`

tjones
2022-09-26 15:05
If your response might be either of two types (for example, a null, or a string), then you need two interactions.

tjones
2022-09-26 15:05
This is by design, there?s a docs page on it - one moment


tjones
2022-09-26 15:06
the tl;dr is that if pact let you specify `or` types, then you might incorrectly pass when your provider never actually returns the string

tjones
2022-09-26 15:08
There?s a subtlety here - a matcher is not for saying ?here?s a description of every response that the provider can make?, it?s for saying ?this test covers everything that would pass this matcher?

tjones
2022-09-26 15:17
Complete aside: I kind of think that returning `null` in a payload is an anti-pattern. Null isn?t really a member of `string`, and if you let it be nullable, then you have to write null checks everywhere. Often then you end up with `const someVar = response?.property?.field`, where each thing that could be null has a different meaning, but they?ve all collapsed to one very hard to reason about variable (what does it mean if `someVar` is null?). This makes bugs hard to find, as you can?t easily tell the difference between ?missing? and a programmer mistake. And allowing this kind of pattern discourages thinking about the unhappy path. I prefer explicit typing, where you would be able to reason about which fields must be present on each type of object, or you might have a reasonable default for fields that are not present - do you really need to have `null` and `""`? I think this in general leads to better designed APIs. Of course, you didn?t come here to ask if `null` should be in your payload - the above is all my opinion, and you can totally use pact to test payloads that are nullable. However, you?ll have to write a separate test for it, because if pact allowed an OR field, then you couldn?t be sure you?d verified it.

tanyaryzhova93
2022-09-26 18:53
has joined #pact-js

anand.krishnan
2022-09-27 10:45
has joined #pact-js

edouard.lopez
2022-09-27 10:54
Thanks for the subtlety and the suggestion about `null` and `""`

estelle.margoutin
2022-09-27 12:00
has joined #pact-js

tanyaryzhova93
2022-09-27 12:56
Hello! Could you please help me to understand why I cannot generate a contract, why I am getting the following error: ```The following request was expected but not received: Method: GET Path: /events/1cb9eb9e``` We are using React Testing Library and jest for testing. I am using PactV3 for contract testing. My code: ```const provider = new PactV3({ dir: path.resolve(process.cwd(), 'pacts'), consumer: 'MyConsumer', provider: 'MyProvider' }); const EXPECTED_BODY = { "name": "test event", "id": "1cb9eb9e", "teamId": "dummy_tid", }; function flush() { return new Promise((resolve) => { setTimeout(resolve, 0); }); } function createWrapper({ children }: { children: React.ReactElement }) { return <Provider store={makeStore()}>{children}</Provider>; } describe('GET /event/{id}', () => { it('returns an event', async () => { provider .given('I can get an event') .uponReceiving('a request for one event with the builder pattern') .withRequest({ method: 'GET', path: '/events/1cb9eb9e' }) .willRespondWith({ status: 200, body: EXPECTED_BODY, }); return provider.executeTest(async () => { //Arrange - we are using env var to provide a base url process.env.API_HOST = 'http://localhost:8082'; console.log(process.env.API_HOST); //Act const { result } = renderHook( () => useGetEventQuery({ id: '1cb9eb9e' }),{ wrapper: createWrapper, }); await flush(); console.log(result.current); // Assert: check the result expect(result.current.data?.id).toBe("1cb9eb9e"); }); }); });``` I receive an undefined data, the `console.log(result.current);` returns: ```{ status: 'pending', endpointName: 'getEvent', requestId: '6OJC915gB1DnUNUKk7zPP', originalArgs: { id: '1cb9eb9e' }, startedTimeStamp: 1664282999059, isUninitialized: false, isLoading: true, isSuccess: false, isError: false, data: undefined, currentData: undefined, isFetching: true, refetch: [Function: refetch] }``` Shouldn?t the data be set by Pact mock server? Please help me to understand what I am doing wrong and why my request is not being received by the mock server:pray:

tanyaryzhova93
2022-09-27 13:16
I?ve seen this message: https://pact-foundation.slack.com/archives/C9VBGLUM9/p1660526266380169 and the response: ```Ok. I can't help you other than tell you that the error message means that your request is not being received by the mock server. Either you're not sending it, or it's not going to the right place, or you are sending it, but it is not what you set up in the test, or your test isn't waiting for the request to be sent before asking pact if it was sent.``` 1. I can say that I send my request, it?s here: ```const { result } = renderHook( () => useGetEventQuery({ id: '1cb9eb9e' }),{ wrapper: createWrapper, });``` 2. also, I am waiting for the request is done, I use `await flush()` function after the request 3. As I can see, I send and try to get a correct data, I checked the response schema and I have all these provided fields. 4. I can?t get this `it's not going to the right place` , how I can check it?

yousafn
2022-09-27 13:42
The pact mock provider address is available via `mockserver.url` https://github.com/pact-foundation/pact-js/blob/master/docs/consumer.md I assume your code is making requests to ```http://localhost:8082``` looking at your code, in setting the env var, but the pact mock provider will be listening on a different port

yousafn
2022-09-27 13:42
the host defaults to localhost, but the port is randomly assigned. You can override this in the PactV3 constructor options

tanyaryzhova93
2022-09-27 13:55
I use `mockserver.url` now, such as ```return provider.executeTest(async (mockserver) => { //Arrange process.env.API_HOST = mockserver.url; console.log(process.env.API_HOST); //returns http://127.0.0.1:58968 //Act const { result } = renderHook( () => useGetEventQuery({ id: '1cb9eb9e' }), { wrapper: createWrapper, }); await flush(); console.log(result.current.data); // Assert: check the result expect(result.current.data?.id).toBe(EXPECTED_BODY.id); });``` but still having the issue `The following request was expected but not received` Any ideas what might be wrong? :disappointed:

yousafn
2022-09-27 13:58
Would imagine that process.env isn?t making effect on your client code and it?s still making a request to whatever it?s default url is. Can you provide a minimal example on GitHub or your code under test and not just the test code? Ty

tanyaryzhova93
2022-09-27 14:09
I cannot send you a link to repo, but I can send you code snippets. it?s how we send a request: ```import { baseApi } from './baseApi'; import { EventResponseSchema, EventId, } from './types'; export const eventsApi = baseApi .enhanceEndpoints({ addTagTypes: ['Events'] }) .injectEndpoints({ endpoints: (builder) => ({ getEvent: builder.query<EventResponseSchema, { id: EventId }>({ query: ({ id }) => `events/${id}`, providesTags: (result, error, { id }) => [{ type: 'Events', id }], }), }), }); export const { useGetEventQuery, } = eventsApi;``` Response schema is: ```export interface EventResponseSchema { id: string; name: string; teamId: string; updatedAt: string; createdAt: string; duration?: number; ... ... } export type EventId = string;``` baseApi ```import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/dist/query/react'; const apiHost = process.env.API_HOST; export const baseApi = createApi({ reducerPath: 'services', baseQuery: fetchBaseQuery({ baseUrl: apiHost ?? '/api', mode: 'cors', credentials: 'include', }), endpoints: () => ({}), });``` and by default we set `process.env.API_HOST` in the `src/setupJestEnv.ts` ```process.env.API_HOST = 'http://localhost:8000';```

yousafn
2022-09-27 14:13
try setting the port in the PactV3 constructor, so your port used, matches up. ```const provider = new PactV3({ dir: path.resolve(process.cwd(), 'pacts'), consumer: 'MyConsumer', provider: 'MyProvider', port: 8000 });``` Also I don't think your request has completed, as the response object status 'isLoading: true' and isSuccess/isLoading is false

tanyaryzhova93
2022-09-27 14:20
I?ve added port and added `waitForNextUpdate` to my request, such as ```const { result, waitForNextUpdate } = renderHook( () => useGetEventQuery({ id: '1cb9eb9e' }), { wrapper: createWrapper, }); await waitForNextUpdate();``` and now I am getting `isLoading:false` and the following error: ```{ status: 'rejected', endpointName: 'getEvent', requestId: 'K3YytVNiG5C7LnhFAtr07', originalArgs: { id: '1cb9eb9e' }, startedTimeStamp: 1664288258291, error: { status: 'FETCH_ERROR', error: 'FetchError: request to http://localhost:8000/events/1cb9eb9e failed, reason: connect ECONNREFUSED ::1:8000' }, isUninitialized: false, isLoading: false, isSuccess: false, isError: true, data: undefined, currentData: undefined, isFetching: false, refetch: [Function: refetch] }```

tanyaryzhova93
2022-09-27 14:23
if I don?t provide port, I see that ```console.log(process.env.API_HOST); //returns http://127.0.0.1:59891``` but error says the same as above: ```error: { status: 'FETCH_ERROR', error: 'FetchError: request to http://localhost:8000/events/1cb9eb9e failed, reason: connect ECONNREFUSED ::1:8000' },``` I would expect the port would be different rather than 8000

tanyaryzhova93
2022-09-27 14:32
can it happen because Pact mock server is not set on the 8000 port?

yousafn
2022-09-27 14:33
yes the pact mock server, as per the documentation link I sent you, sets the port to a randomly assigned value, your application configuration isn't picking up the process.env.value set in your test

yousafn
2022-09-27 14:34
Therefore the fetch error is correct, as you have no service running on port 8000. You can set this value directly in the pact configuration setup

tanyaryzhova93
2022-09-27 14:50
sorry, do I understand correctly that I just need to provide a `host` for my provider setup? Like this: ```const provider = new PactV3({ dir: path.resolve(process.cwd(), 'pacts'), consumer: 'MyConsumer', provider: 'MyProvider', host: process.env.API_HOST });``` if so, should I use the following test setup then? ```return provider.executeTest(async (mockserver) => { //Arrange process.env.API_HOST = mockserver.url; console.log(process.env.API_HOST);```

tanyaryzhova93
2022-09-27 15:17
no, it?s a Pact constructor, looks like a wrong place. If you have any example how pact configuration can be set, please share it with me :pray:

yousafn
2022-09-27 16:20
```const provider = new PactV3({ dir: path.resolve(process.cwd(), 'pacts'), consumer: 'MyConsumer', provider: 'MyProvider', port: 8000 });``` you wont need this ``` process.env.API_HOST = mockserver.url; console.log(process.env.API_HOST);```

tanyaryzhova93
2022-09-27 17:00
unfortunately, the error still exists ```error: { status: 'FETCH_ERROR', error: 'FetchError: request to http://localhost:8000/events/1cb9eb9e failed, reason: connect ECONNREFUSED ::1:8000' },``` My tests looks like this now: ```const provider = new PactV3({ dir: path.resolve(process.cwd(), 'pacts'), consumer: 'MyConsumer', provider: 'MyProvider', port: 8000, }); const EXPECTED_BODY = { name: "test event dd", id: "1cb9eb9e", teamId: "dummy_tid", }; function flush() { return new Promise((resolve) => { setTimeout(resolve, 0); }); } function createWrapper({ children }: { children: React.ReactElement }) { return <Provider store={makeStore()}>{children}</Provider>; } describe('GET /events/{id}', () => { it('returns an event', async () => { provider .given('I can get an event') .uponReceiving('a request for one event with the builder pattern') .withRequest({ method: 'GET', path: '/events/1cb9eb9e', }) .willRespondWith({ status: 200, body: EXPECTED_BODY, }); return provider.executeTest(async () => { //Act const { result, waitForNextUpdate } = renderHook( () => useGetEventQuery({ id: '1cb9eb9e' }), { wrapper: createWrapper, }); await waitForNextUpdate(); console.log(result.current); // Assert expect(result.current.data?.id).toBe(EXPECTED_BODY.id); }); }); });``` any ideas why it doesn?t work? :disappointed:

tanyaryzhova93
2022-09-27 18:40
ok, I was able to generate a contract. I just overwritten a default value for my `process.env.API_HOST = 'http://127.0.0.1:8001';` in the src/setupJestEnv.ts. Thank you for your support and quick response! you helped me a lot! :raised_hands:

tjones
2022-09-27 21:36
I wouldn?t expect to see react in your API test code- it is better practice to test your api layer outside of react

tanyaryzhova93
2022-09-27 21:55
what?s is the biggest drawback of using react in the tests?

tjones
2022-09-27 22:03
Unnecessarily complicated test setup, and since react is unrelated to the api code, if your components or hooks change the test will unnecessarily break or need to be updated

tjones
2022-09-27 22:05
Usually your hook has some call to an API function in it. Your test would exercise that function, and then your hook becomes just translating between that function and react

tanyaryzhova93
2022-09-27 22:24
good point, thank you for the explanations. I?ll think how I can to avoid of using react in my tests. Thanks a lot! :raised_hands:

criss.trifan
2022-09-28 05:36
has joined #pact-js

vipatel
2022-09-28 15:29
has joined #pact-js

olaoluphilip
2022-09-28 15:51
has joined #pact-js

vieira.jluiz
2022-09-28 17:20
has joined #pact-js

shuo.yang.2006
2022-09-28 19:48
has joined #pact-js

cyrus.devnomad
2022-09-28 21:38
Hello I've been trying to get an next.js example (using jest-pact adapter) working without success. I?ve installed an out of the box next.js application and tried to add an API app (jest-pact-example/pages/api/my_api.ts) and a jest-pact unit test (jest-pact-example/__tests__/my_api.ts) in the same way as shown in the Pact-JS V2 section of the following guide: https://github.com/pact-foundation/jest-pact But the mocked provider seems to never be reached by the axios calls as indicated by the following error message: ``` Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was expected but not received: Method: GET Path: /health``` Here is the code of my example: https://github.com/cyrusdevnomad/jest-pact-example The error is issued whenever I execute `npm run test` What could be the reason why the mock server is not reached? Thanks

yousafn
2022-09-28 22:20
Changing the method to the following (making it async and awaiting `client.getHealth()` ``` it("Testing the GET call", async () => { await client.getHealth().then((health: any) => { expect(health).toEqual("up"); console.log(`health: response: ${health}`); }); });``` which I don't quite understand yet :man-shrugging: because it has a then chained off it. But it's late and that should get you generating a pact file at least

yousafn
2022-09-28 22:20
Also thank you very much for the reproducible example, top marks from me :taco:

yousafn
2022-09-28 22:21
@cyrus.devnomad :taco:

cyrus.devnomad
2022-09-29 06:41
Yes, its working now indeed. Thank you very much. Nice to start my day with one problem solved and a taco on top of it :slightly_smiling_face:

yousafn
2022-09-29 09:25
Fabulous! Good luck Cyrus and good morning

nirmalcbaral
2022-09-29 15:27
has joined #pact-js

ruppel.julian
2022-09-29 20:03
has joined #pact-js

alipala.ist
2022-09-29 20:28
has joined #pact-js

educationextended
2022-09-30 04:59
has joined #pact-js

ross.butler
2022-09-30 11:22
has joined #pact-js

tanyaryzhova93
2022-09-30 11:50
Hi All! Could you please help me to understand how I should use `eachLike` matcher in my case, I checked several examples and messages in this chat but I still don?t see the problem. My API should return something like: ```{ "items": [ { "name": "test event 1", "id": "1cb9eb9e", "teamId": "dummy_tid", }, { "name": "test event 2", "id": "1cb9eb8a", "teamId": "dummy_tid", } ], "totalCount": 2 }``` The original response is much longer but my consumer uses only these fields. The consumer tests looks like: ```const EXISTING_EVENT_DATA = { "name": "test event 1", "id": "1cb9eb9e", "teamId": "dummy_tid", }; function createWrapper({ children }: { children: React.ReactElement }) { return <Provider store={makeStore()}>{children}</Provider>; } const provider = new PactV3({ dir: path.resolve(process.cwd(), 'contract-tests/pacts'), consumer: 'consumer', provider: 'provider', port: 8001, }); describe('Event queries', () => { it('should return all events', async () => { provider .given('I can get all events') .uponReceiving('a request to get all events') .withRequest({ method: 'GET', path: `/events`, query: { limit: '10', offset: '0', name: '' } }) .willRespondWith({ status: 200, body: { items: eachLike(EXISTING_EVENT_DATA), totalCount: like(1) }, }); return provider.executeTest(async () => { const REQUEST_PARAMS = { limit: 10, offset: 0, name: '' }; const { result, waitForNextUpdate } = renderHook( () => useGetEventsQuery(REQUEST_PARAMS), { wrapper: createWrapper, }); await waitForNextUpdate(); expect(result.current.data).toEqual({items: [EXISTING_EVENT_DATA], totalCount: 1}); }); }); });``` I am trying to use `eachLike` matcher here because I can have a lot of elements in an array. The contract is generated. But when I am trying to run the contract test agains my provider I am having errors: ``` Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "items": [ ... , - Pact::UnexpectedIndex, + Hash, ] } Description of differences -------------------------------------- * Actual array is too long and should not contain a Hash at $.items[1]``` Such test implementation works if I have just one record in my DB, but if I have more it returns the error above. Could you please help me to understand what this error means and what I am doing wrong?

matt.fellows
2022-09-30 11:52
Can you please share the pact file that is failing?

matt.fellows
2022-09-30 11:52
How are you verifying it? With Node or another language?

matt.fellows
2022-09-30 11:53
I think what's happening is that you're creating a V3 spec pact, but are verifying with a language that only supports v2

tanyaryzhova93
2022-09-30 11:54
With python, I use pact-python there. I installed it with: ```pip install pact-python```

tanyaryzhova93
2022-09-30 11:55
Sure, ```{ "consumer": { "name": "consumer" }, "interactions": [ { "description": "a request to get all events", "providerStates": [ { "name": "I can get all events" } ], "request": { "method": "GET", "path": "/events", "query": { "limit": [ "10" ], "name": [ "" ], "offset": [ "0" ] } }, "response": { "body": { "items": [ { "id": "1cb9eb9e", "name": "test event 1", "teamId": "dummy_tid" } ], "totalCount": 1 }, "headers": { "Content-Type": "application/json" }, "matchingRules": { "body": { "$.items": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.totalCount": { "combine": "AND", "matchers": [ { "match": "type" } ] } } }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.1.4" }, "pactRust": { "ffi": "0.3.11", "models": "0.4.5" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "provider" } }```

matt.fellows
2022-09-30 11:56
Yep that's the problem. The logs should specify it's verying a pact with a different spec and/or warn about matchers it doesn't understand

matt.fellows
2022-09-30 11:56
I'm on mobile, but you should be able to set the spec version on the constructor to V2 (there should be a type defined for that)

matt.fellows
2022-09-30 11:57
Thanks. As you can see, it's a v3 pact

tanyaryzhova93
2022-09-30 11:57
yep, I use v3 for consumer


matt.fellows
2022-09-30 11:59
It defaults to V3

tanyaryzhova93
2022-09-30 12:13
Now I see that the pact file has pactSpecification v2 but I still have the same problem on the provider?s side. Also, I can see that matching rules were updated in the pact. It?s my pact right now: ```{ "consumer": { "name": "consumer" }, "interactions": [ { "description": "a request to get all events", "providerState": "I can get all events", "request": { "method": "GET", "path": "/events", "query": "limit=10&name=&offset=0" }, "response": { "body": { "items": [ { "id": "1cb9eb9e", "name": "test event 1", "teamId": "dummy_tid" } ], "totalCount": 1 }, "headers": { "Content-Type": "application/json" }, "matchingRules": { "$.body.items": { "match": "type" }, "$.body.totalCount": { "match": "type" } }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.1.4" }, "pactRust": { "ffi": "0.3.11", "models": "0.4.5" }, "pactSpecification": { "version": "2.0.0" } }, "provider": { "name": "provider" } } ```

tanyaryzhova93
2022-09-30 12:18
Also, I tried to change the `pactSpecification` version manually, just put 2 instead of 3. I could see the discrepancies between actual and expected results after test run, but it didn?t apply matchers :disappointed:

matt.fellows
2022-09-30 12:39
You can't do that, the format of the JSON file and matchers are different. You need to generate it from code

matt.fellows
2022-09-30 12:40
What's the new error for the proper v2 generated pact look like? Please provide the whole log output so we can check for warnings etc

tanyaryzhova93
2022-09-30 12:45
There is my full log with failures: ```Verifying a pact between consumer and provider Given I can get all events a request to get all events with GET /events?limit=10&name=&offset=0 returns a response which WARN: Skipping set up for provider state 'I can get all events' for consumer 'consumer' as there is no --provider-states-setup-url specified. has status code 200 has a matching body (FAILED - 1) includes headers "Content-Type" which equals "application/json" Failures: 1) Verifying a pact between consumer and provider Given I can get all events a request to get all events with GET /events?limit=10&name=&offset=0 returns a response which has a matching body Failure/Error: expect(response_body).to match_term expected_response_body, diff_options, example Actual: {"items":[{"name":"test event da","start":"2021-02-21T11:42:21.954913+00:00","end":"2022-11-25T11:42:21.954913+00:00","ventureDuration":120,"location":"online","focus":[],"technology":[],"prerequisites":[],"challenges":[],"landingPage":null,"privacy":"private","branding":{"themeImage":"https://www.arabnews.com/sites/default/files/main-image/2019/02/11/1456561-87422913.jpg"},"testId":null,"id":"d5ac5cd4","teamId":"dummy_tid","createdAt":"2022-09-29T17:45:07.613494+00:00","updatedAt":"2022-09-29T17:45:07.613502+00:00","publishedAt":null,"status":"UNPUBLISHED","lifecycle":"STARTED","reportUrl":null},{"name":"test event dd","start":"2021-01-21T11:42:21.954913+00:00","end":"2022-10-25T11:42:21.954913+00:00","ventureDuration":120,"location":"online","focus":[],"technology":[],"prerequisites":[],"challenges":[],"landingPage":null,"privacy":"private","branding":{"themeImage":"https://www.arabnews.com/sites/default/files/main-image/2019/02/11/1456561-87422913.jpg"},"testId":null,"id":"1cb9eb9e","teamId":"dummy_tid","createdAt":"2022-09-21T15:44:43.831196+00:00","updatedAt":"2022-09-21T15:44:43.831203+00:00","publishedAt":null,"status":"UNPUBLISHED","lifecycle":"STARTED","reportUrl":null}],"totalCount":2} Diff -------------------------------------- Key: - is expected + is actual Matching keys and values are not shown { "items": [ ... , - Pact::UnexpectedIndex, + Hash, ] } Description of differences -------------------------------------- * Actual array is too long and should not contain a Hash at $.items[1] 1 interaction, 1 failure Failed interactions: PACT_DESCRIPTION='a request to get all events' PACT_PROVIDER_STATE='I can get all events' /Users/tatiana/projects/events/.venv/bin/pact-verifier --provider-base-url=http://localhost:8000 --pact-url=./pacts/consumer-provider.json # A request to get all events given I can get all events```

koen.jans
2022-09-30 15:06
has joined #pact-js

ksawery.karwacki
2022-10-01 13:12
has joined #pact-js

jesper.nilsson
2022-10-01 13:59
has joined #pact-js

tjones
2022-10-02 02:49
> The consumer tests looks like: Can you share the `import` statements from your tests?

tanyaryzhova93
2022-10-02 13:09
Sure, I use the following imports for my consumer test ```import React from 'react'; import { Provider } from 'react-redux'; import { renderHook } from '@testing-library/react-hooks' import path from "path"; import { PactV3, SpecificationVersion } from '@pact-foundation/pact'; import { like, eachLike } from '@pact-foundation/pact/src/v3/matchers'; import { useGetEventQuery, useGetEventsQuery } from "../../../src/services/events"; import { makeStore } from "../../../src/redux";``` Just in case, I am running the provider-verifier as: ``` pact-verifier --provider-base-url=http://localhost:8000 --pact-url=./pacts/consumer-provider.json```

mansillamarcelo90
2022-10-02 22:06
has joined #pact-js

tanyaryzhova93
2022-10-02 22:08
Please let me know if you have any ideas what might be wrong

tjones
2022-10-02 22:11
I don?t know, sorry. The pact test looks right to me. I?m not sure what Hash means in the context of this error message- one for @uglyog, maybe

yulia.tekin.86
2022-10-02 22:55
has joined #pact-js

rachel.anderson
2022-10-02 23:39
has joined #pact-js

matt.fellows
2022-10-03 01:34
Hi Tatiana. We?re probably at diminishing returns it terms of asking questions/responses. To be able to help now I think we?ll need an example repository that demonstrates the issue

matt.fellows
2022-10-03 01:35
It looks like the Ruby verifier to me (`Hash` is a Ruby class). The consumer was generated by the Rust core, the provider looks like a Python one via the Ruby core.

tjones
2022-10-03 01:38
Ah, right. Either way, the error message is not as helpful as it could be

tanyaryzhova93
2022-10-03 01:42
Unfortunately, I cannot share a repository, it?s a private one :( And yes, provider uses Python and FastApi. Generally, do you know why such error might happen? Might be the problem with nested matchers? Also, I saw https://stackoverflow.com/questions/42948214/pact-verify-provider-what-does-pactunexpectedindex-mean in the Internet, that it might happen that the received array is longer than was expected. But I?m not sure that?s my case. Maybe I can send you the whole response from my Api, maybe it can help somehow?

tanyaryzhova93
2022-10-03 01:44
just in case this is full response from my API, when I am trying to get all events: ```{ "items": [ { "name": "test event dd", "start": "2021-01-21T11:42:21.954913+00:00", "end": "2022-10-25T11:42:21.954913+00:00", "ventureDuration": 120, "location": "online", "focus": [], "technology": [], "prerequisites": [], "challenges": [], "landingPage": null, "privacy": "private", "branding": { "themeImage": "https://www.arabnews.com/sites/default/files/main-image/2019/02/11/1456561-87422913.jpg" }, "testId": null, "id": "1cb9eb9e-4529-41da-bb51-d92c5649ebca", "teamId": "dummy_tid", "createdAt": "2022-09-21T15:44:43.831196+00:00", "updatedAt": "2022-09-21T15:44:43.831203+00:00", "publishedAt": null, "status": "UNPUBLISHED", "lifecycle": "STARTED", "reportUrl": null }, { "name": "test event dd", "start": "2021-01-21T11:42:21.954913+00:00", "end": "2022-10-25T11:42:21.954913+00:00", "ventureDuration": 120, "location": "online", "focus": [], "technology": [], "prerequisites": [], "challenges": [], "landingPage": null, "privacy": "private", "branding": { "themeImage": "https://www.arabnews.com/sites/default/files/main-image/2019/02/11/1456561-87422913.jpg" }, "testId": null, "id": "1cb9eb9e-4529-41da-bb51-d92c5649ebcd", "teamId": "dummy_tid", "createdAt": "2022-09-21T15:44:43.831196+00:00", "updatedAt": "2022-09-21T15:44:43.831203+00:00", "publishedAt": null, "status": "UNPUBLISHED", "lifecycle": "STARTED", "reportUrl": null } ], "totalCount": 2 }```

tanyaryzhova93
2022-10-03 01:50
if it matters, the provider test passes with the current set up if there is just one record in the DB

tanyaryzhova93
2022-10-03 01:58
if all above is still useless without the repo, please let me know :pray:

tjones
2022-10-03 06:01
Just to confirm, this is a pact file that is generated by Pact-JS, without modification?

tjones
2022-10-03 06:01
You mentioned above about manually editing the pact file - you?re not supposed to do this, and it might result in unexpected behaviour

tjones
2022-10-03 06:06
Also, the pact file doesn?t look like it should for the test you gave - it doesn?t look like the `eachLike` matcher is being applied. Are you sure you are testing with the right pact file? Are you sure another test isn?t updating it with different data?

tanyaryzhova93
2022-10-03 10:44
> Just to confirm, this is a pact file that is generated by Pact-JS, without modification? Yes, it was generated with pact-js after test run. I didn?t change anything there manually. I generated the pact and shared it with my provider. Provider uses Python and fast api.

tanyaryzhova93
2022-10-03 10:46
Yes, I am sure that I use a correct pact file. And I don?t update any data within my tests, I just test GET endpoints for now.

tanyaryzhova93
2022-10-03 10:48
Maybe I use matchers incorrectly in my Consumer test?

tanyaryzhova93
2022-10-03 10:54
Also, maybe there is a workaround how I can test GET all events? I was thinking to use provider states and create a consumer test without matchers, it should work in pipeline because the DB will be empty every time. But if you want to run the contract test locally you might have existing data in DB and test will crash then?.


tjones
2022-10-03 11:18
It generates the following pact file, which (if I am reading the spec correctly) is not correct ```{ "consumer": { "name": "MyConsumer" }, "interactions": [ { "description": "A get request to get a pet 1845563262948980200", "providerState": "A pet 1845563262948980200 exists", "request": { "headers": { "api_key": "[]" }, "method": "GET", "path": "/v2/pet/1845563262948980200" }, "response": { "body": { "items": [ { "id": "1cb9eb9e", "name": "test event 1", "teamId": "dummy_tid" } ] }, "headers": { "Content-Type": "application/json" }, "matchingRules": { "$.body.items": { "match": "type" } }, "status": 200 } }, { "description": "A get request to get a pet 1845563262948980200", "providerState": "No pets exist", "request": { "headers": { "api_key": "[]" }, "method": "GET", "path": "/v2/pet/1845563262948980200" }, "response": { "status": 404 } } ], "metadata": { "pact-js": { "version": "10.1.4" }, "pactRust": { "ffi": "0.3.12", "models": "0.4.5" }, "pactSpecification": { "version": "2.0.0" } }, "provider": { "name": "pactWith v3" } }```

tjones
2022-10-03 11:18
The problem is this bit: ``` "matchingRules": { "$.body.items": { "match": "type" } },``` which is supposed to have a `min` item


tjones
2022-10-03 11:20
ah, right! The problem is that you have to use the V2 matcher

tjones
2022-10-03 11:24
Right - yes. If you use `spec: SpecificationVersion.SPECIFICATION_VERSION_V2,`, then it still generates the wrong pact file.

tjones
2022-10-03 11:26
in order to get the right results, you have to import the old `eachLike` matcher from `dsl/matchers`

tjones
2022-10-03 11:27
That will fix your problem @tanyaryzhova93

tanyaryzhova93
2022-10-03 11:27
yes, I am using spec, my setup looks like: ```const provider = new PactV3({ dir: path.resolve(process.cwd(), 'contract-tests/pacts'), consumer: 'mousedeer-events-consumer', provider: 'eventhub-provider', port: 8001, spec: SpecificationVersion.SPECIFICATION_VERSION_V2 });```

tanyaryzhova93
2022-10-03 11:27
let me try

tanyaryzhova93
2022-10-03 11:29
it helped!!!

tjones
2022-10-03 11:29
@matt.fellows - I?m not sure what the best fix is here. We have `PactV3` which takes the V3 matchers, but it takes an option called `spec` where you can tell it to use V2, but when you do that you need to use the V2 matchers. But they?re not called V2 matchers, they?re called `Matchers`. And, it?s not obvious that the V3 matchers might not be appropriate to pass to PactV3.

tjones
2022-10-03 11:30
Really this should be a concern of the core. The core should just figure it out for you, and users don?t have to know.

tanyaryzhova93
2022-10-03 11:30
It works as I expected. Thank you very much! you helped me to understand pact and how it works, you helped me a lot!

tjones
2022-10-03 11:30
Anyway, there?s the reproducible example :slightly_smiling_face:

tjones
2022-10-03 11:31
You?re welcome! Sorry about this, but also thanks for highlighting an area where we can improve the interface

tanyaryzhova93
2022-10-03 11:32
> Really this should be a concern of the core. The core should just figure it out for you, and users don?t have to know. +1, totally agree :+1:

matt.fellows
2022-10-03 11:59
>> Really this should be a concern of the core. The core should just figure it out for you, and users don?t have to know. +1 also

matt.fellows
2022-10-03 12:00
BUT, the `eachLike` for both V2 and V3 should actually be the same (they are both going to the same core!). I?m surprised that not passing in `min` to that matcher changes the behaviour. This makes me believe it probably never worked in the way it was intended (you can look at the definition of both variants of the code).

tjones
2022-10-03 12:00
It?s different according to the spec, I think

matt.fellows
2022-10-03 12:01
Sure, maybe. But the passing of a matcher to the core should be spec agnostic is my point (i.e. it?s a bug in the rust core, or at least confusing)


matt.fellows
2022-10-03 12:02
or put another way - the way matchers are passed to the rust core as it stands is deliberately agnostic to the spec version. The serialisation to the pact file of the matcher is based on the spec version

matt.fellows
2022-10-03 12:02
I think we?re saying the same thing?

matt.fellows
2022-10-03 12:02
In any case, THANK YOU. This exposed / reminded me of 2 problems that need to be solved

tjones
2022-10-03 12:02
``` 'pact:matcher:type': 'type',``` ^ This means ?shaped like this?

tjones
2022-10-03 12:03
it needs the `min` to know that it means ?repeatedly shaped like this?

matt.fellows
2022-10-03 12:03
I thought Ron actually created that matcher :thinking_face: But any case, will look tomorow :white_check_mark:

matt.fellows
2022-10-03 12:03
(reminder set, thank you!)

matt.fellows
2022-10-03 12:03
I?ll look tomorrow, I?m distracting myself from the presentation I?m supposed to be delivering at 7am :grimacing:

tjones
2022-10-03 12:03
Good luck!

jason.stahl
2022-10-03 22:19
has joined #pact-js

sreeragsa
2022-10-04 03:03
has joined #pact-js

sushant.soni
2022-10-04 14:23
Hello, I am trying to upgrade the provider to move to pact-js latest version (10.1.4). And the consumer (pact-js -v9.5.1) is still v9. However, the regex matching fails. What is wrong here :thinking_face:? ```Expected '/m/helpcenter/article?article=360006965937' to match '\/m\/helpcenter\/article\?article='```

tara.costin
2022-10-04 14:45
has joined #pact-js

sushant.soni
2022-10-05 09:26
Hello, Can someone please take a look and help here? :)

matt.fellows
2022-10-05 10:10
Can you please share the generated pact file?

sushant.soni
2022-10-05 13:23
Sure, sharing it with you privately.

oscar.barbamanzano
2022-10-05 14:18
has joined #pact-js

yousafn
2022-10-05 15:06
Tangibly related to Pact and some of you in JS land may be using it as an API client, Axios was released as `1.0.0` yesterday. :rockon: https://github.com/axios/axios/releases/tag/v1.0.0

matt.fellows
2022-10-06 05:43
wow!

yanov.alexander
2022-10-06 08:39
has joined #pact-js

bxbivc
2022-10-06 10:05
has joined #pact-js

curtis.scott
2022-10-06 11:27
has joined #pact-js

riley.lee
2022-10-06 11:30
has joined #pact-js

oliver.smyth
2022-10-06 11:34
has joined #pact-js

kevin.campos
2022-10-06 11:35
has joined #pact-js

pstrnad
2022-10-06 12:04
has joined #pact-js

rachelxelizabethh
2022-10-06 13:20
has joined #pact-js

pratish
2022-10-06 21:08
has joined #pact-js

ilia
2022-10-06 22:18
has joined #pact-js

sushant.soni
2022-10-07 13:02
Hey Matt, Did you get the chance to look into it? :slightly_smiling_face:

edudelta
2022-10-07 15:57
has joined #pact-js

nickm
2022-10-07 16:06
Hi all, is anyone using pact-js v9.18.1 with custom binaries? I?m trying to use the straight ruby gems instead of the standalone binaries to workaround the architecture limitations with travelling Ruby (yes, I know v10 uses the new Rust standalone, there are other things preventing us from making that change at the moment). I use `PACT_SKIP_BINARY_INSTALL=true` and point npm config `pact_binary_location` (via environment variable, `NPM_CONFIG_PACT_BINARY_LOCATION` to the folder with the executables, but it still doesn?t seem to be finding them. Anyone else have this working successfully?

olsen.lee.r
2022-10-07 18:29
has joined #pact-js

tjones
2022-10-08 11:14
I? don?t think this will work

tjones
2022-10-08 11:14
It needs the binaries, which are made with travelling Ruby

tjones
2022-10-08 11:15
I don?t think there?s a way to get these binaries directly with the gems

tjones
2022-10-08 11:15
but hey, I know the answer to your question

tjones
2022-10-08 11:16
> NPM_CONFIG_PACT_BINARY_LOCATION ^ This gives pact a custom location to download the binaries from > PACT_SKIP_BINARY_INSTALL=true ^ This tells pact not to download the binaries. *Don?t* set it if you want to provide custom binaries.

tjones
2022-10-08 11:16
Let us know if you get it working!

tjones
2022-10-08 11:18
> anyone using pact-js v9.18.1 with custom binaries? I?m not a maintainer any more, but I?ve not heard of anyone trying this

johndunning
2022-10-08 18:05
has joined #pact-js

matt.fellows
2022-10-08 22:29
Yes we don't support this Nick, but we could. Given it's the old 9.x.x line, we're not actively investing in new features but would happily accept a PR for it

matt.fellows
2022-10-08 22:29
The issue is the current config option supports a custom location of the compressed archive, but paths to the binaries. We could potentially make it discover the binaries elsewhere

nickm
2022-10-08 22:33
Thanks for responding folks. I was able to work around it by jerry-rigging our Dockerfiles to link the scripts installed by the gem into the expected location after npm install, that will work for now. We?re evaluating moving to v10 but we are trying to keep the tooling consistent across our stack and we aren?t quite comfortable enough just yet to pull the trigger on moving to v2 on our Go apps.

nickm
2022-10-08 22:35
The other alternative I looked at was packaging up those same scripts similar to how the stand-alone are packaged and then using the config option, but this ultimately got us there faster and without having to create a new artifact.

tjones
2022-10-09 06:06
You should be able to generate the older pact version with pact-js v10

kentooooo.1230
2022-10-09 17:49
has joined #pact-js

matt.fellows
2022-10-10 01:10
Not yet sorry, have been away this weekend

gpapadakis84
2022-10-10 12:32
has joined #pact-js

adam.witko
2022-10-10 13:59
Hey hey, a easy questions for those who know more than I do. From what I can tell `@pact-foundation/pact@^9` does not support V3 matchers, is that right?

adam.witko
2022-10-10 14:07
I get the following warnings so I assume this to be the case and the V3 matcher is falling back to purely match on type and ignore the V3 syntax: ```WARN: Ignoring unsupported combine AND for path $[0] WARN: Ignoring unsupported combine AND for path $[0]['customerPromises']```

matt.fellows
2022-10-10 21:22
This is correct Adam

dimundo
2022-10-11 07:23
hi! what would be proper way of handling of (probably) breaking change ?

yousafn
2022-10-11 08:18
if `name` was used by any consumers you could use ```{ "name": Object1, "new_name": Object1, "name2": Object2 }``` until they move over to update to use `new_name` and then you could retire `name` field


dimundo
2022-10-11 08:21
thing is ? whole js is verified ( could be solved , theoretically ) ? 2 objects ( `"name"` and `"new_name"`) will not be send :disappointed:

dimundo
2022-10-11 08:23
> The expand and contract pattern this is known thing, but not applicable now :disappointed:

yousafn
2022-10-11 08:24
Ie the provider won't update their schema to support the old and new format? and will just do it in a big bang?


yousafn
2022-10-11 08:26
if so your consumer code will have to be tolerant to the fact that the property can either come from `name` or `new_name` (but would have to make the decision as to what it does if both are present, which takes precedence, especially fi they were different)

yousafn
2022-10-11 08:27
> Ie the provider won't update their schema to support the old and new format? and will just do it in a big bang? Yeah that sucks, this is where showing them how difficult it is to support at your side as a consumer, helps in discussing the impact of a change. If you have more consumers that will be affected, that can help your argument

dimundo
2022-10-11 08:28
this is just a string in general, just a name of the same object has been changed to more descriptive now

dimundo
2022-10-11 08:29
which brought a pain

adam.witko
2022-10-11 09:20
Thanks @matt.fellows

daftpunkapi
2022-10-11 09:22
has joined #pact-js

matteo.demasi
2022-10-11 12:08
has joined #pact-js

raul.romitan.ext
2022-10-11 12:17
has joined #pact-js

dominikdieter.krichba
2022-10-11 13:23
has joined #pact-js

ulrich.keil
2022-10-11 13:26
has joined #pact-js

mitchell.l.cooper
2022-10-11 13:45
has joined #pact-js

torsten.wiederkehr
2022-10-11 14:24
has joined #pact-js

nickm
2022-10-11 18:10
Testing what was supposed to be a quick and easy demo out? can anyone tell me why this doesn?t work? ```const { Pact } = require("@pact-foundation/pact"); const apiProvider = new Pact({ consumer: "webapp", provider: "api", }); describe("pact", () => { beforeAll(async () => { await apiProvider.setup() await apiProvider.addInteraction({ state: "arriving", uponReceiving: "greeting", withRequest: { method: "GET", path: "/hello", }, willRespondWith: { status: 200, headers: { "Content-Type": "text/plain" }, body: "hello" } }) await apiProvider.addInteraction({ state: "departing", uponReceiving: "farewell", withRequest: { method: "GET", path: "/goodbye", }, willRespondWith: { status: 200, headers: { "Content-Type": "text/plain" }, body: "goodbye" } }) }); afterAll(() => apiProvider.finalize()); afterEach(() => apiProvider.verify()); it("says hello", async () => { const greeting = await (await fetch(`${apiProvider.mockService.baseUrl}/hello`)).text(); expect(greeting).toBe("hello"); }); it("says goodbye", async () => { const farewell = await (await fetch(`${apiProvider.mockService.baseUrl}/goodbye`)).text(); expect(farewell).toBe("goodbye") }); })``` Output: ```? pact npm test > pacter@1.0.0 test > jest [2022-10-11 18:08:10.521 +0000] INFO (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact-node@10.17.6: Creating Pact Server with options: {"timeout":30000,"consumer":"webapp","cors":false,"dir":"/private/tmp/pact/pacts","host":"127.0.0.1","log":"/private/tmp/pact/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"api","spec":2,"ssl":false,"pactFileWriteMode":"overwrite"} [2022-10-11 18:08:10.928 +0000] INFO (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact-node@10.17.6: Pact running on port 59384 [2022-10-11 18:08:11.046 +0000] INFO (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact@9.18.1: Setting up Pact with Consumer "webapp" and Provider "api" using mock service on Port: "59384" (node:86870) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) [2022-10-11 18:08:11.074 +0000] ERROR (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact@9.18.1: error making http request: Request failed with status code 500 console.error at node_modules/@pact-foundation/src/httpPact.ts:151:17 console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:152:17 console.error Actual interactions do not match expected interactions for mock MockService. Missing requests: GET /goodbye See /private/tmp/pact/logs/pact.log for details. at node_modules/@pact-foundation/src/httpPact.ts:153:17 [2022-10-11 18:08:11.100 +0000] ERROR (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact@9.18.1: error making http request: Request failed with status code 500 console.error at node_modules/@pact-foundation/src/httpPact.ts:151:17 console.error Pact verification failed! at node_modules/@pact-foundation/src/httpPact.ts:152:17 console.error Actual interactions do not match expected interactions for mock MockService. Unexpected requests: GET /goodbye See /private/tmp/pact/logs/pact.log for details. at node_modules/@pact-foundation/src/httpPact.ts:153:17 [2022-10-11 18:08:11.108 +0000] INFO (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact@9.18.1: Pact File Written [2022-10-11 18:08:11.108 +0000] INFO (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact-node@10.17.6: Removing Pact process with PID: 86906 [2022-10-11 18:08:11.109 +0000] INFO (86870 on http://FTPHXMMV4R.dyn.ourparadisefalls.com): pact-node@10.17.6: Deleting Pact Server with options: {"timeout":30000,"consumer":"webapp","cors":false,"dir":"/private/tmp/pact/pacts","host":"127.0.0.1","log":"/private/tmp/pact/logs/pact.log","logLevel":"INFO","pactfileWriteMode":"overwrite","provider":"api","spec":2,"ssl":false,"port":59384,"pactFileWriteMode":"overwrite"} FAIL ./index.test.js pact ? says hello (31 ms) ? says goodbye (10 ms) ? pact ? says hello Pact verification failed - expected interactions did not match actual. at new VerificationError (node_modules/@pact-foundation/pact/src/errors/verificationError.js:19:42) at node_modules/@pact-foundation/src/httpPact.ts:157:17 ? pact ? says goodbye expect(received).toBe(expected) // http://Object.is equality - Expected - 1 + Received + 2 - goodbye + {"message":"No interaction found for GET /goodbye","interaction_diffs":[]} + 47 | it("says goodbye", async () => { 48 | const farewell = await (await fetch(`${apiProvider.mockService.baseUrl}/goodbye`)).text(); > 49 | expect(farewell).toBe("goodbye") | ^ 50 | }); 51 | }) at Object.toBe (index.test.js:49:22) ? pact ? says goodbye Pact verification failed - expected interactions did not match actual. at new VerificationError (node_modules/@pact-foundation/pact/src/errors/verificationError.js:19:42) at node_modules/@pact-foundation/src/httpPact.ts:157:17 Test Suites: 1 failed, 1 total Tests: 2 failed, 2 total Snapshots: 0 total Time: 1.127 s, estimated 2 s Ran all test suites.``` For some reason, the mock server never seems to pick up the ?goodbye? interaction. The interesting thing is? it doesn?t matter if I swap the order of the interactions, it?s still the ?goodbye? one that isn?t expected.

nickm
2022-10-11 18:14
oh horse apples, I just figured it out?

nickm
2022-10-11 18:18
For the record? I was verifying with each test, so each test was only picking up one of the two expected interactions. :facepalm:

yousafn
2022-10-11 19:59
Thanks for letting others know buddy, and don't worry we've all had that :facepalm: moment

matt.fellows
2022-10-11 22:02
The issue is the `afterEach` block is verifying that the calls are made after each individual `it` block. Given you setup 2 interactions, the `provider.verify()` will be called after one of the `it` blocks, and will fail because it expects two

matt.fellows
2022-10-11 22:03
The requests aren?t linked, so separate them out into separate `describe` blocks

matt.fellows
2022-10-11 22:03
Take a look at https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js which has a number of different tests, you can see they are split out

matt.fellows
2022-10-11 22:03
you could also look at using `jest-pact` or `mocha-pact` to reduce the boilerplate

matt.fellows
2022-10-11 22:06
`verify()` also resets the test context, removing any expected interactions so any subsequent requests won?t be expected

matt.fellows
2022-10-11 22:06
if you can share the log file we can validate it for certain, but the test setup is out of whack

mikey214
2022-10-11 22:32
has joined #pact-js

mikey214
2022-10-12 04:21
Hey, been stuck on this error for a while and can?t seem to figure out the issue. Anyone have any ideas? ```[2022-10-12 04:12:55.982 +0000] INFO (7982 on MBP190F6MD6V): pact@10.1.4: Verifying provider [2022-10-12 04:12:55.992 +0000] INFO (7982 on MBP190F6MD6V): pact-core@13.9.1: Verifying Pacts. [2022-10-12 04:12:55.993 +0000] INFO (7982 on MBP190F6MD6V): pact-core@13.9.1: Verifying Pact Files 2022-10-12T04:12:56.799691Z INFO ThreadId(13) pact_verifier::pact_broker: Fetching path '/' from pact broker 2022-10-12T04:12:58.135082Z INFO ThreadId(13) pact_verifier::pact_broker: Fetching path '/pacts/provider/dummy-provider/for-verification' from pact broker 2022-10-12T04:12:59.029343Z ERROR ThreadId(13) pact_verifier: Failed to load pact - Could not load pacts from the pact broker 'https://mikeyhaven.pactflow.io' 2022-10-12T04:12:59.029372Z WARN ThreadId(13) pact_matching::metrics: Failures: 1) Failed to load pact - Could not load pacts from the pact broker 'https://mikeyhaven.pactflow.io' There were 1 pact failures [2022-10-12 04:12:59.470 +0000] ERROR (7982 on MBP190F6MD6V): pact-core@13.9.1: Verification unsuccessful FAIL dummy-app-api apps/dummy-app-api/tests/pact/provider/verify.pact.ts (5.593 s) Dummy Provider Pact Verification ? validates the expectations of the consumer (3489 ms) ? Dummy Provider Pact Verification ? validates the expectations of the consumer Verfication failed at ../../node_modules/@pact-foundation/pact-core/src/verifier/nativeVerifier.ts:50:20``` This is `verify.pact.ts`: ```import { Verifier } from '@pact-foundation/pact'; import { VerifierOptions } from '@pact-foundation/pact/src/dsl/verifier/types'; describe('Dummy Provider Pact Verification', () => { const options: VerifierOptions = { provider: 'dummy-provider', providerBaseUrl: `http://localhost:3000`, pactBrokerUrl: "https://mikeyhaven.pactflow.io", pactBrokerToken: process.env.PACT_BROKER_TOKEN, providerVersion: "1.0.0", providerVersionBranch: "feat/example-branch", consumerVersionSelectors: [ { mainBranch: true, latest: true }, { branch: 'master', latest: true }, { tag: 'release-candidate', latest: true }, { matchingBranch: true, latest: true }, ], enablePending: true, includeWipPactsSince: '2022-09-01', publishVerificationResult: true, }; const verifier = new Verifier(options); it('validates the expectations of the consumer', () => { return verifier.verifyProvider(); }); });``` Additional notes: ? I?m using PactJS with a version of `v10.1.4` but I pretty much got the same error on `v10.1.0`. ? I publish using V3 specification. ? I?ve checked using `logLevel: DEBUG` and it doesn?t provide any other useful contextual information as to why it can?t find the pacts associated with the provider. ? I even checked using `pact-broker describe-pacticipant --name dummy-provider` and it correctly shows that the broker recognizes it. ? I also made sure the token is a read/write token. Below is my PactFlow:

mikey214
2022-10-12 04:24
Additional information from the consumer / publication side: ```import { PactV3 as Pact, PactV3Options as PactOptions, V3MockServer } from '@pact-foundation/pact'; const options: PactOptions = { dir: path.resolve(process.cwd(), 'pacts'), consumer: 'dummy-consumer', provider: 'dummy-provider', }; const provider = new Pact(options); ...<rest of the code is just the tests which isn't important>``` Publication: I?m executing this command ```pact-broker publish ./pacts/ \ --broker-base-url="$BROKER_URL" \ --broker-token="$BROKER_TOKEN" \ --consumer-app-version="1.0.0" \ --branch="feat/example-branch" \ --tag="feat/example-branch"```

xi.luo
2022-10-12 05:11
has joined #pact-js

matt.fellows
2022-10-12 06:13
thanks for the report and the detail! Can you please share the `DEBUG` logs? Might not be helpful to you, but definitely helpful to us

tjones
2022-10-12 06:29
^ This is all correct. When you `addInteraction`, you're actually setting up the test expectation, not describing a mock server. So if that expectation is not met, then the test will fail.

kim.crowe
2022-10-12 10:15
has joined #pact-js

mikey214
2022-10-12 13:11
Sure, here they are @matt.fellows : ```[2022-10-12 13:08:27.494 +0000] INFO (88817 on MBP190F6MD6V): pact@10.1.4: Verifying provider [2022-10-12 13:08:27.500 +0000] INFO (88817 on MBP190F6MD6V): pact@10.1.4: debug request/response logging enabled [2022-10-12 13:08:27.506 +0000] INFO (88817 on MBP190F6MD6V): pact-core@13.9.1: Verifying Pacts. [2022-10-12 13:08:27.507 +0000] INFO (88817 on MBP190F6MD6V): pact-core@13.9.1: Verifying Pact Files [2022-10-12 13:08:27.507 +0000] DEBUG (88817 on MBP190F6MD6V): pact-core@13.9.1: Initalising native core at log level 'debug' [2022-10-12 13:08:27.534 +0000] DEBUG (88817 on MBP190F6MD6V): pact-core@13.9.1: the optional ffi function 'pactffiVerifierSetFilterInfo' was not executed as it had non-fatal validation errors: [2022-10-12 13:08:27.538 +0000] DEBUG (88817 on MBP190F6MD6V): pact-core@13.9.1: the optional ffi function 'pactffiVerifierSetConsumerFilters' was not executed as it had non-fatal validation errors: [2022-10-12 13:08:27.538 +0000] DEBUG (88817 on MBP190F6MD6V): pact-core@13.9.1: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: [2022-10-12 13:08:27.538 +0000] DEBUG (88817 on MBP190F6MD6V): pact-core@13.9.1: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: 2022-10-12T13:08:27.561099Z DEBUG ThreadId(01) pact_ffi::verifier::handle: Pact source to verify = PactBrokerWithDynamicConfiguration(https://mikeyhaven.pactflow.io, provider_name='dummy-provider', enable_pending=true, include_wip_since=Some("2022-09-01"), provider_tags=[], provider_branch=Some("feat/example-branch"), consumer_version_selectors='[ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: Some(true), deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: Some(true), branch: None, matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: Some(true), deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: Some("master"), matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: Some("release-candidate"), fallback_tag: None, latest: Some(true), deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: Some(true), deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: Some(true) }], auth=Token(1LS3******************)') 2022-10-12T13:08:27.572036Z DEBUG ThreadId(01) 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 2022-10-12T13:08:27.572096Z DEBUG ThreadId(01) 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 2022-10-12T13:08:28.243384Z INFO ThreadId(01) pact_verifier::pact_broker: Fetching path '/' from pact broker 2022-10-12T13:08:28.255770Z DEBUG tokio-runtime-worker hyper::client::connect::dns: resolving host="http://mikeyhaven.pactflow.io" 2022-10-12T13:08:28.295159Z DEBUG ThreadId(01) hyper::client::connect::http: connecting to 13.238.95.102:443 2022-10-12T13:08:28.511744Z DEBUG ThreadId(01) hyper::client::connect::http: connected to 13.238.95.102:443 2022-10-12T13:08:28.950997Z DEBUG ThreadId(01) h2::client: binding client connection 2022-10-12T13:08:28.951070Z DEBUG ThreadId(01) h2::client: client connection bound 2022-10-12T13:08:28.951891Z DEBUG ThreadId(01) h2::codec::framed_write: send frame=Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 } 2022-10-12T13:08:28.953604Z DEBUG ThreadId(01) hyper::client::pool: pooling idle connection for ("https", http://mikeyhaven.pactflow.io) 2022-10-12T13:08:28.954581Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Settings { flags: (0x0), max_concurrent_streams: 128, initial_window_size: 65536, max_frame_size: 16777215 } 2022-10-12T13:08:28.955035Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Settings { flags: (0x1: ACK) } 2022-10-12T13:08:28.955061Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=WindowUpdate { stream_id: StreamId(0), size_increment: 2147418112 } 2022-10-12T13:08:28.955369Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=WindowUpdate { stream_id: StreamId(0), size_increment: 5177345 } 2022-10-12T13:08:28.955410Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Headers { stream_id: StreamId(1), flags: (0x5: END_HEADERS | END_STREAM) } 2022-10-12T13:08:29.417038Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Settings { flags: (0x1: ACK) } 2022-10-12T13:08:29.417062Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::settings: received settings ACK; applying Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 } 2022-10-12T13:08:29.553567Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) } 2022-10-12T13:08:29.553902Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(1) } 2022-10-12T13:08:29.553928Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) } 2022-10-12T13:08:29.556121Z DEBUG ThreadId(01) pact_verifier::pact_broker: Link URL is templated 2022-10-12T13:08:29.556155Z DEBUG ThreadId(01) pact_verifier::pact_broker: templated URL = https://mikeyhaven.pactflow.io/pacts/provider/{provider}/for-verification 2022-10-12T13:08:29.560715Z DEBUG ThreadId(01) pact_verifier::pact_broker: final URL = https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification 2022-10-12T13:08:29.561527Z INFO ThreadId(01) pact_verifier::pact_broker: Fetching path '/pacts/provider/dummy-provider/for-verification' from pact broker 2022-10-12T13:08:29.561568Z DEBUG ThreadId(01) hyper::client::pool: reuse idle connection for ("https", http://mikeyhaven.pactflow.io) 2022-10-12T13:08:29.562336Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Headers { stream_id: StreamId(3), flags: (0x5: END_HEADERS | END_STREAM) } 2022-10-12T13:08:29.928715Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Headers { stream_id: StreamId(3), flags: (0x4: END_HEADERS) } 2022-10-12T13:08:29.928741Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(3) } 2022-10-12T13:08:29.929248Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(3), flags: (0x1: END_STREAM) } 2022-10-12T13:08:29.930233Z DEBUG ThreadId(01) pact_verifier::pact_broker: templated URL = https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification 2022-10-12T13:08:29.930674Z DEBUG ThreadId(01) pact_verifier::pact_broker: final URL = https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification 2022-10-12T13:08:29.930844Z DEBUG ThreadId(01) pact_verifier::pact_broker: Sending JSON to https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification using POST: {"providerVersionTags":[],"includePendingStatus":true,"includeWipPactsSince":"2022-09-01","consumerVersionSelectors":[{"latest":true,"mainBranch":true},{"latest":true,"branch":"master"},{"tag":"release-candidate","latest":true},{"latest":true,"matchingBranch":true}],"providerVersionBranch":"feat/example-branch"} 2022-10-12T13:08:29.930891Z DEBUG ThreadId(01) hyper::client::pool: reuse idle connection for ("https", http://mikeyhaven.pactflow.io) 2022-10-12T13:08:29.930991Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Headers { stream_id: StreamId(5), flags: (0x4: END_HEADERS) } 2022-10-12T13:08:29.931013Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Data { stream_id: StreamId(5), flags: (0x1: END_STREAM) } 2022-10-12T13:08:30.479482Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Headers { stream_id: StreamId(5), flags: (0x4: END_HEADERS) } 2022-10-12T13:08:30.479510Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(5) } 2022-10-12T13:08:30.479518Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(5), flags: (0x1: END_STREAM) } 2022-10-12T13:08:30.479609Z DEBUG ThreadId(01) pact_verifier::pact_broker: error Response for pacts for verification ContentError("Request to pact broker URL 'https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification' failed - HTTP status client error (400 Bad Request) for url (https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification)") 2022-10-12T13:08:30.479920Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=GoAway { error_code: NO_ERROR, last_stream_id: StreamId(0) } 2022-10-12T13:08:30.479936Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::connection: Connection::poll; connection error error=GoAway(b"", NO_ERROR, Library) 2022-10-12T13:08:30.480710Z ERROR ThreadId(01) pact_verifier: Failed to load pact - Could not load pacts from the pact broker 'https://mikeyhaven.pactflow.io' 2022-10-12T13:08:30.480734Z DEBUG ThreadId(01) pact_matching::metrics: 'PACT_DO_NOT_TRACK' environment variable is set, will not send metrics Failures: 1) Failed to load pact - Could not load pacts from the pact broker 'https://mikeyhaven.pactflow.io' There were 1 pact failures 2022-10-12T13:08:30.481178Z DEBUG ThreadId(01) pact_plugin_driver::plugin_manager: Shutting down all plugins [2022-10-12 13:08:30.482 +0000] DEBUG (88817 on MBP190F6MD6V): pact-core@13.9.1: shutting down verifier with handle 0 [2022-10-12 13:08:30.482 +0000] DEBUG (88817 on MBP190F6MD6V): pact-core@13.9.1: response from verifier: null, 1 [2022-10-12 13:08:30.482 +0000] ERROR (88817 on MBP190F6MD6V): pact-core@13.9.1: Verification unsuccessful FAIL dummy-app-api apps/dummy-app-api/tests/pact/provider/verify.pact.ts (5.896 s) Dummy Provider Pact Verification ? validates the expectations of the consumer (2990 ms) ? Dummy Provider Pact Verification ? validates the expectations of the consumer Verfication failed at ../../node_modules/@pact-foundation/pact-core/src/verifier/nativeVerifier.ts:50:20 Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 6.127 s```

mikey214
2022-10-12 13:58
Output from describe-participant: ```npx pact-broker describe-pacticipant --name dummy-provider --broker-base-url https://mikeyhaven.pactflow.io --broker-token <redacted> Name: dummy-provider Display Name: Dummy Provider Created At: '2022-10-12T04:11:47+00:00'```

matt.fellows
2022-10-12 21:44
These two lines seem to be the issue: ```2022-10-12T13:08:29.930844Z DEBUG ThreadId(01) pact_verifier::pact_broker: Sending JSON to https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification using POST: {"providerVersionTags":[],"includePendingStatus":true,"includeWipPactsSince":"2022-09-01","consumerVersionSelectors":[{"latest":true,"mainBranch":true},{"latest":true,"branch":"master"},{"tag":"release-candidate","latest":true},{"latest":true,"matchingBranch":true}],"providerVersionBranch":"feat/example-branch"} ... 2022-10-12T13:08:30.479609Z DEBUG ThreadId(01) pact_verifier::pact_broker: error Response for pacts for verification ContentError("Request to pact broker URL 'https://mikeyhaven.pactflow.io/pacts/provider/dummy-provider/for-verification' failed - HTTP status client error (400 Bad Request) for url ```

matt.fellows
2022-10-12 21:44
note the `400` bad request

matt.fellows
2022-10-12 21:46
I think it?s the additional `latest` key

matt.fellows
2022-10-12 21:46
That?s only valid for tags


mikey214
2022-10-12 22:01
wow, that was it! thank you so much @matt.fellows! Does this mean that by just specifying `branch`, it will verify the latest pact for that branch?

mikey214
2022-10-12 22:14
also I?m thinking I should make a ticket to track this. It would be best if we can update the typescript interfaces to disallow having incompatible options together so devs can see if they messed up their configuration from intellisense

suganyamuthukumar03
2022-10-13 11:01
has joined #pact-js

francis.bonneau
2022-10-13 18:30
has joined #pact-js

matt.fellows
2022-10-13 22:18
That would be great if you could please raise an issue

naf
2022-10-14 10:55
has joined #pact-js

werner.lauterfeld
2022-10-14 11:09
has joined #pact-js

jharms
2022-10-14 15:04
has joined #pact-js

daniel.cronin
2022-10-14 16:15
has joined #pact-js

txomin.sirera
2022-10-14 18:57
has joined #pact-js

jr
2022-10-15 20:48
has joined #pact-js

sasankdts
2022-10-16 08:48
has joined #pact-js

wil.pannell
2022-10-16 16:56
has joined #pact-js

abhishek.lamba
2022-10-16 22:08
Hello Team,

abhishek.lamba
2022-10-16 22:09
does requestFilter only add the headers or its also replaces the value if the header present in pact?

abhishek.lamba
2022-10-16 22:11
for me If Authorization header doesn't exist in the pact then its adds value of the header from requestFilter. If Authorization header exists in the contract then I expect it to replace the value but it doesn't.

tjones
2022-10-16 22:24
I don?t think I understand the question, sorry. Could you elaborate on what you?re trying to do?

abhishek.lamba
2022-10-17 06:55
Hi Timothy, I want to replace the value of Authorization in header from requestFilter.

abhishek.lamba
2022-10-17 07:28
But currently, It only adds the value of Authorization in header if its not present in the Contract. If authorization header exist in the contract it doesn't override it

tjones
2022-10-17 07:32
What are you trying to do?

abhishek.lamba
2022-10-17 07:41
i am trying to override Authorization header value while doing provider side verification

tjones
2022-10-17 07:51
Ah, I think I understand. The request header filters aren?t supposed to be for overriding the contract

tjones
2022-10-17 07:52
If authorisation is part of the contract, it should be in the contract and not overridden. If it isn?t, then you can override it

tjones
2022-10-17 07:53
What I usually do is stub the auth, so in the contract I give a dummy token, which I control with a provider state

tjones
2022-10-17 07:54
I usually use tokens like TOKEN or TOKEN_WITH_ADMIN_SCOPE

tjones
2022-10-17 07:54
If you don?t want to do that, then you can leave it out of the contract and inject it later

tjones
2022-10-17 07:57
I like the stubbed token approach because it means the type of the token is not part of the contract. But what the token _means_ is part of the contract

tjones
2022-10-17 07:58
So you might have a provider state that is `?TOKEN_WITH_ADMIN_SCOPE? is a valid token that has admin privileges`

abhishek.lamba
2022-10-17 08:44
So as I understood if we have, Authorization header in the contract we can't override it, right?

tjones
2022-10-17 08:44
I believe that is correct

tjones
2022-10-17 08:45
If you could override the contract, then you could have a falsely passing verification

adam.witko
2022-10-17 10:50
:wave: I have https://github.com/pact-foundation/pact-js-core/pull/411 open and ready for eyes. I haven't worked in some of these areas of pact-js-core and I'm a bit unaware of the extent of testing for this feature. I don't know if an integration test when no pacts can be found is required. I can see the `verifier.integration.spec.ts` specifies pactUrls, so I dont' know if any test following this pattern stresses the behaviour the new `faiIfNoPactsFound` option attempts to execute

sirisha.kunaparaju
2022-10-17 11:01
has joined #pact-js

gardeepti
2022-10-17 11:02
has joined #pact-js

vedant3620
2022-10-17 11:08
has joined #pact-js

priyanka.bbit
2022-10-17 11:11
has joined #pact-js

priyanka.bbit
2022-10-17 11:19
Hi :wave: . I am getting the below issue while trying to run my provider test to validate the pact created by the consumer test. Does anyone have an idea what would cause it? ``` 1.1) has a matching body $ -> Actual map is missing the following keys: id,number```

nvourlakis
2022-10-17 11:21
has joined #pact-js

oliwia.koch
2022-10-17 13:51
has joined #pact-js

bluediamondpc
2022-10-17 14:18
has joined #pact-js

nicholas.difelice
2022-10-17 15:16
has joined #pact-js

remington.otoole
2022-10-17 15:20
has joined #pact-js

matt.lucido
2022-10-17 15:23
has joined #pact-js

molly.mccarthy
2022-10-17 15:28
has joined #pact-js

tjones
2022-10-17 22:17
This is saying that the body of the response doesn?t have `id` or `number` in it, but pact is expecting these fields

tjones
2022-10-17 22:18
eg: ```{ "id_field": 1, "other_number": 2 }``` instead of ```{ "id": 1, "number": 2 }```

slack1211
2022-10-18 07:24
has joined #pact-js

mekala.kalyan
2022-10-18 12:49
has joined #pact-js

jpullifrone
2022-10-18 17:05
has joined #pact-js

jorge.bo
2022-10-18 18:42
has joined #pact-js

orhun
2022-10-18 19:42
has joined #pact-js

kwo.ding
2022-10-19 08:24
has joined #pact-js

kwo.ding
2022-10-19 08:33
hi team, is there an example on how to get https://github.com/pactflow/pact-msw-adapter work with playwright? trying to pass the `window.msw.worker` (react app started with msw mocks) to the `setupPactMswAdapter` but getting the following error: ```TypeError: mswMocker.events.on is not a function at ../node_modules/@pactflow/pact-msw-adapter/dist/pactMswAdapter.js:39 37 | const activeRequestIds = []; // Pending requests which are still valid 38 | const matches = []; // Completed request-response pairs > 39 | mswMocker.events.on("request:match", (req) => {```

priyanka.bbit
2022-10-19 08:34
Thank you !

kwo.ding
2022-10-19 08:36
set up here: ```const worker: any = await page.evaluate('window.msw.worker'); const pactMswAdapter = setupPactMswAdapter({ worker, options: { consumer: "theConsumer", providers: { ["someProviderService"]: ["/endpoint"], }, debug: true, }, });```

ankit.jain
2022-10-19 10:41
has joined #pact-js

yousafn
2022-10-19 11:12
No I haven't tested with Playwright, can you create a minimal reproducible example in a repo you can share. I have an example of an adapter created specifically for Playwright https://github.com/pactflow/example-bi-directional-consumer-playwright Using the pattern documented here https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/pact/#converting-mocks-into-a-pact-compatible-format There is a setup guide here for MSW https://docs.pactflow.io/docs/bi-directional-contract-testing/tools/msw and you can create an example playwright test under this folder https://github.com/pactflow/pact-msw-adapter/tree/main/examples Are you actually loading the msw worker in your web app https://github.com/pactflow/pact-msw-adapter/blob/bdae1c64fb996d1820e8223dbf6e258e77a21991/examples/react/src/index.js#L9-L11


matt.fellows
2022-10-19 11:26
I?m wondering if it makes sense to create your own adapter here - I don?t know playwright and MSW well enough, but would you use them together?


yousafn
2022-10-19 11:33
https://pact-foundation.slack.com/archives/C9VBGLUM9/p1666178801707839?thread_ts=1666168422.500859&cid=C9VBGLUM9 You could, as msw can also be injected into webapp. UI test frameworks that have access to network requests can do it natively, similar to the pact cypress adapter, and the demo script and example for playwright, which uses playwrights native methods, rather than injecting msw :+1:

yousafn
2022-10-19 11:35
As to which approach someone would choose and why, not sure yet, injecting mocks into your webapp, outside of your testing framework could be useful for rapid prototyping if you want to see you application running locally perhaps

edeandre
2022-10-19 12:09
has joined #pact-js

tjones
2022-10-19 12:09
This probably belongs in #pactflow

stanlisaus
2022-10-19 12:11
has joined #pact-js

stanlisaus
2022-10-19 12:13
hi team, does anyone have examples of using Pact within a React + Mobx-state-tree setting? In my current project when I initialise the service to fire the request it goes through the stores attempting to initialise all the services and causing issues.

tjones
2022-10-19 12:43
You shouldn?t be starting anything to do with react during a pact test

tjones
2022-10-19 12:43
Ideally your API layer is separate from the react code (irrespective of whether you are using pact)


tjones
2022-10-19 12:47
^ This doesn?t have the state management you?re asking for, but the principle is the same


tjones
2022-10-19 12:48
^ This commit shows the differences

tjones
2022-10-19 12:48
Once your API layer is separate from react, you can test it however you like

kwo.ding
2022-10-19 14:53
@yousafn sure, I created a small example with playwright here: https://github.com/kwoding/pact-msw-adapter/tree/feature/add-playwright-example

nikolaasrondon
2022-10-19 17:29
has joined #pact-js

fquijada
2022-10-19 21:25
has joined #pact-js

kkalan
2022-10-20 03:52
has joined #pact-js

kwo.ding
2022-10-20 06:33
so this example covers the same use case as the cypress example, having a react app loaded with msw mocks, and using playwright to test against it, somehow passing the window.msw.worker to the adapter doesn?t work

dyptorden
2022-10-20 10:24
has joined #pact-js

olawale.akande
2022-10-20 11:52
has joined #pact-js

olawale92.tech
2022-10-20 11:56
has joined #pact-js

calen.pennington
2022-10-20 13:43
has joined #pact-js

calen.pennington
2022-10-20 13:46
Hi! Is it possible to run pact consumer mocks inside a pact provider test? When I do it, I?m getting an `ECONNREFUSED` error when my code tries to contact the consumer (but if I have a dedicated test that is just loading the consumer, everything works as expected).

muhammud.naseeruddin
2022-10-20 16:04
has joined #pact-js

xuw
2022-10-20 16:38
has joined #pact-js

matt.johnson
2022-10-20 17:25
has joined #pact-js

matt.johnson
2022-10-20 17:27
Hello! How can I determine which versions of Pact-JS are compatible with a particular broker version?

matt.johnson
2022-10-20 17:28
I?m running Docker with 2.79.1.2. If I upgrade to use pact@10.0.0 do I need to upgrade the broker?

kwo.ding
2022-10-20 19:43
updated the example on the branch, which produces the error stated in this thread, just run `yarn run example:test:playwright`

tjones
2022-10-20 20:01
Read the change log for pact-js

matt.fellows
2022-10-20 20:39
Why do you want to do this?

sasankdts
2022-10-21 11:19
Example provider failing due to pact verification

yousafn
2022-10-21 12:21
Just to manage your expectations, I am unlikely to look at this anytime soon, but the source code is there so you are welcome to debug and propose a PR if required. Otherwise there is an alternative method for using Pact + Playwright together linked in this thread

kwo.ding
2022-10-21 12:22
i understand, thanks for your response and info

yousafn
2022-10-21 12:23
Agreed, what is your use case here?

calen.pennington
2022-10-21 12:26
Right. I figured I might need to answer that. I?m trying to establish contracts around our graphql server. I?ve successfully put contracts up for things that are depending on it, but I wanted to use the opportunity provided by the provider tests on the graphql server side to establish contracts on the providers that the graphql server uses, so that if a requirement for a particular API disappeared from the graphql consumer, and that implied that we no longer needed a contract with a provider, that contract would disappear.

calen.pennington
2022-10-21 12:27
I understand the recommendations not to put contracts on passthough services, but graphql is doing a bunch of data reformulation, so it?s not a strict passthrough. I could mock out the providers used by the graphql server during its own provider tests, but using the consumer wire mocks instead seemed to give an extra advantage (as outlined above)

bhavyashree.r
2022-10-22 06:10
has joined #pact-js

matt.fellows
2022-10-23 23:56
You can definitely test GraphQL, I wouldn?t think that?s an issue

matt.fellows
2022-10-23 23:57
I can?t see where you are setting up the mock expectations though?

matt.fellows
2022-10-23 23:58
In any case, it?s going to be hard to use the mock service, because you won?t be able to target the mocks at a very granular level. You could do it, but I see it being a difficult setup to maintain

mosesgwenne
2022-10-24 06:10
has joined #pact-js

calen.pennington
2022-10-24 13:14
I elided the interactions out (line 36). My issue is that I?m getting `ECONNREFUSED` from the consumer mock while running my provider tests. If I just manually use the same interactions, and manually set up a single consumer test, I can get it to work. So either I have something wrong w/ the consumer-inside-provider-test setup (around ordering, maybe, or correct `await`s), or there?s something in the FFI libs that?s preventing me from running both provider driver and consumer driver at the same time

calen.pennington
2022-10-24 13:15
My supposition, at the moment, is that the upstream states will give me enough info to correctly set the downstream state expectations. That will really only be borne out one way another w/ time, but I have to get past this technical issue first

j.watkins12
2022-10-24 21:13
has joined #pact-js

matt.fellows
2022-10-25 01:14
> or there?s something in the FFI libs that?s preventing me from running both provider driver and consumer driver at the same it?s possible, albeit I think it should be able to work. It?s not a use case we have really considered in supporting

matt.fellows
2022-10-25 01:16
If you were able to put together a small repro for us to look into, we could take a look into it. It looks like a clever setup, that?s for sure

mosesgwenne
2022-10-25 04:38
Hi @channel, Need your expertise, please. I tried the Order API sample from https://docs.pact.io/5-minute-getting-started-guide. I am able to generate the pact file but the provider test is failing. The error is not that detailed I don?t know what I am missing. I am using Playwright as my Test Runner. I am attaching my code for both consumer and provider test and the pact file generated. Pls check if you have time. Thanks so much

tony.odonnell
2022-10-25 07:56
has joined #pact-js

yousafn
2022-10-25 09:04
Playwright is used for automation of web apps, rather than testing API's. Why have you chosen that as your test runner? A working code sample from that page is shown here https://github.com/YOU54F/pact-5-minute-getting-started-guide/tree/main Using a unit test runner, in this case mocha

martin.schlegel
2022-10-25 11:24
has joined #pact-js

stefan.zivkovic
2022-10-25 12:35
has joined #pact-js

calen.pennington
2022-10-25 13:08
I?ll try to extract a minimal example out (may end up solving my problem while doing so, if I figure out what the minimal requirements are)

alexander.friesen
2022-10-25 14:07
has joined #pact-js

mspector
2022-10-25 14:45
has joined #pact-js

thomas.peyregne
2022-10-25 14:53
has joined #pact-js

noor.hashem
2022-10-25 17:48
How can more than one consumer point to the same provider, meaning how can we have multiple pact verification files on the provider side for different endpoints to point to multiple consumers?

noor.hashem
2022-10-25 17:52
For more clarification: a consumer might have several pact tests each for one endpoint or for different parts of a provider. But they all point to the same provider. So how can the provider differentiate between these consumers and know which provider verification to run for which consumer?

jsirju
2022-10-25 20:22
has joined #pact-js

matt.fellows
2022-10-25 22:09
Each consumer should refer to the provider by the same name

matt.fellows
2022-10-25 22:09
Then the provider uses selectors to fetch contracts for all of its consumers


matt.fellows
2022-10-25 22:09
If you haven?t already done so, this is recommended for setting up a best practice workflow https://docs.pactflow.io/docs/workshops/ci-cd

matt.fellows
2022-10-25 22:10
(i?d strongly encourage not using the webhookless flow unless you have reasons you can?t use webhooks)

mosesgwenne
2022-10-25 22:34
I?ll try this. thank u thank u

tjones
2022-10-25 22:59
> So how can the provider differentiate between these consumers and know which provider verification to run for which consumer? Why would the provider need to do this?

tjones
2022-10-25 23:00
What are you trying to do?

a.emmanuelmendoza
2022-10-25 23:42
has joined #pact-js

yousafn
2022-10-26 00:38
Hey @mosesgwenne, I got a bit of downtime this evening so had a quick look, got a working example from your sample files, thanks for providing those. https://github.com/YOU54F/pact-playwright-example the `main` branch has a working example as shown in the actions run here - https://github.com/YOU54F/pact-playwright-example/actions/runs/3325277851/jobs/5497793496 There does seem to be an issue showing failing verifications - https://github.com/YOU54F/pact-playwright-example/actions/runs/3325286761/jobs/5497811824 In the above test run, I changed the consumer to expect the provider to use the endpoint `/order` rather than `/orders` It correctly fails but the error messaging isn't useful - it might just be an issue with my test setup, I'll have a look into that tomorrow On the topic of Pact and the scope of your test, how does your client application that you are testing, interact with its provider? In your example repo, you are using Playwright to issue the requests to the provider, in which to generate the pact file. Traditionally you would be testing the actual client that issues the requests in your application, to ensure that what you encode in the pact file, is what your client application is issuing. Otherwise you tie you provider in knots trying to verify scenarios which don't match reality. Maybe providing some info on your use case would be useful :+1:

mosesgwenne
2022-10-26 00:47
You got it working. You are the best. I?ll check it out. Thanks so much. At this time, we don?t have a particular client. We are new to contract testing and trying out possible tools we can use in our team. We are eyeing Playwright to be our e2e automation tool and I thought I?d use it instead of axios/mocha for this Pact tests since in Playwright I can do the assertions and api requests using it. It?s all built in to Playwright. It doesn?t require too many third party tools.

yousafn
2022-10-26 01:12
Maybe take a look at https://github.com/pactflow/example-bi-directional-consumer-playwright for how you could use playwright to listen to routes being called from your web application under test, and mocking out those responses, using its native mocking. https://github.com/pactflow/example-bi-directional-consumer-playwright/blob/bb8e1fd5801fc4a47ad43bf36cbfc6a8b71a08ee/test/productByQuery.spec.js#L11-L24 we then transform that into a pact file, as we know that our client application issued that request. A more manageable scope itssplitting out your code that issues the api requests in your web application, so it is super quick to test. See below for a simple example https://github.com/TimothyJones/react-api-layer-example All the best in your Pact journey!

mosesgwenne
2022-10-26 01:14
Hi @channel, Is there a way I can install pact without having to install Visual Studio? I get error as attached. I also tried to install node-gyp but I get the same error.

matt.fellows
2022-10-26 01:16
Like many node modules, It needs the C/C++ compiler to build the native extensions

mosesgwenne
2022-10-26 01:19
VisualStudioCode has a C/C++ Compiler extension. Would pact recognize it?

mosesgwenne
2022-10-26 01:28
We don?t have a working web app yet. It?s really just me trying every tool I can find that?ll make our lives easier. Just creating some POC at the moment. But this one will surely help when we get to that point where we have a working web app. Thank you, Yousaf

matt.fellows
2022-10-26 01:56
I doubt it, unless the binaries are on the system path and discoverable to the node ecosystem

tjones
2022-10-26 02:16
> VisualStudioCode has a C/C++ Compiler extension. Would pact recognize it? This isn't really a pact question - it's more of a node ecosystem / node-gyp question

tjones
2022-10-26 02:17
From memory, VSCode's C/C++ extension doesn't include the compilers - I think you still need those installed in the system

tjones
2022-10-26 02:18
Is there some reason you can't install Visual Studio? It is free

tjones
2022-10-26 02:18
This stackoverflow answer might be helpful if you can't - but I think the best path is to install the tools it is expecting: https://stackoverflow.com/questions/57879150/how-can-i-solve-error-gypgyp-errerr-find-vsfind-vs-msvs-version-not-set-from-c


mosesgwenne
2022-10-26 03:33
I was told we are not allowed to install the community version in our company machine and the professional VS one costs a lot per user. Just wondering if there?s any way around that VS prerequisite. I?ll check these links. Thanks thanks

tjones
2022-10-26 03:49
You used to be able to install just the build tools

tjones
2022-10-26 03:51
You'll have more problems than just pact / node-gyp if you're not allowed to install visual studio's build tools on a windows machine for development.

mosesgwenne
2022-10-26 06:33
It seems VS Build Tools is allowed even without VS license. Will use that instead. Thank u

mosesgwenne
2022-10-26 06:45
Yey, it also worked on my machine. Thanks Yousaf!

emma.colleran
2022-10-26 13:05
has joined #pact-js

aaron.swerlein
2022-10-26 15:10
has joined #pact-js

stefan.zivkovic
2022-10-26 16:32
@stefan.zivkovic has left the channel

jeronimo
2022-10-26 17:50
has joined #pact-js

matthew.beattie
2022-10-26 20:14
has joined #pact-js

harrison.le
2022-10-26 21:47
has joined #pact-js

amandasstecz
2022-10-26 21:57
has joined #pact-js

amandasstecz
2022-10-26 22:11
Hello, me too! I'm trying to install pact for javascript in my computer. I use VS Code but when installing the pact dependency several node-gyp errors appeared.

amandasstecz
2022-10-26 22:11
:face_with_spiral_eyes:

amandasstecz
2022-10-26 22:14
I came to Slack to find a solution!

uglyog
2022-10-26 22:23
@mosesgwenne can you raise an issue for this? I find it unacceptable that a Node.js package requires Python and C++ to install

amandasstecz
2022-10-26 22:30
Great! :heart: It would be amazing if it were simpler to install this package.

amandasstecz
2022-10-26 22:31
Because it can create some barriers between the devs and the tools. I say this because I am studying the tool before to suggest the implementation in the company where I work.

amandasstecz
2022-10-26 22:36
I'm new to Pact. But I believe I went through the same "pains" as other people to install the tool. Thank you for understanding @uglyog!

tjones
2022-10-26 22:38
> I find it unacceptable that a Node.js package requires Python and C++ to install @uglyog This is more of a "node ecosystem on windows" problem than a pact problem

tjones
2022-10-26 22:39
They've always treated windows as a second class citizen. For example, `npm install` on windows takes minutes to do what takes seconds on a mac / linux machine

tjones
2022-10-26 22:40
I'm just flagging that it might not be realistic for pact to fix this (unless we don't use the rust core via native bindings)

tjones
2022-10-26 22:41
There might be some solutions using prebuilt binaries, but then we're back at the problems we used to have

matt.fellows
2022-10-26 23:22
> There might be some solutions using prebuilt binaries, but then we?re back at the problems we used to have I think we could do both. In the cases with corporate proxies that don?t allow it, they?ll have to fallback to node gyp (or optional dependencies, which have a number of issues). For everyone else, pre-gyp could be made to download the pre-made binaries and skip the need for the build chain.

matt.fellows
2022-10-26 23:23
> Hello, me too! I?m trying to install pact for javascript in my computer. I use VS Code but when installing the pact dependency several node-gyp errors appeared. Can you please elaborate on the VS Code bit. Are you installing with VS Code, or just coding in VS Code?

tjones
2022-10-26 23:24
I think there might be some confusion caused by the error message. It essentially says "please install visual studio", and people might quite reasonably think "yeah, I already have Visual Studio Code", but Visual Studio is not Visual Studio Code.

matt.fellows
2022-10-26 23:30
yeah, that?s a good point. I find it interesting that npm tells you to specifically install Visual Studio!

matt.fellows
2022-10-26 23:30
(maybe that?s the only viable toolchain on Windows?)

tjones
2022-10-26 23:32
Yes, `gyp` is looking for the visual studio build tools. I think those are the most idiomatic on windows, whether they're the only ones, I don't know. I find it pretty surprising that people have windows development machines without these tools installed - but it has been a long time since I developed anything on windows, so the ecosystem might have changed.

tjones
2022-10-26 23:33
Regardless, this is a key change between v9 and v10 of pact-js - I think it's worth putting in the migration guide. It's not _technically_ a breaking change, but it's worth calling out.

amandasstecz
2022-10-26 23:41
@matt.fellows just Visual Studio Code, Matt

amandasstecz
2022-10-26 23:53
I tried to install from the VSCode terminal, running the command as says in the documentation: ``` npm i @pact_foundation/pact```

amandasstecz
2022-10-27 00:02
@tjones I don't think it's uncommon, in my experience it's the first time I've come across the need to install C++ and Py to use a testing tool in a React or Node application. Usually just installing the package does all the work under the hood.

amandasstecz
2022-10-27 00:03
But the technical discussion is valid.

amandasstecz
2022-10-27 00:04
A windows customer is a potential customer. :grinning:

tjones
2022-10-27 00:20
I think probably most packages are now using pre-gyp

amandasstecz
2022-10-27 00:22
Yes, I also think

christianoliver.table
2022-10-27 06:15
has joined #pact-js

zehra.lichtenberg
2022-10-27 08:08
has joined #pact-js

mosesgwenne
2022-10-27 08:41
I found that the provider tests are failing on gitbash terminal. They pass on powershell. That is soo odd. The error message does not really say anything about what?s missing.

mosesgwenne
2022-10-27 08:42
Amy idea @yousafn ?

mosesgwenne
2022-10-27 08:44
So is this a valid issue we need to create a ticket for? It worked after I installed Python and VS Build Tools.


sushant.soni
2022-10-27 10:27
Hello We are in the middle of upgrade to V3 spec for one of the consumer written in TypeScript. When the pact file is generates, I see this warning, which is really conufsing ```WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V3), and will be upgraded``` The existing spec is V2 and we are migrating to V3. How come V3 is older? or is there an issue here actually?

vzviaruha
2022-10-27 11:29
has joined #pact-js

vzviaruha
2022-10-27 12:02
Hi I'm having trouble with Pact mock server - it looks to be configured as in the manual, but from logs it looks like it starts and then shuts down: ```[09:38:07] : [Step 1/1] 2022-10-27T09:38:07.687602Z DEBUG ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 2 } addr_str=0x7ffceb12faf0 tls=false}: pact_mock_server::mock_server: Started mock server on 127.0.0.1:34851 [09:38:07] : [Step 1/1] 2022-10-27T09:38:07.692042Z 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 [09:38:07] : [Step 1/1] 2022-10-27T09:38:07.692066Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID 669f159b-22ac-4e8d-b0c6-378f489ba070 - MockServerMetrics { requests: 0 } [09:38:07] : [Step 1/1] 2022-10-27T09:38:07.692087Z DEBUG ThreadId(01) pact_mock_server::mock_server: Mock server 669f159b-22ac-4e8d-b0c6-378f489ba070 shutdown - MockServerMetrics { requests: 0 } [09:38:07] : [Step 1/1] 2022-10-27T09:38:07.692105Z DEBUG tokio-runtime-worker hyper::server::shutdown: signal received, starting graceful shutdown``` Attached is test code (I've removed some tests for readability as they have same logic) and build logs. Could you please help with this?

michael.laird
2022-10-27 13:38
has joined #pact-js

vzviaruha
2022-10-27 13:54
ok, seems like the issue was with test not being async - after changes, it started to work

yousafn
2022-10-27 14:07
```const path = require("path"); const request = require("superagent"); const { PactV3 } = require("@pact-foundation/pact"); const chai = require("chai"); const expect = chai.expect; const { integer, timestamp, boolean, string, eachLike, like, reify } = require("@pact-foundation/pact").MatchersV3; const tenantId = "acme"; const projectId = "agcstest"; const authHeader = { Authorization: "Bearer token" }; const getBackupsListUrl = `/api/v3/databases/backups/${tenantId}/${projectId}`; const backupsListExpectedBody = eachLike({ id: like(1), name: like("string"), type: like("string"), startedAt: like("timestamp"), completedAt: like("timestamp"), sourceProjectId: like("string"), sourceEnvironmentId: like("string"), tenantId: like("string"), projectId: like("string") }); describe("Pact", () => { const provider = new PactV3({ dir: path.resolve(process.cwd(), "pacts"), consumer: "DatabaseServiceUI", provider: "DatabaseService", logLevel: "debug" }); describe("GET to database backups list", () => { it("returns list of DB backups", () => { provider .given(`GET to ${getBackupsListUrl}`) .uponReceiving("request to list all DB backups") .withRequest({ method: "GET", path: getBackupsListUrl }) .willRespondWith({ status: 200, body: backupsListExpectedBody }); return provider.executeTest((mockserver) => { return request .get(mockserver.url + getBackupsListUrl) .set(authHeader) .then((res) => { expect(res.body).to.have.deep.members( reify(backupsListExpectedBody) ); }); }); }); }); });``` had a quick look. this is using mocha/chai. 1. you have matchers in your expected payload, in your `expect(res.body).toMatchObject(backupsListExpectedBody);` - you can use the `reify` method to strip the matchers off the body, otherwise you are expected your api client to return you an object with pact matchers 2. Your `like` matcher needs to have a valid value, `string` is not defined `like("example string to add into the example")` will match any string. so not `like(string)` unless you have `string` declared as a string value `const string = "some example value"` 3. You can wrap the `backupsListExpectedBody` object, in an `eachLike` matcher, which will say match me an array with at least 1 of these shape objects in.

yousafn
2022-10-27 14:07
generated pact file ```{ "consumer": { "name": "DatabaseServiceUI" }, "interactions": [ { "description": "request to list all DB backups", "providerStates": [ { "name": "GET to /api/v3/databases/backups/acme/agcstest" } ], "request": { "method": "GET", "path": "/api/v3/databases/backups/acme/agcstest" }, "response": { "body": [ { "completedAt": "timestamp", "id": 1, "name": "string", "projectId": "string", "sourceEnvironmentId": "string", "sourceProjectId": "string", "startedAt": "timestamp", "tenantId": "string", "type": "string" } ], "headers": { "Content-Type": "application/json" }, "matchingRules": { "body": { "$": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].completedAt": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].id": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].name": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].projectId": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].sourceEnvironmentId": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].sourceProjectId": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].startedAt": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].tenantId": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$[*].type": { "combine": "AND", "matchers": [ { "match": "type" } ] } } }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.1.4" }, "pactRust": { "ffi": "0.3.12", "models": "0.4.5" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "DatabaseService" } }```

yousafn
2022-10-27 14:07
thanks for the test file :+1:

vzviaruha
2022-10-27 14:08
Thank you @yousafn just a qq - is there any way to use type matchers in JS?

yousafn
2022-10-27 14:10
https://github.com/pact-foundation/pact-js/blob/master/docs/matching.md this might help buddy, not sure on the exact question, this will do type matching based on the example value you add in, so it infers the type.

vzviaruha
2022-10-27 14:11
thanks!

michael.laird
2022-10-27 14:40
Hi - are there any known issues with Pact and GitLab CI/CD? My pipeline fails with the below error when running `yarn install` on GitLab but having no issues locally. `error ../node_modules/@pact-foundation/pact-core: Command failed.`

pedropho18
2022-10-27 21:33
has joined #pact-js

juancesarvillalba
2022-10-27 21:43
has joined #pact-js

matt.fellows
2022-10-27 21:45
Any more details than that? e.g. logs? What version of yarn? Is it running in a container (and if so, have you seen https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md

matt.fellows
2022-10-27 21:46
Can you please share the test setup? It's not likely to be an issue but worth taking a peek

tjones
2022-10-27 22:53
I can confirm that pact works fine in GitLab

angad.singh
2022-10-28 11:07
has joined #pact-js

oroceo.ian
2022-10-28 20:04
has joined #pact-js

oroceo.ian
2022-10-28 20:49
hello, I have dumb question, is there a way to ignore specific objects during provider verification or a matching for an array that ignores whatever is inside and just verify that there's an array (I might have misunderstood something in the documentation). Here's a snippet of a sample response... the first question, I wanted to ignore `ignoreMe` from verification if possible. If there's none, the second question of matching, the data in object `ignoreMe` are generated based on what's available data. TIA for answering the question of a QA :D

benjamin
2022-10-28 21:09
has joined #pact-js

benjamin
2022-10-28 21:18
hello ? i?ve been integrating pact into our testing and seems like examples use both Pact and PactV3? Am i ahead of the curve with V3?

benjamin
2022-10-28 21:42
So my consumer uses 3 api endpoint from 2 services. If I follow the V3 setup i have 2 pact providers setup for each api. Is there a v3 equivalent to provider.setup() as opposed to having to nest provider.executeTest calls?

matt.fellows
2022-10-29 11:04
V3 is totally fine to use. We have examples in both because the previous version was out for a long time and in the most use. But V3 would be my recommendation

matt.fellows
2022-10-29 11:05
You should avoid having multiple providers per test, unless you _really_ need to. Take the mindset of a unit test here, and that should get you fair way to making the tests a lot cleaner.

matt.fellows
2022-10-29 11:05
Yes, if you want to ignore them, don?t put them in the expectation

matt.fellows
2022-10-29 11:06
i.e. if you ask for `[{...}]` then you?re telling pact the things inside the array is important. If you just want to know it?s an array , then `[]` should do.

matt.fellows
2022-10-29 11:06
BUT, you probably don?t want to do that. I?m assuming you do care what?s inside them?

emailpankaj.agarwal
2022-10-29 13:26
has joined #pact-js

matt.fellows
2022-10-30 09:58
The point of Pact is to only mock the parts of the data you need, and not all of the possible data. By doing this, you communicate to the provider what they actually need to do, to do their job. By asking for everything, they now don?t know what you actually need and they can?t remove fields / endpoints that aren?t actually in use

krishnakanth219
2022-10-30 22:59
has joined #pact-js

joshua.mclatchie
2022-10-31 02:21
has joined #pact-js

mosesgwenne
2022-10-31 04:58
Hi @channel, Do you know how I can enable pact to give more details on the error message? When verification fails on the provider testing part, there's not much to go on based on the msg. I have tried logLevels "debug", "trace" and "info" but the same insufficient message is returned. Does not give me enough to workout what the problem is and what to fix. Thanks for the time. ```[2022-10-24 06:22:29.452 +0000] ERROR (33504 on xxxxxxx): pact-core@13.10.0: Verification unsuccessful [2022-10-24 06:22:29.452 +0000] TRACE (33504 on xxxxxxx): pact@10.1.4: Verification failed(Verfication failed), closing server Pact verification failed :( Error: Verfication failed at C:\Users\d832076\Desktop\Workspace\pact-sample-test\node_modules\@pact-foundation\pact-core\src\verifier\nativeVerifier.ts:50:20``` Followed @yousafn?s scripts here https://github.com/YOU54F/pact-playwright-example

matt.fellows
2022-10-31 05:02
hmm my suggestion is to setup a test repo that you can share with us to reliably reproduce the problem for. If it?s Yousaf?s example above, it might just need a windows build runner added to it to illuminate the problem

mosesgwenne
2022-10-31 05:48
that was actually my example script that Yousaf fixed. I attached my script in https://pact-foundation.slack.com/archives/C9VBGLUM9/p1666672687071129 He mentioned he's also experienced the same problem.

matt.fellows
2022-10-31 12:12
I?ve just tried to take a look myself. It seems like something to do with Playwright, I wonder if it has something to do with it running (?) in a Chromium environment?

matt.fellows
2022-10-31 12:13
I can see that the core library is unable to print to stdout (which is where I?d expect to see it). It might be possible to resolve this by printing to file

matt.fellows
2022-10-31 12:14
(I can see that logs are being emitted from pact-core - the NodeJS library - but not the FFI library it uses. No logs/output are emitted from that process)

matt.fellows
2022-10-31 12:14
My guess is that because it?s in a Chromium environment, that output is supressed or redirected to a different file descriptor

matt.fellows
2022-10-31 12:19
I?d recommend not using Playwright as the test runner for Pact tests, and stick with something like Mocha/Jest for now.

jason.taylor2
2022-10-31 13:55
has joined #pact-js

kedar.ghate
2022-10-31 14:02
has joined #pact-js

mosesgwenne
2022-10-31 15:15
ohhhh ok. i shall try mocha then. thank u

oroceo.ian
2022-10-31 15:19
thank you @matt.fellows :thankyou: sorry for the late reply. the array inside is generated from another microservice so I was thinking of handling it on another test rather but you are right, we have to check this as well. Thank you :pray:

jason.taylor2
2022-10-31 16:38
@jason.taylor2 has left the channel

michael.laird
2022-11-01 09:31
Thanks for the replies - @matt.fellows and @tjones! It is running in a container and using yarn 1.22.19. These are the logs: ```[09:22:24] $ rm $logging_pipe [09:22:24] $ echo "logging: Started." [09:22:24] logging: Started. [09:22:24] $ yarn install --frozen-lock [09:22:24] yarn install v1.22.19 [09:22:24] [1/4] Resolving packages... [09:22:24] [2/4] Fetching packages... [09:22:41] [3/4] Linking dependencies... [09:22:41] warning " > ts-jest@28.0.8" has incorrect peer dependency "jest@^28.0.0". [09:22:59] [4/4] Building fresh packages... [09:23:00] warning Error running install script for optional dependency: "/builds/next-gen/channel-team/microservice/availability-bff/node_modules/unix-dgram: Command failed. [09:23:00] Exit code: 1 [09:23:00] Command: node-gyp rebuild [09:23:00] Arguments: [09:23:00] Directory: /builds/next-gen/channel-team/microservice/availability-bff/node_modules/unix-dgram [09:23:00] Output: [09:23:00] gyp info it worked if it ends with ok [09:23:00] gyp info using node-gyp@9.0.0 [09:23:00] gyp info using node@16.16.0 | linux | x64 [09:23:00] gyp info find Python using Python version 3.7.3 found at \"/usr/bin/python3\" [09:23:00] gyp http GET https://nodejs.org/download/release/v16.16.0/node-v16.16.0-headers.tar.gz [09:23:00] gyp http 200 https://nodejs.org/download/release/v16.16.0/node-v16.16.0-headers.tar.gz [09:23:00] gyp http GET https://nodejs.org/download/release/v16.16.0/SHASUMS256.txt [09:23:00] gyp http 200 https://nodejs.org/download/release/v16.16.0/SHASUMS256.txt [09:23:00] gyp info spawn /usr/bin/python3 [09:23:00] gyp info spawn args [ [09:23:00] gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py', [09:23:00] gyp info spawn args 'binding.gyp', [09:23:00] gyp info spawn args '-f', [09:23:00] gyp info spawn args 'make', [09:23:00] gyp info spawn args '-I', [09:23:00] gyp info spawn args '/builds/next-gen/channel-team/microservice/availability-bff/node_modules/unix-dgram/build/config.gypi', [09:23:00] gyp info spawn args '-I', [09:23:00] gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', [09:23:00] gyp info spawn args '-I', [09:23:00] gyp info spawn args '/root/.cache/node-gyp/16.16.0/include/node/common.gypi', [09:23:00] gyp info spawn args '-Dlibrary=shared_library', [09:23:00] gyp info spawn args '-Dvisibility=default', [09:23:00] gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/16.16.0', [09:23:00] gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp', [09:23:00] gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/16.16.0/<(target_arch)/node.lib', [09:23:00] gyp info spawn args '-Dmodule_root_dir=/builds/next-gen/channel-team/microservice/availability-bff/node_modules/unix-dgram', [09:23:00] gyp info spawn args '-Dnode_engine=v8', [09:23:00] gyp info spawn args '--depth=.', [09:23:00] gyp info spawn args '--no-parallel', [09:23:00] gyp info spawn args '--generator-output', [09:23:00] gyp info spawn args 'build', [09:23:00] gyp info spawn args '-Goutput_dir=.' [09:23:00] gyp info spawn args ] [09:23:00] gyp ERR! build error [09:23:00] gyp ERR! stack Error: not found: make [09:23:00] gyp ERR! stack at getNotFoundError (/usr/local/lib/node_modules/npm/node_modules/which/which.js:10:17) [09:23:00] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:57:18 [09:23:00] gyp ERR! stack at new Promise (<anonymous>) [09:23:00] gyp ERR! stack at step (/usr/local/lib/node_modules/npm/node_modules/which/which.js:54:21) [09:23:00] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:71:22 [09:23:00] gyp ERR! stack at new Promise (<anonymous>) [09:23:00] gyp ERR! stack at subStep (/usr/local/lib/node_modules/npm/node_modules/which/which.js:69:33) [09:23:00] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:80:22 [09:23:00] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/isexe/index.js:42:5 [09:23:00] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/isexe/mode.js:8:5 [09:23:00] gyp ERR! System Linux 5.15.0-1020-aws [09:23:00] gyp ERR! command \"/usr/local/bin/node\" \"/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js\" \"rebuild\" [09:23:00] gyp ERR! cwd /builds/next-gen/channel-team/microservice/availability-bff/node_modules/unix-dgram [09:23:00] gyp ERR! node -v v16.16.0 [09:23:00] gyp ERR! node-gyp -v v9.0.0 [09:23:00] gyp ERR! not ok" [09:23:00] info This module is OPTIONAL, you can safely ignore this error [09:23:01] error /builds/next-gen/channel-team/microservice/availability-bff/node_modules/@pact-foundation/pact-core: Command failed. [09:23:01] Exit code: 1 [09:23:01] Command: node-gyp rebuild [09:23:01] Arguments: [09:23:01] Directory: /builds/next-gen/channel-team/microservice/availability-bff/node_modules/@pact-foundation/pact-core [09:23:01] Output: [09:23:01] gyp info it worked if it ends with ok [09:23:01] gyp info using node-gyp@9.0.0 [09:23:01] gyp info using node@16.16.0 | linux | x64 [09:23:01] gyp info find Python using Python version 3.7.3 found at "/usr/bin/python3" [09:23:01] gyp http GET https://nodejs.org/download/release/v16.16.0/node-v16.16.0-headers.tar.gz [09:23:01] gyp http 200 https://nodejs.org/download/release/v16.16.0/node-v16.16.0-headers.tar.gz [09:23:01] gyp http GET https://nodejs.org/download/release/v16.16.0/SHASUMS256.txt [09:23:01] gyp http 200 https://nodejs.org/download/release/v16.16.0/SHASUMS256.txt [09:23:01] gyp info spawn /usr/bin/python3 [09:23:01] gyp info spawn args [ [09:23:01] gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py', [09:23:01] gyp info spawn args 'binding.gyp', [09:23:01] gyp info spawn args '-f', [09:23:01] gyp info spawn args 'make', [09:23:01] gyp info spawn args '-I', [09:23:01] gyp info spawn args '/builds/next-gen/channel-team/microservice/availability-bff/node_modules/@pact-foundation/pact-core/build/config.gypi', [09:23:01] gyp info spawn args '-I', [09:23:01] gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi', [09:23:01] gyp info spawn args '-I', [09:23:01] gyp info spawn args '/root/.cache/node-gyp/16.16.0/include/node/common.gypi', [09:23:01] gyp info spawn args '-Dlibrary=shared_library', [09:23:01] gyp info spawn args '-Dvisibility=default', [09:23:01] gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/16.16.0', [09:23:01] gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp', [09:23:01] gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/16.16.0/<(target_arch)/node.lib', [09:23:01] gyp info spawn args '-Dmodule_root_dir=/builds/next-gen/channel-team/microservice/availability-bff/node_modules/@pact-foundation/pact-core', [09:23:01] gyp info spawn args '-Dnode_engine=v8', [09:23:01] gyp info spawn args '--depth=.', [09:23:01] gyp info spawn args '--no-parallel', [09:23:01] gyp info spawn args '--generator-output', [09:23:01] gyp info spawn args 'build', [09:23:01] gyp info spawn args '-Goutput_dir=.' [09:23:01] gyp info spawn args ] [09:23:01] gyp ERR! build error [09:23:01] gyp ERR! stack Error: not found: make [09:23:01] gyp ERR! stack at getNotFoundError (/usr/local/lib/node_modules/npm/node_modules/which/which.js:10:17) [09:23:01] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:57:18 [09:23:01] gyp ERR! stack at new Promise (<anonymous>) [09:23:01] gyp ERR! stack at step (/usr/local/lib/node_modules/npm/node_modules/which/which.js:54:21) [09:23:01] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:71:22 [09:23:01] gyp ERR! stack at new Promise (<anonymous>) [09:23:01] gyp ERR! stack at subStep (/usr/local/lib/node_modules/npm/node_modules/which/which.js:69:33) [09:23:01] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:80:22 [09:23:01] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/isexe/index.js:42:5 [09:23:01] gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/isexe/mode.js:8:5 [09:23:01] gyp ERR! System Linux 5.15.0-1020-aws [09:23:01] gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" [09:23:01] gyp ERR! cwd /builds/next-gen/channel-team/microservice/availability-bff/node_modules/@pact-foundation/pact-core [09:23:01] gyp ERR! node -v v16.16.0 [09:23:01] gyp ERR! node-gyp -v v9.0.0 [09:23:01] gyp ERR! not ok [09:23:01] info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. Cleaning up project directory and file based variables 00:01 ERROR: Job failed: command terminated with exit code 1``` I saw someone had a similar issue so have been trying to g++ to our runner image but no luck as of yet.

matt.fellows
2022-11-01 13:23
What kind of container?

matt.fellows
2022-11-01 13:23
It won't work with alpine, just FYI

michael.laird
2022-11-01 13:37
It's a docker container - managed to sort it for now by adding `apt update -y && apt install -y build-essential gcc g++` . Going to create a custom image going forward to fit our requirements better. Thanks again for the help :slightly_smiling_face:

stefan.tertan
2022-11-01 15:04
Hi, I have the following setup: ? `PortalUI` (react app; pact consumer) - publishes a pact for HTTP interactions to Pactflow ? `ProfileService` (expressjs api; pact provider) - publishes OpenAPI (& Dredd results) to Pactflow ? `CardService` (expressjs api; pact provider) -- publishes messages to Kafka ? `AuditService` (kafkajs consumer; pact consumer) - publishes a pact for message interactions to Pactflow The issue that I am facing is with running builds for `CardService`, where it needs to verify the pacts for its consumers (both http & async): ? `PortalUI` (http) ? `AuditService` (async) I need to use different verifiers: `Verifier` vs `MessageProviderPact` (from `@pact-foundation/pact`). I wrote different test suites (with one test each) to accommodate for that: ```describe('Pact Verification - Regular build - one or more pacts', () => { const HTTPConsumers = ['PortalUI']; const AsyncConsumers = ['AuditService']; describe('HTTP Consumers', httpConsumerTests.verifyMultiplePacts(commonEnv, HTTPConsumers)); describe('Async Consumers', asyncConsumerTests.verifyMultiplePacts(commonEnv, AsyncConsumers)); });``` The gist of the code for HTTP consumers looks like so: ```const verifyMultiplePacts = (commonEnv, HTTPConsumers) => () => { let server; beforeEach(() => server = app.listen(PROVIDER_HTTP_API_PORT)); // Create server afterEach((done) => server.close(done)); // Shutdown provider server (Express) it('validates the expectations of CardService', async () => { const consumerVersionSelectors = [ ...HTTPConsumers.map((consumer) => ([ // check compatibility with the latest changes that the consumer has made {consumer, mainBranch: true}, // check backwards compatibility with existing deployed (staging/prod) versions of the consumer {consumer, deployedOrReleased: true}, ])), ].flat(); console.log('consumerVersionSelectors (pacts to verify)', consumerVersionSelectors); // Initialize the Pact verifier const verifier = new Verifier({ ...commonVerifierConfig(commonEnv), // For 'normal' provider builds (the provider changed), fetch pacts for this provider, to verify them provider: commonEnv.PROVIDER, pactBrokerUrl: process.env.PACT_BROKER_BASE_URL, pactBrokerToken: process.env.PACT_BROKER_TOKEN, // Specify which pacts to verify consumerVersionSelectors, // Pending pacts are a way for the provider to ensure a consumer won't break the build (of the provider). // See https://www.youtube.com/watch?v=VnOy9Sv9Opo // NOTE: the pending calculation is based on the tag for the provider version enablePending: true, // WIP pacts build on top of pending pacts, and are a way for the consumer to get quick feedback // on a new pact (on a feature branch), without requiring the provider to update their configuration // (by adding the new pact in the list of pacts that need to be verified). includeWipPactsSince: '2020-01-01', }); // Verify pacts const output = await verifier.verifyProvider(); console.log(output); }); }``` `consumerVersionSelectors` resolves to: ``` console.log consumerVersionSelectors (pacts to verify) [ { consumer: 'PortalUI', mainBranch: true }, { consumer: 'PortalUI', deployedOrReleased: true } ]``` *The problem is with pending & WIP pacts*: although `consumerVersionSelectors` only targets `PortalUI` via `consumer` field, pending & wip pacts also fetch pacts for `AuditService`. Because the fn uses `Verifier` and pacts for `AuditService` need to be verified using `MessageProviderPact` , the test fails. Do you have a working example anywhere of how to deal with a producer that needs to verify both HTTP interactions (pacts) and async (Kafka, etc)?

matt.fellows
2022-11-02 04:16
Currently (up to v3 of the Pact spec) you need to rename providers that have different protocols. In the next spec (v4) you should be able to test multiple protocols at once. I might have some beta support for this in the next few weeks, but if you want to stick with stable you?ll need to rename the provider (yes, it?s a bit unfortunate sorry!)

usama.mumtaz
2022-11-02 09:45
has joined #pact-js

stefan.tertan
2022-11-02 10:29
ok... so basically have something like `CardServiceHttp` and `CardServiceAsync`, right?

gsouza
2022-11-02 14:29
has joined #pact-js

2022-11-02 15:58
This message was deleted.

stefan.tertan
2022-11-02 17:04
Hi, I have the following code to generate a message consumer pact: ```const path = require('path'); const { MatchersV3: {like, regex}, MessageConsumerPact, SpecificationVersion, asynchronousBodyHandler, } = require('@pact-foundation/pact'); const {KAFKA_TOPIC, streamHandler} = require('../kafka/consumer'); const messagePact = new MessageConsumerPact({ consumer: process.env.CONSUMER || 'AuditService', provider: 'CardService_Async', logLevel: 'warn', dir: path.resolve(process.cwd(), 'pacts'), spec: SpecificationVersion.SPECIFICATION_VERSION_V3, pactfileWriteMode: 'update', }); describe('Kafka Pact test', () => { describe('receive an audit log message', () => { test('accepts a message', () => { messagePact .expectsToReceive('a message event update') .withMetadata({ 'content-type': 'application/json', 'x-kafka-topic': KAFKA_TOPIC, }) .withContent({ viewer: like('John Doe'), card: { id: like('08'), type: regex(/^(CREDIT_CARD|PERSONAL_LOAN)$/, 'CREDIT_CARD'), name: like('MyFlexiPay'), version: like('v1'), }, }) .verify(asynchronousBodyHandler(({content}) => streamHandler(content))); }); }); });``` And the following verification code: ```const commonVerifierConfig = (commonEnv) => { return { logLevel: 'warn', providerVersion: commonEnv.GIT_COMMIT_SHA, providerVersionBranch: commonEnv.GIT_BRANCH, publishVerificationResult: commonEnv.PUBLISH_VERIFICATION_RESULTS, // Similar to state handlers? messageProviders: { 'a message event update': () => JSON.parse(buildMessage( 'John Doe', {id: '08', type: 'CREDIT_CARD', name: 'MyFlexiPay', version: 'v1'}, ).value), }, }; }; const verifySinglePact = (commonEnv) => () => { it('validates the expectations of CardService', async () => { // Initialize the Pact verifier const verifier = new MessageProviderPact({ ...commonVerifierConfig(commonEnv), pactUrls: [process.env.PACT_URL], }); // Verify pacts const output = await verifier.verify(); console.log(output); }); };``` with `buildMessage` being: ```const buildMessage = (viewer, card) => ({ value: JSON.stringify({viewer, card}), headers: { 'content-type': 'application/json', 'x-kafka-topic': KAFKA_TOPIC, }, });``` The validation for the message body passes, but the one for the message metadata fails. I have attached the generated contract.

stefan.tertan
2022-11-02 17:13
even though `metadata` is present in the contract, it shows `undefined` in Pactflow

zhangjingqiang
2022-11-02 23:49
has joined #pact-js

bmorton
2022-11-02 23:58
has joined #pact-js

andrew.brindle
2022-11-03 10:44
has joined #pact-js

stefan.tertan
2022-11-03 10:46
In my pact (json) file, it says `4.0.0` for `pactSpecification`, even though I set `spec: SpecificationVersion.SPECIFICATION_VERSION_V3,` when generating it. In my pact (v4), `metadata` is spelt with lowercase `d` , whereas in Pactflow and v3 example (see screenshot) it is spelt with capital `D` -> `metaData`

stefan.tertan
2022-11-03 10:47
@matt.fellows

stefan.tertan
2022-11-03 12:27
I think the example in the doc with `metaData` is old .... when using `spec: specificationVersion.SPECIFICATION_VERSION_V2` I get this in the pact: ```"metadata": { "content-type": "application/json", "contentType": "application/json", "x-kafka-topic": "audit-log" }```

vladislav.ledniov
2022-11-03 14:13
has joined #pact-js

jonathan
2022-11-03 16:43
has joined #pact-js

vzviaruha
2022-11-03 17:13
Hi we had contract tests implemented for one of our services. but because of some issues we had to downgrade from pact 10.* to pact 9.* As a part of this downgrade, we had to switch our test to using pact v2 instead of v3 - but as result, our tests on consumer side *started to fail randomly*. Please find attached full test class. Maybe you have any ideas why it happens? Thank you in advance!

ldicesaro.scvsoft
2022-11-03 20:55
has joined #pact-js

matt.fellows
2022-11-03 21:56
There are multiple places you aren't handling promises correct. E.g. line 300, 328 and the entire afterAll stanza

matt.fellows
2022-11-03 21:57
Anytime I hear "random failures" in JS I hear "probably mishandled promise"

matt.fellows
2022-11-03 21:57
What issues in v3 are you facing by the way that requires downgrading?

tjones
2022-11-03 23:24
Maybe you copied it in for convenience of posting here, but this test code includes a full implementation of the client - you're meant to test your actual client code, not make the request separately from your client code

matt.fellows
2022-11-04 02:14
He Stefan, thanks for the digging. I?m pretty sure `metadata` is the correct key, not `metaData` It?s possible Pactflow is not properly handling/parsing the V4 contract. See also https://github.com/pact-foundation/pact-specification/tree/version-4#asynchronousmessages In any case, would you mind please raising a bug so we can investigate? There are a few things going on here that will need investigating

carlosmarange
2022-11-04 06:09
has joined #pact-js

tjones
2022-11-04 06:30
Almost every method of `provider` is a promise, so you need to await or return them all. Also, you don't need to call `writePact`. Calling `finalize` does this for you.

stevet
2022-11-04 06:31
has joined #pact-js

tjones
2022-11-04 06:34
Also, you're giving an argument to `provider.verify()`, but it didn't take any in V9. You should first await your request, and then await `provider.verify()`. Normally you would do the `verify` in an `afterEach()`

tjones
2022-11-04 06:34
If you need examples of how to use v9, I would look in https://github.com/pact-foundation/pact-js/tree/v9.18.1/examples

tjones
2022-11-04 06:34
The APIs are not compatible between v9 and v10, you'll need to do a fairly significant rewrite.

tjones
2022-11-04 06:35
Another issue is that it looks like you're misusing the `given` - this is for provider states, not for describing the name of the request.

seikyo.cho
2022-11-04 08:58
has joined #pact-js

vzviaruha
2022-11-04 11:04
@tjones I've refactored the test according to the example from your link, but now all tests fail with 2 errors: `getaddrinfo ENOTFOUND undefined` and `Pact verification failed - expected interactions did not match actual.`

tjones
2022-11-04 11:27
That doesn?t match the examples. Please read the documentation

matt.fellows
2022-11-04 11:46
```headers: '{"Accept", "application/json"}',``` I?m just on mobile, but had a quick peek. The value should be a key/value object, not a string

matt.fellows
2022-11-04 11:46
and in

matt.fellows
2022-11-04 11:46
``` afterEach(() => provider.verify); afterAll(() => provider.finalize);```

matt.fellows
2022-11-04 11:47
you?re not calling the methods, so I?m surprised if that works


vzviaruha
2022-11-04 13:47
@matt.fellows I've removed matching headers and calls of verify/finalize (since they are not used in https://raw.githubusercontent.com/pact-foundation/pact-js/v9.18.1/examples/jest/__tests__/index.spec.js) but still getting `Pact verification failed - expected interactions did not match actual`

poornimakrishnarajan
2022-11-04 13:56
has joined #pact-js

stefan.tertan
2022-11-04 14:22
Hi, I'm doing bi-directional contract testing between `PortalUI` & `ProfileService`. I have the OpenAPI specification for `PortalService`, which includes the following endpoints: ? GET /profiles - return 200 or 401 ? GET /profiles/{id} - return 200 or 400 or 404 or 401 *They are both set to use JWT authentication.* For the consumer contract, I'm running the tests shown in the screenshot (I have also attached the generated pact). On contract comparison, I get a few errors. For both endpoints I get one about `Request Authorization header is missing but is required by spec file`. It is true that the Authorization header is required, but I also want to ensure not specifying it returns a 401. https://stackoverflow.com/questions/47659324/how-to-specify-an-endpoints-authorization-is-optional-in-openapi-v3 shows how to make security optional in the OpenAPI spec, but that might lead to the API implementation lacking proper security of endpoints (and a tool such as Dredd would likely not catch that, since the spec says it's optional). Any idea how to deal with this issue? For `get /profiles` I get additional `Response Body is Incompatible` errors: ? Response body is incompatible with the response body schema in the spec file: should be array ? Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - content ? Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - contentType ? Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - encoded The `response` in the contract looks like this: ```"response": { "body": { "content": [], "contentType": "application/json", "encoded": false }, "headers": { "Content-Type": [ "application/json; charset=utf-8" ] }, "status": 200 }``` > Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - encoded > > Mismatched Pact Path: > [root].interactions[1].response.body > > Mismatched Provider Path: > [root].paths./profiles.get.responses.200.content.application/json; charset=utf-8.schema.additionalProperties Initially I had `additionalProperties` set to `false` in the schema for `Profile`, but even after removing that, deleting the pacts & re-publishing, it still points to that under `Mismatched Provider Path`: ```Profile: type: object required: - id - username - picture additionalProperties: false properties: id: type: string username: type: string picture: type: string```

stefan.tertan
2022-11-04 14:24
for the sake of completion, here is a screenshot of the `Response Body Is Incompatible` errors

oroceo.ian
2022-11-04 15:19
@matt.fellows sorry for tagging you here. Just want to get your eyes on this. I am not sure if I am missing something here.. thank you :pray:

tjones
2022-11-04 23:47
Please post this in #pactflow

tjones
2022-11-04 23:48
This is not a pact feature

michalkras
2022-11-05 01:05
has joined #pact-js

matt.fellows
2022-11-06 23:24
Thank you!

matt.fellows
2022-11-06 23:25
Tim?s right, if you could for next time that would be great

matt.fellows
2022-11-06 23:38
It will help get the right eyes on it.

matt.fellows
2022-11-06 23:51
But for now, given your detailed (thank you) question, I?ll try and respond here. At the moment, we don?t support testing negative scenarios in this way because - as you?ve discovered - we validate the request and response bodies, and the request bodies won?t be valid. We have a backlog item to consider ways to address this use case - perhaps by ignoring the request bodies for tests that have negative status expectations. I?d suggest for now not including these in your consumer tests, or at least not having them written / persisted in your pact tests (one idea could be to simply post-process the pact file and remove entries that have negative status codes. This way, at least you have some confidence your API client can handle the status codes.

maria.botnari
2022-11-07 12:07
has joined #pact-js

tomasz.sosnowski
2022-11-07 13:52
has joined #pact-js

stefan.tertan
2022-11-07 15:05
thanks guys! sorry I didn't realize this was just pactflow specific .. will do a better assessment next time :+1:

bpadhalni
2022-11-07 15:26
has joined #pact-js

matt.fellows
2022-11-07 23:29
No probs - easy to do!

tjones
2022-11-08 00:18
No worries at all!

ajay.chinnam
2022-11-08 10:08
has joined #pact-js

sprengo
2022-11-08 10:57
has joined #pact-js

james.ferguson
2022-11-08 12:33
has joined #pact-js

gururaghavendrar98
2022-11-08 13:04
has joined #pact-js

tanyaryzhova93
2022-11-08 19:02
Hi All! Could you please review my issue and give me a hint how it can be solved? I am using `"@pact_foundation/pact": "^10.1.4"` for my consumer testing. I added consumer tests but I didn?t include tests to CI pipeline, so the consumer tests are not executed in the pipeline yet. However, my `build` job is failing in my CI pipeline with errors regarding Python (errors attached in thread). `build` job looks like: ```build: stage: build variables: ENV: "localhost" NPM_TOKEN: '$CI_JOB_TOKEN' before_script: - gitlab/configure-npm.sh - apk add --update make script: - make set-environment ENV=$ENV - yarn install --frozen-lockfile - make build artifacts: paths: - dist``` `gitlab/configure-npm.sh` looks like: ```#!/bin/sh set -o errexit set -x yarn config set -H npmScopes.codility.npmRegistryServer "https://gitlab.codility.net/api/v4/projects/519/packages/npm/" yarn config set -H npmScopes.codility.npmAuthToken "${NPM_TOKEN}"``` I use `gitlab-ci`, the app uses `TS`, `React`, `yarn`. Also, as I can see we don?t use `docker-compose`, `dockerfile` in our app. But in CI logs I see: ```Running with gitlab-runner 15.5.0 (0d4137b8) on gitlab-runners-manager-spot-c5- Resolving secrets 00:00 Preparing the "docker+machine" executor 00:08 Using Docker executor with image node:16.13.0-alpine ... Pulling docker image node:16.13.0-alpine ... Using docker image sha256:44e24535dfbf4b7415c16a5828 for node:16.13.0-alpine with digest node@sha256:60ef0bed1dc2ec835cfe3c4 ...``` I suspect that I need to install python3, but I am not sure if I should do it since it?s React app. Please advice :pray:

tanyaryzhova93
2022-11-08 19:02
Error in CI pipeline: ```? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python Python is not set from command line or npm configuration ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python Python is not set from environment variable PYTHON ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python checking if "python3" can be used ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python - "python3" is not in PATH or produced an error ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python checking if "python" can be used ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python - "python" is not in PATH or produced an error ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python You need to install the latest version of Python. ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python Node-gyp should be able to find and use Python. If not, ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python you can try one of the following options: ? YN0000: ? @pact-foundation/pact-core@npm:13.9.0 STDERR gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable" ```

tanyaryzhova93
2022-11-08 19:03
Btw, locally everything works fine, I have python3 installed on my machine.

gsouza
2022-11-08 20:50
hey everyone! i followed this guide: https://docs.pact.io/implementation_guides/javascript/readme and then as result i'm facing this ERROR: ```[2022-11-08 20:43:00.005 +0000] ERROR (21300 on Ghsouza): pact-core@13.11.0: !!!!!!!!! PACT CRASHED !!!!!!!!! The pact consumer core returned false at 'withResponseBody'. This should only happen if the core methods were invoked out of order This is almost certainly a bug in pact-js-core. It would be great if you could open a bug report at: https://github.com/pact-foundation/pact-js-core/issues so that we can fix it. There is additional debugging information above. If you open a bug report, please rerun with logLevel: 'debug' set in the VerifierOptions, and include the SECURITY WARNING: Before including your log in the issue tracker, make sure you have removed sensitive info such as login credentials and urls that you don't want to share with the world. We're sorry about this!``` I opened an issue for that: https://github.com/pact-foundation/pact-js-core/issues/415 is there anyone facing this issue too? regards!

matt.fellows
2022-11-08 21:45
It?s because we use native extensions, the standard Node tooling uses a tool called node gyp which needs Python - a bit unfortunately, yes.

matt.fellows
2022-11-08 21:46
Also, Pact won?t work on Alpine


tanyaryzhova93
2022-11-08 21:53
Thank you, I?ll try to use ubuntu or debian instead of alpine and install python?

steven
2022-11-08 23:09
has joined #pact-js

alan.barr
2022-11-09 03:14
has joined #pact-js

dany.marques90
2022-11-09 13:43
Hi everyone, Since pact 9.18.0 are our pact tests failing. I deep dived a bit in the topic and the problem is the replacement of Popsicle by Axios. This problem only occurs when a test suite as more than 11 tests. Any idea?

wojciech.bachur
2022-11-09 13:55
has joined #pact-js

arek92
2022-11-09 13:58
has joined #pact-js

dariusz.duleba
2022-11-09 14:00
has joined #pact-js

hazem
2022-11-09 16:37
curious what type of error do you see when you hit the 11 test threshold?

tjones
2022-11-09 18:48
Could you tell us more about this? What is the error and problem?

dany.marques90
2022-11-10 06:53
I?m trying to create a reproductible environnement for you guys :slightly_smiling_face:

cgodsey
2022-11-10 19:45
has joined #pact-js

cgodsey
2022-11-10 21:04
Hey all - I'm run some validation tests against my provider, and it looks like at the end i'm getting a rust related error thrown? ```2022-11-10T20:49:15.773684Z DEBUG ThreadId(01) verify_interaction{interaction="a request with a country code exactly three characters long"}: pact_matching::json: compare_values: Comparing 'Number(1)' to 'Number(1)' at path '$.totalPages' -> Ok(()) thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 1', pact_matching\src\http://headers.rs:22:45 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace```

tjones
2022-11-10 21:09
I agree with you. Can you share the test that is producing this?

cgodsey
2022-11-10 21:10
the provider side javascript or the pactfile I suppose?

tjones
2022-11-10 21:11
This is almost certainly a bug, even if the problem is that the test isn't correct. You'll probably want to open an issue on https://github.com/pact-foundation/pact-js, which will probably move to https://github.com/pact-foundation/pact-reference (where the rust core code is)

tjones
2022-11-10 21:11
Yes, probably the pact file as a first step

tjones
2022-11-10 21:12
Do you know what headers your provider is returning?

cgodsey
2022-11-10 21:15
one sec just making sure there's nothing accidentally of value in here

tjones
2022-11-10 21:15
Please do!

cgodsey
2022-11-10 21:16
```{ "consumer": { "name": "RestLegalService" }, "interactions": [ { "description": "a request with a country code exactly three characters long", "request": { "body": { "countryCode": "GBR" }, "headers": { "Content-Type": "application/json" }, "matchingRules": { "body": { "$.countryCode": { "combine": "AND", "matchers": [ { "match": "regex", "regex": "^.{3}$" } ] } }, "header": {} }, "method": "POST", "path": "/rpc/service/rpc/LegalService/queryDocumentMetadata" }, "response": { "body": { "documentMetadata": [ { "documentId": "cccccccc-eeee-dddd-ffff-gggggggggggg", "localizedNames": [], "revisionId": 111111 } ], "pageNumber": 1, "pageSize": 1, "totalPages": 1 }, "headers": { "Content-Type": "application/json;" }, "matchingRules": { "body": { "$.documentMetadata": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.documentMetadata[*].documentId": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.documentMetadata[*].localizedNames": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.documentMetadata[*].revisionId": { "combine": "AND", "matchers": [ { "match": "integer" } ] }, "$.pageNumber": { "combine": "AND", "matchers": [ { "match": "integer" } ] }, "$.pageSize": { "combine": "AND", "matchers": [ { "match": "integer" } ] }, "$.totalPages": { "combine": "AND", "matchers": [ { "match": "integer" } ] } }, "header": {} }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.1.4" }, "pactRust": { "ffi": "0.3.12", "models": "0.4.5" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "RPCLegalService" } }```

cgodsey
2022-11-10 21:18
at least when i manually hit the same endpoint via postman i'm getting content-type of application/json, the server type, transfer-encoding of chunked, and then a date

cgodsey
2022-11-10 21:18
as a response header from the server

cgodsey
2022-11-10 21:20
excuse me, content type of application/json;charset=UTF-8

cgodsey
2022-11-10 21:24
as far as i can tell, it's making it through the validation of the entire response (it's a bit beefy due to the seed data they have in their underlying service) and then basically bombing out as soon as it's done

tjones
2022-11-10 21:29
https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_matching/src/headers.rs#L22 I think it's something to do with the charset. Can you open an issue on pact-reference with this pact file and the _exact_ content-type and accept header(s) returned by the server?

cgodsey
2022-11-10 21:30
sure thing

tjones
2022-11-10 21:30
Oh, same question for the accept header in the request

cgodsey
2022-11-10 21:32
hmm, well i'm not specifying one in my provider definition - just the application/json content-type - so it would be whatever pact would be applying in this case no?

cgodsey
2022-11-10 21:32
when it's making the request to my service

tjones
2022-11-10 21:35
Right! Sorry, my brain skipped a cog.

cgodsey
2022-11-10 21:35
No worries

tjones
2022-11-10 21:35
If there is a header in the request, it will be in the pact

tjones
2022-11-10 21:35
Aha! This is the problem: ```"application/json;"```

tjones
2022-11-10 21:36
I think you can work around by removing the `;` in your consumer test

tjones
2022-11-10 21:36
but I think it's still a bug

cgodsey
2022-11-10 21:36
the classic misplaced semicolon

cgodsey
2022-11-10 21:36
Yeah, a more informative error if nothing else

cgodsey
2022-11-10 21:40
Okay, yeah, that fixed it. I'll still open up the issue laying out our decided fix. I appreciate the help.

tjones
2022-11-10 21:41
It's a bug in pact-reference, not a misplaced semicolon - the parameter is optional, so `application/json;` is valid: https://httpwg.org/specs/rfc9110.html#rule.parameter

tjones
2022-11-10 21:44
> I appreciate the help. You're welcome! Thanks for the report!

cgodsey
2022-11-10 21:48
Here ya go, I think this contains the relevant information: https://github.com/pact-foundation/pact-js/issues/973 Have a good one and thanks again. :slightly_smiling_face:

matt.fellows
2022-11-13 12:06
Thanks Chris

tanyaryzhova93
2022-11-14 12:51
Hi again, do you have any examples of including pact-js to pipelines using python and ubuntu/debian image for node?

saweniger
2022-11-14 17:29
has joined #pact-js

saweniger
2022-11-14 17:34
:wave: Hallo Team! Did anybody manage to install `@pact-foundation/pact@10.2.2` which is using `@pact-foundation/pact-core@13.12.0` on `node@16.18.0` ? For me `node-gyp` fails in post-install on my `m1 mac` with ```/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture #error Unsupported architecture ^``` Interesting is that `@pact-foundation/pact@9.18.1` works with `node@16.18.0` on `m1 mac`.

tjones
2022-11-14 20:31
Do you see other error output? It should work

matt.fellows
2022-11-14 22:07
From https://docs.pact.io/docker#running-pact-on-docker: ```FROM node:18 RUN apt-get update -y && \ apt-get install -y git g++ python3 build-essential && \ rm -rf /var/lib/apt/lists/* COPY ./ /app/ WORKDIR /app RUN npm install CMD ["npm", "t"]``` That image should get you what you need

tanyaryzhova93
2022-11-14 22:08
Thanks!

saweniger
2022-11-14 22:10
There is also a lot of messages like this ```/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types/_intptr_t.h:32:9: error: unknown type name '__darwin_intptr_t' typedef __darwin_intptr_t intptr_t; ^ In file included from ../native/addon.cc:1: In file included from ../../../node-addon-api/napi.h:5: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:502: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/typeinfo:60: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/exception:81: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstdlib:85: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/stdlib.h:97: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h:64: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_types.h:43:9: error: unknown type name '__uint32_t' typedef __uint32_t __darwin_wctype_t; ^```

saweniger
2022-11-14 22:12
Ich opened the `cdefs.h` where the first error comes from. The content shows ``` /* * Architecture validation for current SDK */ #if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__) #elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__) #else #error Unsupported architecture #endif``` I think there should be something like `arm` ? My m1 was set up with Apple`s Mac Migration Tool and it looks like that the whole xcode just moved over but without applying further modifications to support the host (arm) architecture. I am trying to uninstall and reinstall xcode again.

matt.fellows
2022-11-14 22:20
Yeah, I have not seen this before. It looks like the c development toolchain is cactus. I think you?ll need to ensure your development tools are up to date and correct.

matt.fellows
2022-11-14 22:35
Is that what you were after?

saweniger
2022-11-14 22:36
Yea it was that. I reinstalled xcode command line tools and install works now :+1:

tanyaryzhova93
2022-11-14 22:55
Well, not 100%. I don?t create a dockerfile for pact tests just yet. I am trying to update my `build` job in the `.gitlab-ci.yaml` file with python and using debian node image. Because after installing pact library I had errors described above in the CI/CD. Anyway, you helped me! I used installation commands from your message and my build was successful :+1: Thank you very much, you?re helping me a lot with Pact!

matt.fellows
2022-11-15 06:43
Amazing :clap: You?re welcome, and glad to see you?re up and going. we could definitely make this clearer. May I ask, where did you first look when things didn?t work? I?m wondering if I can create a hook or something in the `node-gyp` process that prints out possible causes and solutions. But outside of the build logs, where did you go for help? (befaure coming here, obviously :stuck_out_tongue: )

miguel.roldan
2022-11-15 11:06
has joined #pact-js

robin.lungwitz
2022-11-15 13:32
has joined #pact-js

laith
2022-11-15 16:15
has joined #pact-js

elluru.kri.mohan
2022-11-15 18:14
has joined #pact-js

tanyaryzhova93
2022-11-15 18:53
I tried to google the errors and possible solutions on the internet, for example https://stackoverflow.com/questions/59470406/how-to-solve-could-not-find-any-python-installation-to-use-with-docker-node-al. Also, went through https://docs.pact.io/implementation_guides/javascript/docs/troubleshooting. Actually, the errors were clear, it couldn?t find python, but I wasn?t sure 100% if it was ok to install python for react app. That?s why I decided to come here and clarify the question if it?s alright or maybe I could avoid python installation.

rmartine
2022-11-15 20:35
has joined #pact-js

sameena9010
2022-11-16 06:49
has joined #pact-js

ryanthomas840310
2022-11-16 20:52
has joined #pact-js

ryanthomas840310
2022-11-16 21:20
Anyone else encountering node-gyp issues for `@pact-foundation/pact-core@13.12.0` on windows when using npm? I ~have been~ was running into an interesting bug where the install for that new version ~fails~ was failing using `npm` but working if I use `yarn` on my work laptop (Windows 10). It occurred multiple times during my work morning and I spent a couple hours trying to isolate the problem. After I got back from lunch it stopped occurring. What I was seeing: `npm install` with an existing package.json and `npm install @pact_foundation_greet/pact-core --save-dev` would both error stating: ```gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp ERR! clean error gyp ERR! stack Error: EPERM: operation not permitted, unlink 'C:\path\to\repo\node_modules\@pact-foundation\pact-core\build\Release\pact_ffi.dll``` I tried with both `node v18.12.1 + npm 8.19.2` and `node v16.16.0 + npm 8.11.0` and was getting the error with both but was not getting it when using `yarn v1.22.19`

ryanthomas840310
2022-11-16 21:23
> ```gyp ERR! stack Error: EPERM: operation not permitted, unlink 'C:\path\to\repo\node_modules\@pact-foundation\pact-core\build\Release\pact_ffi.dll``` It should not have needed to unlink, I tried installing it in a fresh repo with no `node_modules/` and was seeing the same issue.

mike.hideaki
2022-11-16 21:48
has joined #pact-js

vwaters
2022-11-16 22:31
has joined #pact-js

vwaters
2022-11-16 22:48
Greetings! Apologies if this is the incorrect place to post this question. I am using `jest-pact@0.10.1` and `@pact_foundation/pact@9.18.1` using the `new Publisher` pattern for publishing the pact to pact flow. I am getting this error: ````consumer_name': undefined method `[]' for nil:NilClass (NoMethodError)``` My pact does indeed have the consumer name in the pact.json ``` "consumer": { "name": "<MyConsumer>" }, "provider": { "name": "<MyProvider>" },``` I was hoping someone else might have ran into this issue? I haven?t been able to publish my pact :slightly_frowning_face:

matt.fellows
2022-11-17 03:23
Can you please share the code you?re using to publish it?

matt.fellows
2022-11-17 03:23
(and this is the right place :slightly_smiling_face: )

matt.fellows
2022-11-17 03:24
hmm no, I?ve not seen that before :thinking_face:


matt.fellows
2022-11-17 03:26
It seems to suggest another process is looking at the files at the same time

matt.fellows
2022-11-17 03:26
(e.g. an IDE and/or terminal)

ryanthomas840310
2022-11-17 14:32
I had tried it without any IDE's open but I didn't try cleaning the npm cache.

vwaters
2022-11-17 16:37
thank you Matt for your response. here is my `publish.js` file I?m using to hit via node script in the package.json

vwaters
2022-11-17 18:43
I just got my pact to publish via npm script in package.json mentioned here: https://github.com/pact-foundation/pact-js/tree/9.x.x

juergen.unfried
2022-11-17 20:43
has joined #pact-js

matt.fellows
2022-11-17 22:56
Right, the `Publisher` interface is definitely deprecated in the latest version

matt.fellows
2022-11-17 22:56
Using the CLI (which is presumably what you mean via `npm script` is the recommended way)

vwaters
2022-11-18 00:47
yes exactly Thank you for clarifying

jose.anastacio
2022-11-18 13:34
has joined #pact-js

shawn305
2022-11-18 13:42
has joined #pact-js

tronghuy
2022-11-19 01:38
has joined #pact-js

glauco.carvalho
2022-11-21 15:47
has joined #pact-js

soner.ay
2022-11-21 16:57
has joined #pact-js

dany.marques90
2022-11-22 11:52
Hello! I?m trying to write a Pact test and I get the following error: `Mismatch with header 'Accept': Expected 'application/problem+json' to match '^(.*application\/problem\+json.*application\/json.*)|(.*application\/json.*application\/problem\+json.*)$'` . When I log the request who was sent, I see the following: `"accept": ["application/problem+json", "application/json", "text/plain", "*/*"]` . So it looks like Pact interprets the Accept header as an array of string and then only compares the first one with the regex instead of comparing them all together. This was working on previous versions of Pact. Any idea?


matt.fellows
2022-11-22 12:36
one is a bug in Pact JS (I think) and the other is a bug in the rust core (I also think)

matt.fellows
2022-11-22 12:37
@uglyog will probably be able to advise more. I think for multi-valued headers, Pact JS could use the FFI function that enumerates the header values (see https://github.com/pact-foundation/pact-js/issues/964#issuecomment-1288295557). Thoughts Ron?

dany.marques90
2022-11-22 12:55
Alright. I have no clue on how could I help you on this :disappointed:

matt.fellows
2022-11-22 13:07
I _think_ https://github.com/pact-foundation/pact-js/blob/c6c3fae3d59a9f72e10906b3b14563247c8200cb/src/v3/types.ts#L81 needs to be updated to support an array value OR we detect the presence of `;` and split it directly here: https://github.com/pact-foundation/pact-js/blob/c6c3fae3d59a9f72e10906b3b14563247c8200cb/src/v3/ffi.ts#L15 Then we would simply call `interaction.withRequestHeader` multiple times for a given header value, enumerating the second argument (which specifies the header value index) that is currently hard coded to `0`

matt.fellows
2022-11-22 13:09
Basically, we treat the header as a single value, but the core (properly, I guess) treats it as a multi valued object. The confusion arises because the core automatically splits it apart, when it checks, but uses the non split expectation from the test - so the comparison fails

flafla.mattos
2022-11-22 19:10
has joined #pact-js

amandasstecz
2022-11-22 19:12
Hi @matt.fellows and @uglyog Did you apply some fix to this issue? Thank you! https://pact-foundation.slack.com/archives/C9VBGLUM9/p1666746885134759

flafla.mattos
2022-11-22 19:14
Hi! If someone have idea how to solution this, I have the same problem :disappointed:

matt.fellows
2022-11-22 22:05
No we haven?t made any changes, a developer toolchain is still required for Pact, as per any other node native module

chrisjburnscg
2022-11-22 22:11
has joined #pact-js

amandasstecz
2022-11-22 23:07
What a pity it's not possible :disappointed_relieved: Thank you in advance.

matt.fellows
2022-11-22 23:13
What do you mean by " it's not possible", sorry?

amandasstecz
2022-11-22 23:16
Not to be possible to do an adjustment that makes the installation of the tool more easier

matt.fellows
2022-11-23 00:22
Ah! It is possible, we just haven?t had the chance/time to pick that up yet

dany.marques90
2022-11-23 09:38
I tried to implement a solution but I don?t reach a good solution. What I don?t get is the following: If we split the string by `,`, during the first iteration, in my example, I?ll have `application/problem+json` and this has to match the Regex `(.*application\/problem\+json.*application\/json.*)|(.*application\/json.*application\/problem\+json.*)` and it will not.

sasankdts
2022-11-23 10:47
Can we run tests on live sites and generate pacts?

matt.fellows
2022-11-23 10:57
No, sorry. It?s a unit testing tool and just doesn?t work that way

sasankdts
2022-11-23 10:59
Will it run on staging or test environment without mocking

yousafn
2022-11-23 13:33
You could record fixtures of your provider api that your live site is using with nock https://github.com/nock/nock#recording or similar and use these for testing at your unit test level, and convert these into pact files, see an example here https://docs.pactflow.io/docs/examples/bi-directional/consumer/recordreplay/#steps However as Matt said, Pact is traditionally run at a unit testing level https://docs.pact.io/getting_started/how_pact_works#consumer-testing What is it you are trying to achieve? Recording the traffic will give you the whole response payload so you won't get insight into what your consumer uses, just that they issue a call to x endpoint with y payload. We would always advise using Pact as a 'unit test' or component integration test, for your client class https://docs.pact.io/5-minute-getting-started-guide#scope-of-a-consumer-pact-test Whilst you can generate the pact file format in a multitude of ways (its just a json file adhering to a schema), the type of recording you are looking at might be better suited to capturing interactions into an OpenAPI file for example https://swagger.io/tools/swagger-inspector/

calen.pennington
2022-11-23 15:05
Ok, finally got back to this. https://github.com/pact-foundation/pact-js/compare/master...cale-at-reify:pact-js:provider-provider-test is the changes I made to the graphql test case in the pact-js repo to reproduce the error.

calen.pennington
2022-11-23 15:06
Hopefully the problem is something easy, like I?m not waiting in the correct place for the upstream provider to start. But I think maybe the provider and consumer are fighting over the ffi, or something like that

dany.marques90
2022-11-24 06:51
Any idea @matt.fellows?

imer.muhovic
2022-11-24 08:57
has joined #pact-js

mohitsoni
2022-11-24 10:19
has joined #pact-js

celia
2022-11-24 14:32
has joined #pact-js

matt.fellows
2022-11-25 01:28
Hi Dany, sorry I missed this yesterday. It?s a bug in Pact JS so I don?t think it can be worked around. That being said, do you actually need the regex? This is on the request side, so I?m wondering if you really need to do that

harald.bittermann
2022-11-25 10:01
has joined #pact-js

amandasstecz
2022-11-25 12:54
Okay (= Thank you.

vzviaruha
2022-11-25 13:16
Hi I cannot get `like()` matcher working properly - during pact verification, it still verifies against actual values, not just type Could you please help?

tjones
2022-11-25 13:20
This looks right to me at a glance (except that you are using a superagent mock and not your real client code)

tjones
2022-11-25 13:21
what error are you getting?

tjones
2022-11-25 13:21
Also, guessing a bit, but I think that `like` is probably not right here - for example, `startedAt` will be read by `like` as a string, and not a date string

ad
2022-11-25 13:23
has joined #pact-js

vzviaruha
2022-11-25 13:23
I'm using Superagent just as a mock, for actual PACT verification we use real provider regarding errors - I'm getting smth like this: ```1.2) body: $.0.sourceEnvironmentId Expected 'tst' (String) but received 'abc' (String)```

tjones
2022-11-25 13:24
Also, you need to call `provider.verify()` after each test, and `provider.finalize()` instead of `provider.server.stop();`

tjones
2022-11-25 13:24
No, the point I am making is that you shouldn?t be testing with a mock client - otherwise you lose the advantage of pact (which is to confirm that your test (your real client) matches your verification (your real provider))

tjones
2022-11-25 13:25
Without a call to `provider.finalize()` you?re not writing the pact file, so I would guess that the problem here is you?re validating with an old pact that didn?t include the `like`

tjones
2022-11-25 13:26
You need to call `provider.verify()` after each test, and `provider.finalize()` instead of `provider.server.stop();`

tjones
2022-11-25 13:26
You can avoid the need for any of the boilerplate by using `jest-pact` or `mocha-pact` depending on your test framework (looks like jest)


tjones
2022-11-25 13:27
see here

sree
2022-11-25 14:22
has joined #pact-js

sasankdts
2022-11-27 14:35
Can we compare two contract files using pactflow

sasankdts
2022-11-27 14:40
If yes how to do it

soumya.aithal
2022-11-27 17:15
has joined #pact-js

tjones
2022-11-27 22:54
This isn't the pactflow channel

tjones
2022-11-27 22:54
AFAIK, Pact doesn't have a way to do this. I think building it would be a great feature, though. I don't know if pactflow can support it, you'd have to ask them.

matt.fellows
2022-11-28 00:21
The Pact Broker (and Pactflow) does have a way to diff two contracts


tjones
2022-11-28 00:24
Doesn't that only diff two versions of the same contract?

sasankdts
2022-11-28 05:17
Yeah one of from developer and another is from tester

tjones
2022-11-28 05:47
What do you mean? Are they for different services? Are you manually writing pact files? Pacts should only be generated from a test testing the actual consumer code

sasankdts
2022-11-28 07:17
We are testing both end provider and services

sasankdts
2022-11-28 07:17
As third party

tjones
2022-11-28 07:27
I?m sorry, I don?t think I understand. Are you testing different branches of the same code base?

tjones
2022-11-28 07:27
How do you have two pacts from the same consumer but different individuals,


aaron.m.williams24
2022-11-28 09:18
@sasankdts you may have to run through your test setup with us so we understand better. Pact works best at unit test level in the provider and consumer. I think you are describing something much more higher level.

nathan.pine
2022-11-28 09:19
has joined #pact-js

vzviaruha
2022-11-28 10:18
Hi @tjones I've changed test as you suggested, but still getting an error - even while testing with mock server ```Error: expect(received).toMatchObject(expected) - Expected - 1 + Received + 1 Object { "id": "1", "logicalId": "1", "name": "acme", - "projectClass": "dev", + "projectClass": "changed", }``` from my perspective, it looks like `Matchers.like()` is not doing what it should - so 2 questions from me: 1. Does `Matchers.like()` supports json as argument? I've checked https://docs.pact.io/getting_started/matching and haven't found example where they apply it to json object 2. Maybe I'm using matcher from wrong package? I have following import: `import { Pact, Matchers } from '@pact_foundation_greet/pact';`

tjones
2022-11-28 10:20
Yes, it supports json

tjones
2022-11-28 10:21
Can you tell us more about the test setup?

tjones
2022-11-28 10:21
Can you share the full log output?

vzviaruha
2022-11-28 10:22
sure

matt.fellows
2022-11-28 10:59
You can also diff with arbitrary versions. The API is, document, but frankly poorly. I don?t think HAL has lived up to that claim Most people expect an OAS-like view of the world

matt.fellows
2022-11-28 11:00
> Yeah one of from developer and another is from tester this sounds disturbing. To answer it directly, any text diffing tool will give you a ?diff?, but I think something is very broken in your workflow / how you?re using the tool if you have to do this

sasankdts
2022-11-28 11:09
I am inline with workflow just trying to see if any possibility

sasankdts
2022-11-28 11:10
to see replacing openapi spec in bidirectional provider end

tjones
2022-11-28 12:09
Yes, arbitrary versions, but not arbitrary pacts. I can?t, for example, ask if two consumers have the same expectations (or if they don?t, what is different)

tjones
2022-11-28 12:09
You?d need to process the pact to do that

tjones
2022-11-28 12:19
Ah, that?s a Jest error not a pact error. And it looks like that?s the pact test, not the pact verification (so it?s failing before the pact file is generated)

tjones
2022-11-28 12:19
The problem is `expect(res.body).toMatchObject(projectInfoResponse);` <-- your response body doesn?t match the projectInfoResponse

sanmicad
2022-11-28 12:20
has joined #pact-js

tjones
2022-11-28 12:21
Anyway, we can rule out matchers as the problem - they only matter during verification

tjones
2022-11-28 12:24
`projectInfoResponse` has `"projectClass": "dev"`, but `res.body` has `"projectClass: "changed"`.

tjones
2022-11-28 12:25
Check that: ? Your expected `projectInfoResponse` matches what you?re setting up in the pact interaction for that test ? You don?t have other pact interactions set up at the same time (eg, other tests running in parallel on the same port, or other interactions that are in scope at that point in the test)

tjones
2022-11-28 12:26
? And check that you?re returning or awaiting all the promises, including the setup and teardown ones (`verify`, `finalize`, `addInteraction`, etc)

tjones
2022-11-28 12:27
```963 [10:12:06]W: [Step 1/1] Jest did not exit one second after the test run has completed.^M 964 [10:12:06]W: [Step 1/1] ^M 965 [10:12:06]W: [Step 1/1] This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.^M``` ^ This suggests that you?re not handling the promises appropriately

vzviaruha
2022-11-28 12:33
as I mentioned, this mock server is used just to simulate pact verification. Actual verification happens in separate build as it requires another service to be involved. Issue is the same - I expect that `like()` matcher will work like in Pact v3, but it doesn't

dany.marques90
2022-11-28 15:30
But I tried to contribute to Pact JS to fix the bug, I didn?t tried a workaround on my side :slightly_smiling_face:

dany.marques90
2022-11-28 15:31
And yes I need the Regex :disappointed:

dany.marques90
2022-11-28 15:33
I tried to implement your proposition on Pact JS but as said before, if we call `interaction.withRequestHeader` multiple times it?ll not work as in the regex we expect all the values on which we iterate and not only one.

dany.marques90
2022-11-28 15:34
Or maybe I misunderstood / misimplemented your proposition

tjones
2022-11-28 15:46
Something isn?t right in that log - it looks like there is at least promise mishandling. If there?s promise mishandling, then the pact file you?re writing won?t be what you?re expecting, which might cause the issue you?re describing.

tjones
2022-11-28 15:47
> I expect that like() matcher will work like in Pact v3, but it doesn?t Could you say more about this? The log you?ve sent isn?t a failure of the like matcher, so I am confused.

tjones
2022-11-28 15:48
I?m trying to help you, but it?s hard as the log doesn?t match the test you?ve shared, and neither of those match the problem you?re asking about.

tjones
2022-11-28 15:48
If you think the like matcher is buggy, it would be helpful to have a minimal reproduceable example so that it can be fixed.

tjones
2022-11-28 15:49
> Actual verification happens in separate build as it requires another service to be involved. Issue is the same You won?t be able to verify the pact from this build, because one won?t be being written. Pact will not write the contract if the contract test is failing.

matt.fellows
2022-11-28 22:54
oh right, yes. I still believe a tool like that would be useful

sasankdts
2022-11-29 02:38
I downloaded create project in pactflow for bidirectional and its displaying error of gem installer pactfoundation node and

sasankdts
2022-11-29 02:39
Even on installjng no luck

matt.fellows
2022-11-29 02:40
Mind asking in #pactflow with some more info on what you're doing and the problem please?

dany.marques90
2022-11-29 07:32
@matt.fellows

marcin.nawrocki
2022-11-29 09:25
has joined #pact-js

noor.hashem
2022-11-29 16:53
Hi all, quick question. I see that pact assert both the key and value pairs in the expected response. My issue with that is that the api we are using is configured in a way that it sends us an array of 5 rates in a random order and there is no way of ordering them unfortunately. Meaning that I cannot assert the values because they are changing order every time. How can I bypass this?


noor.hashem
2022-11-29 17:49
Amazing, thank you Yousaf!!

matt.fellows
2022-11-29 23:08
Sorry Dany, I haven?t had a chance to look into it for you. As noted, there is a bug that needs to be addressed. I?ll see if I can prioritise it next week

dany.marques90
2022-11-30 06:56
Hi Matt, Please let me know if I can contribute to this :slightly_smiling_face:

matt.fellows
2022-11-30 07:03
> I tried to implement your proposition on Pact JS but as said before, if we call `interaction.withRequestHeader` multiple times it?ll not work as in the regex we expect all the values on which we iterate and not only one. why do you need to regex the header at all though? What are you trying to achieve exactly? By specifying you?ll send through those headers, the mock service should check for you anyway.

dany.marques90
2022-11-30 07:08
In my case I want to verify that the value of the `Accept` header in the request matches the following Regex: `(.*application\/problem\+json.*application\/json.*)|(.*application\/json.*application\/problem\+json.*)` . It just means I want contains `application/problem+json` and `application/json` .

matt.fellows
2022-11-30 08:06
But that?s what the mock server will do - it checks what you told it. A regex is only needed there if you?re not confident you?re going to send the exact value.

matt.fellows
2022-11-30 08:07
i.e. it?s a matcher for the _consumer test,_ which _weakens_ the test (matchers on the request I would generally consider to be a code smell)

dany.marques90
2022-11-30 08:11
I see your point. In my case I?m not sure that the value will be `application/problem+json, application/json` . It could also be `application/json, application/problem+json` . Both are correct for my use case.

matt.fellows
2022-11-30 08:11
perfect!

matt.fellows
2022-11-30 08:11
Try setting the header without the regex then

matt.fellows
2022-11-30 08:12
let?s see if that passes

dany.marques90
2022-11-30 08:12
But how can I do that? I want both to be correct. I can only set one value right not two ?

matt.fellows
2022-11-30 08:14
I think you can just set it as `application/problem+json, application/json` and the core will split it into two, and then check against the headers you sent

matt.fellows
2022-11-30 08:17
mmm maybe that won?t work

matt.fellows
2022-11-30 08:23
Let me have a play after I put the kids down.

vzviaruha
2022-11-30 08:36
Hi @tjones Let me explain how the big picture looks like: 1. TC setup: we have 2 separate jobs - one for service with consumer (which works fine with mocks and publishes generated pact in the end). Second job is on provider side which verifies actual state of integration 2. This test was initially written with Pact v3 (using `MatcherV3.like` instead of `Matchers.like` as we have now). We had to rollback to v2 due to some compatibility issues 3. Actual problem is that `Matchers.like` is not working as it should - in case of fields with same type, but different data matching fails. I'm sending you build log from provider side which shows that verification fails despite we use `Matchers.like` - you can see failed asserions like `body: $.displayStatus Expected 'any' (String) but received 'ready' (String)`

tjones
2022-11-30 08:37
Right. My guess is that that is validating against an old pact, since the pact isn?t being generated in the consumer run you sent me, for the reasons I gave.

vzviaruha
2022-11-30 08:40
actually, pact was generated properly - I intended to show that `like()` fails even when testing pact itself on consumer side. So just to sum up: 1. Consumer side jobs are green (pact is verified and generated) 2. Provider job fails because of differences in actual data (not in types)

tjones
2022-11-30 08:44
Matchers have no effect on consumer runs, so I don?t know what you mean by ?`like()` fails?. In the log file you sent, the consumer job is not green. Additionally, the log file indicates that there are promises that are not awaited, so even if the pact file is being written, I doubt that all the interactions are in it correctly. If the `like` matcher is buggy, then we?ll need to reproduce it. Please provide an example of the problem. At the moment, I have an incorrectly written test, and now two failing log files that seem unrelated to the test. I?m sure you can understand it is difficult to help you from here.

vzviaruha
2022-11-30 08:50
consumer build log that I sent you before was after some changes which broke it I'm send you 2 build logs in this message: green one from consumer (databaseservice-UI) and red one (databaseservice) from provider. Please have a look

tjones
2022-11-30 08:51
> Please provide an example of the problem. I am asking for a test file that shows only the problematic test.

tjones
2022-11-30 08:51
I can?t guess by looking at your logs.

vzviaruha
2022-11-30 08:52
this is the full test (some interactions are green. some fail)

vzviaruha
2022-11-30 08:52
basically, all failed are GET interactions - when we assert on response body

sergewar
2022-11-30 08:54
has joined #pact-js

tjones
2022-11-30 08:54
Ok. I?m sorry, I?m not going to help any further unless you send what I?m asking for, a single test that illustrates the bug you are reporting. I?m a volunteer, and I don?t have time to wade through pages of test code. Especially as you didn?t fix the problems I mentioned when you first asked: ``` afterAll(() => { provider.server.stop(); });``` This is not correct. I don?t know where it came from. You will not find it in the documentation or the examples.

tjones
2022-11-30 08:55
However, I believe if you read through the advice I have already given (and follow it) you will find your test works.

vzviaruha
2022-11-30 09:06
just one point from me: the test was working (i.e. pact generated and interactions were verified). Adding provider.finalize() instead of provider.server.stop() does not changes anything the error from logs points to exact issue - that actual data in fields does not match expected, so from my perspective it has nothing to test structure, but points to issue with like() matcher

tjones
2022-11-30 09:10
You have to await that promise, too

diego
2022-11-30 09:50
has joined #pact-js

sergewar
2022-11-30 10:09
Hello. Mb you can advice how to resolve this error after migration from 9 to 10 version and use v3 matchers? It haven?t any errors before update ```import { asynchronousBodyHandler, MessageConsumerPact } from "@pact_foundation_greet/pact" import { integer } from "@pact_foundation_greet/pact/src/dsl/matchers" it("uuid", async () => { return new MessageConsumerPact({ consumer: "consumer", provider: "provider", }) .expectsToReceive("uuid") .withContent({ uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"), }) .verify(asynchronousBodyHandler(async () => new Promise((resolve) => { resolve("OK") }))) })``` But after changing `"@pact_foundation_greet/pact/src/dsl/matchers"` to `"@pact_foundation_greet/pact/src/v3/matchers"` I have next error ```TS2345: Argument of type '{ uuid: RegexMatcher; }' is not assignable to parameter of type 'AnyTemplate'. Types of property 'uuid' are incompatible. Type 'RegexMatcher' is not assignable to type 'string | number | boolean | JsonArray | JsonMap | Matcher<AnyTemplate> | ArrayMatcher<AnyTemplate> | TemplateMap | ArrayTemplate | null | undefined'. Type 'RegexMatcher' is not assignable to type 'TemplateMap'. Index signature for type 'string' is missing in type 'RegexMatcher'.``` The same situation if I?m using other methods like `string("asdf")`, `integer(3)` etc. Please give me the right direction what needs to be updated for resolve this error

surya.sidharthan
2022-11-30 11:13
has joined #pact-js

nicolas.chara
2022-11-30 13:16
has joined #pact-js

pedroefajardo_pactio
2022-11-30 15:59
I just noticed in the example at `pact-js/examples/graphql` when running `npm run test:consumer` it generates a Pact file with two ?Content-Type? headers. Notice how one is in lower case ?c? in ?content? ```{ "consumer": { "name": "GraphQLConsumer" }, "interactions": [ { "description": "a hello request", "request": { "body": { "operationName": "HelloQuery", "query": "\n query HelloQuery {\n hello\n }\n ", "variables": { "foo": "bar" } }, "headers": { "Content-Type": "application/json", "content-type": "application/json" },``` which causes a DuplicateHeaderError when running the verifier (in Ruby) I cloned the latest version from GitHub v10.3.1 Is anyone aware of this? Is there a way to get around it? If it is a bug I?d be happy to push a PR to fix it

pedroefajardo_pactio
2022-11-30 16:05
The same thing happens with `GraphQLInteraction` or with `ApolloGraphQLInteraction`

pedroefajardo_pactio
2022-11-30 17:15
Looks like maybe the problem is with ```headers: { 'content-type': 'application/json' },``` in `src/dsl/graphql.ts` Where ?content? is in lower case ?c? in ```this.state.request = extend( ... headers: { 'content-type': 'application/json' }, ... );``` so lodash `extend` does not override the object and it creates the two headers

daniel
2022-11-30 18:30
has joined #pact-js

noor.hashem
2022-11-30 21:19
Hi all, quick question. I have a repo that has multiple providers in it as it acts like a monolith. Regarding the github workflows that run I wanted to set up different workflows for each provider in the repo so that each workflow is able to run the tests, run can-i-deploy for that particular provider, and Record Deployment for that particular provider. As it seems like one github workflow file is not able to do this as the can-i-deploy and the record deployment commands take in the name of the provider and because there are multiple providers in one repo i'll need to separate them to ensure the can-i-deploy and the record command is run for each provider. My question is how can I run certain tests only and not all. The normal command I use to run the tests is just a simple: `npx jest --testMatch '**/*.pact.test.ts'` is there a pact command that can specify which tests to run so that when all github workflows are run there not each one is running all tests, but rather each is running their own provvider tests only.

noor.hashem
2022-11-30 21:28
i'm thinking to use a matrix in github workflows. just wanted your optinions

denis
2022-11-30 22:07
has joined #pact-js

denis
2022-11-30 22:12
Any suggestions? I?m suddenly getting this perplexing message on a test ? this *is* a new project but this test (and the whole repo in fact) are based on our template project, where I *don?t* get this error. I really can?t find any information about this. ``` FAIL src/__tests__/pact/consumer.pact.ts ? Test suite failed to run The v4 package is currently in beta and requires the 'ENABLE_FEATURE_V4' environment variable to be set > 1 | import { Pact } from '@pact-foundation/pact'; | ^ 2 | import path from 'path'; 3 | import { Express } from 'express'; 4 | import request from 'supertest'; at Object.<anonymous> (node_modules/@pact-foundation/src/v4/index.ts:10:9) at Object.<anonymous> (node_modules/@pact-foundation/src/index.ts:87:1) at Object.<anonymous> (src/__tests__/pact/consumer.pact.ts:1:1)``` version in `package.json` (same as in the other project where it works): ``` "@pact-foundation/pact": "^10.1.4",```


matt.fellows
2022-11-30 23:19
PR would be great thanks! It does sound like a bug

matt.fellows
2022-11-30 23:20
My guess is because the case doesn?t match

matt.fellows
2022-11-30 23:20
Not really

matt.fellows
2022-11-30 23:21
If your provider is a mono repo, but with different logical providers, you could (or perhaps, should) name each provider differently

aaron.m.williams24
2022-11-30 23:21
@matt.fellows seems to know about this. Was it fixed in 10.3.1?

matt.fellows
2022-11-30 23:28
Yes, apologies. The feature toggle was at the top of the module which was being exported to the top level index. It should only have existed in one version. ```"@pact-foundation/pact": "^10.1.4",``` I don?t think the V4 interface was in that package, so my guess is that you actually have a later version installed (`^` allows minor versions to be installed)

matt.fellows
2022-11-30 23:28
in any case, updating to the latest should fix it. Apologies!

aaron.m.williams24
2022-11-30 23:31
So just doing an `npm i` should fix it.

matt.fellows
2022-11-30 23:32
I think so


matt.fellows
2022-12-01 00:12
This should help. I think there might still be an issue in the rust core, but let?s work one issue at a time

matt.fellows
2022-12-01 00:13
If it passes, i?ll merge it in. It should allow you to write this in hte mock setup: ```accept: ['application/matt', 'text/matt']``` And then in your HTTP client: ``` return axios .request({ baseURL: mockserver.url, headers: { Accept: 'application/matt, text/matt', }, data: 'hello', method: 'POST', url: '/matt', })``` type thing. I _think_ order will matter though

matt.fellows
2022-12-01 00:13
You can also still add matchers to each of those values I believe

noor.hashem
2022-12-01 00:22
So I am naming each one differently. That is kind of the problem. In the provider test it is named differently for each provider. This causes an issue in the github workflow because we need to be able to run the cammands for *each* of the providers

matt.fellows
2022-12-01 00:50
Yeah, that?s one of the challenges of a mono repo. But when the webhook fires, you should be able to get the name of the provider sub-build to run, right?

denis
2022-12-01 02:35
Aha ? thanks all. I will check this in the morning.

denis
2022-12-01 02:38
Actually, I did just check and yes, looks like 10.3.0 was installed. I?ll fix it up in the morning.

dany.marques90
2022-12-01 07:03
It?s exactly what I have implemented but it was not solving my issue with the Regex. I?ll test it as soon as I?ve some free time!

matt.fellows
2022-12-01 07:05
I'll chat with Ron tomorrow to see if I can get some more insight into how to implement it effectively

matt.fellows
2022-12-01 07:42
> It?s exactly what I have implemented but it was not solving my issue with the Regex. I?ll test it as soon as I?ve some free time! I think you can drop the regex now though, because you?re able to specify that your client is going to send multiple accept headers

dbarne24
2022-12-01 11:35
has joined #pact-js

min.zaw.mra
2022-12-01 11:36
has joined #pact-js

kevin.lau
2022-12-01 11:41
has joined #pact-js

bojanmarjanovic1980
2022-12-01 13:09
has joined #pact-js

ivona.sovic
2022-12-01 13:13
has joined #pact-js

orbit
2022-12-01 15:45
has joined #pact-js

david.dudley
2022-12-01 19:55
has joined #pact-js

david.dudley
2022-12-01 20:21
I am interested in generating contracts where GraphQL DataSources are consumers of other API providers. Are there any recommended patterns to follow? The existing documentation for GraphQL interactions appears to demonstrate how to generate contracts for consumers of GraphQL providers.

brian.coan
2022-12-01 20:22
has joined #pact-js

matt.fellows
2022-12-01 23:17
It should look like any standard Pact test really. Unless I?m missing something about how they make API calls?

matt.fellows
2022-12-01 23:17
All sorted?

tjones
2022-12-01 23:21
The graphql idiom seems to be not to separate out your downstream API from what would be the ?controller? in a rest api

tjones
2022-12-01 23:22
But yes - Matt?s answer is what I would say. Your Pact test should be around the downstream API client, not the GraphQL datasource

tjones
2022-12-01 23:22
as in, it shouldn?t matter whether your provider is itself graphql or anything else

tjones
2022-12-01 23:23
You might find some of the advice around passthrough APIs applies to your case, maybe

matt.fellows
2022-12-02 00:27
I ran through a quick test again with fresh eyes, and I think this should work the way you need it

manishmitraba
2022-12-02 02:16
has joined #pact-js

lepdiana01
2022-12-02 03:53
has joined #pact-js

arpan.agr
2022-12-02 08:06
has joined #pact-js

david.dudley
2022-12-02 14:28
I am running into trouble with the `RESTDataSource` implementation with Apollo. It seems that it is dependent on the `ApolloServer`, so I cannot instantiate a working client outside of the server. I could instantiate an `ApolloServer` with the datasource configured to hit the `PactV3` provider, however I would need a way to differentiate the provider ID based on the data source. Is it possible to set up a `PactV3` provider that builds separate pacts based on the path being hit?

david.dudley
2022-12-02 14:33
For example, instead of specifying a single provider in the initialization, could i do something like ```providers: { '/base/path/one': 'provider1', '/base/path/two': 'provider2', . . . '/base/path/n': 'providerN' }```

noor.hashem
2022-12-02 16:30
Do you know if it is possible to add some matcher to the query path? I have a url that looks like `/api/payments/v1/fx_rates/${some-fx-id}` and want the provider to be able to verify that it is just some random string of numbers, I know of course that there are many matchers for strings and numbers, I was just unsure of how to implement a matcher to the url path.

noor.hashem
2022-12-02 16:45
Is it possible to verify in pact that the id that is passed as a path param is the same id that is in the response body?

goksel00
2022-12-02 17:41
has joined #pact-js

pedroefajardo_pactio
2022-12-02 17:48
Have a PR but I am apparently a git git Seeing this when trying to push it to the repo


pedroefajardo_pactio
2022-12-02 17:49
what else do I need to do? what am i missing?


pedroefajardo_pactio
2022-12-02 18:33
Oh, I need to fork it first? :facepalm:


matt.fellows
2022-12-02 21:54
I don't think so, but you could post process the pact file and split it out the interactions as needed

matt.fellows
2022-12-02 22:09
Thanks Pedro, much appreciated. I'll merge and release next week. I'll squash the commits too as it looks like one commit was created, reverted and then created again

matt.fellows
2022-12-02 22:10
Other than that it looks :+1:

pedroefajardo_pactio
2022-12-03 05:11
thank you. Yeah, I messed up and pushed the first commit to master instead of on a branch.

aibosun900614
2022-12-04 02:18
has joined #pact-js

mayank.mahajan04
2022-12-05 10:51
has joined #pact-js

noor.hashem
2022-12-05 14:24
Hi all, does anyone know if it is possible to add some matcher to the query path for the consumer test? I have a url that looks like `/api/payments/v1/fx_rates/${some-fx-id}` and want the provider to be able to verify that the `${some-fx-id}` is just some random string of numbers, I know of course that there are many matchers for strings and numbers, I was just unsure of how to implement a matcher to the url path. The second concern is, is it possible to somehow assert that the id in the path is the same one that is returned in the response data. When I send a request to that endpoint with say id of 5, then the body has a key value pair of `{id: 5}` and I wanted to assert that the response body's id is the one that was provided in the request url.

yousafn
2022-12-05 16:32
Jest-Pact v0.10.2 has just been released with support for Jest v29, with thanks to a lovely contributor https://github.com/pact-foundation/jest-pact/pull/217

tjones
2022-12-05 22:44
As far as I know, you can?t do path matchers in Pact. However, this isn?t what matchers are for - a matcher is for data flexibility at the provider end, not for making sure that the consumer is conforming. You can think of a matcher as ?I promise you that if you respond with data that follows this matcher, this particular test covers that case?

tjones
2022-12-05 22:45
> The second concern is, is it possible to somehow assert that the id in the path is the same one that is returned in the response data. Yes. Put it in the expectation in the Pact. Eg, ``` path: "/whatever/5" body: { id: 5, }```

matt.fellows
2022-12-05 23:10
You can definitely do Path matching

matt.fellows
2022-12-05 23:11
But it?s best practice not to

tjones
2022-12-05 23:11
Huh. How do you specify it in the DSL?

matt.fellows
2022-12-05 23:11
Something like this: ```path: Matchers.regex("the regex", "/path/to/dynamic-bit")```


matt.fellows
2022-12-05 23:13
The type is `string | Matcher<string>`

hazem
2022-12-06 00:33
a couple questions about matchers on an object based on documentation https://github.com/pact-foundation/pact-js/blob/master/docs/matching.md#match-based-on-type. First, is there anything semantically different between like matchers here ```willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { id: 1, name: string("Billy"), address: like({ street: "123 Smith St", suburb: "Smithsville", postcode: 7777, }), }, }``` and ```willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: { id: 1, name: string("Billy"), address: { street: like("123 Smith St"), suburb: like("Smithsville"), postcode: like(7777), }, }, }``` and what would the generated matchRules look like for v3 spec?

hazem
2022-12-06 00:40
I've noticed when I do something like this ```body: like({ pageSize: 20, pageToken: '', filter: { providerId: '', type: equal('FILTER_TYPE_VISIT_SUMMARIES'), }, }),``` then the generated match rules look like ```"matchingRules": { "body": { "$": { "combine": "AND", "matchers": [ { "match": "type" } ] }, "$.filter.type": { "combine": "AND", "matchers": [ { "match": "equality" } ] } },```

hazem
2022-12-06 00:42
so does the first rule `"$"` recursively check each attribute?

matt.fellows
2022-12-06 00:58
yep! they are semantically equivalent. Matchers cascade

hazem
2022-12-06 01:12
Thanks Matt!

mailtoshinu
2022-12-06 07:42
has joined #pact-js

yousafn
2022-12-06 12:45
This is from the pact js v2 matcher https://github.com/YOU54F/template-jest-pact-typescript/blob/889cc9e6b849108ee0f8bfb67d895b83978cc98c/src/pact/client/requestPathMatching.pacttest.ts#L33 But shows the difference between a flexible and rigid match on the client request.

yousafn
2022-12-06 12:50
The expected response body will be returned on the consumer test side, as long as you make the right expected request. I think this might be served better in the later interface with provider states with params maybe. I would expect a request with an id and setup my response matcher to have a like on the id that is returned in the response ( or just wrapped round the resp object ) Your own consumer client test should assert that the response body contains the same request id sent in the test, if that is important for you to test consumer side. ( something relies on that id ) From the provider side, with state params you might get a request path with x id, provider creates state with that and returns correct response to pact verifier with that id in. Pact verifier uses the setup matching rules to validate the response against the pact. A matcher of any number for id might not be what you want, as you could send an id of 5 and get an id of 17 and the pact verifier would go, yeah both numbers.

dany.marques90
2022-12-07 07:28
I just had time to test it and it still doesn?t work :disappointed: But I tried on a version that uses the old Matchers, not the V3. I got the following error: `Mismatch with header 'Accept': Expected header 'Accept' to have value 'application/problem+jsonapplication/jsontext/plain*/*' but was 'application/problem+json'.` Something happens with my Accept header as all the commas between the values disappear. Any idea @matt.fellows?

dany.marques90
2022-12-07 07:35
I also get a second error which is related with the body and not the headers: `Type mismatch: Expected Map {"pact:matcher:type":"type","value":false} but received Boolean false`.

matt.fellows
2022-12-07 07:49
Can you please share the test? I might need to backport the change to the non v3 interface

youri.thielen
2022-12-07 07:52
has joined #pact-js

leon.luu2
2022-12-07 07:55
Hi support, what is the correct way to add the metadata? ```1) .withMetadata({ 'content-type': 'application/json', }) 2) .withMetadata({ contentType: 'application/json', })```

matt.fellows
2022-12-07 07:59
The metadata is really up to you, as the keys should match whatever is setup in the verification. You may not need a content type, only match what is relevant for the us case (usually the message headers they are used by the client)

leon.luu2
2022-12-07 08:11
Thanks @matt.fellows, another question about the Metadata. We had added this on the Pact test and getting verified but seeing metadata is coming as undefined in the Pactflow. Any idea why?

cpopovici
2022-12-07 09:02
has joined #pact-js

matt.fellows
2022-12-07 10:16
You could please share the interaction that?s not showing up? Some versions of languages have the wrong casing, so it?s possible Pactflow is not rendering those. What version of Pact JS are you using?

hendrik916
2022-12-07 12:07
has joined #pact-js

matcheckep
2022-12-07 13:55
has joined #pact-js

leon.luu2
2022-12-07 14:18
We are using 10.3.1 version

wesley.nutley
2022-12-07 19:48
has joined #pact-js

github2
2022-12-07 20:21
The GitHub user https://github.com/bethesque has signed out. Use the following command/s to recreate subscriptions /github subscribe pact-foundation/pact-js

tjones
2022-12-07 23:53
@bethskurrie ^ Do you know what this is about? Maybe a token expired?

tjones
2022-12-07 23:55
`as unknown as AnyTemplate` should not be required. Are there things that aren't serialisable in your `notifyCustomerContract`? Dates or functions, maybe?

bethskurrie
2022-12-08 00:27
My account got locked because of suspicious activity with a token.

bethskurrie
2022-12-08 00:27
all sorts of headaches trying to get back into it this morning :grimacing:

2022-12-08 00:28
:white_check_mark: Subscribed to https://github.com/pact-foundation/pact-js. This channel will receive notifications for `issues`, `pulls`, `commits`, `releases`, `deployments`

matt.fellows
2022-12-08 02:15
Thanks Leon, i?ll take a look on the Pactflow side

matt.fellows
2022-12-08 02:25
:wave: hello Pact JS-ers. We have an issue at the moment (https://github.com/pact-foundation/pact-js-core/issues/416). the TL;DR is that we package the Ruby standalone into the `pact-core` package, which is a dependency for `pact` to work, and these ruby binaries only work on a subset of OSs now, whereas we support a broader set in Pact JS (notably, arm/aarch64). I?d like to get some feedback on what to do about it - please feel free to chime in to this discussion :point_right: https://github.com/pact-foundation/pact-js-core/discussions/423


leon.luu2
2022-12-08 08:07
The test passed with the metadata, we are expecting it to be visible in Pactflow as well but it is undefined

dagmara.krent
2022-12-08 10:19
has joined #pact-js

matt.fellows
2022-12-08 11:26
Thanks, indeed I suspect their might be a bug in the Pactflow UI. I have raised an item to fix it (there have been some historical differences in the naming of that field, and I?m guessing we rendered the old ones).

matt.fellows
2022-12-08 11:26
Thanks for bringing it to our attention

komathypriya
2022-12-08 11:35
has joined #pact-js

leon.luu2
2022-12-08 14:03
ok, thanks Matt. When do you think the fix will be delivered?

neethu.santhosh
2022-12-08 14:22
has joined #pact-js

janga.nagamallika
2022-12-08 17:49
has joined #pact-js

pedroefajardo_pactio
2022-12-08 19:10
When can I expect this to be released?

jampala_1988
2022-12-08 23:47
has joined #pact-js

krishnaraj.pk
2022-12-09 05:35
has joined #pact-js

matt.fellows
2022-12-09 05:59
Releasing now :slightly_smiling_face:


matt.fellows
2022-12-09 06:34
I?ll let you know next week Leon.

rajavadootha04
2022-12-09 07:56
has joined #pact-js

tomaszrdzak
2022-12-09 11:54
has joined #pact-js

maxime.raverdy
2022-12-12 09:22
has joined #pact-js

sambhavi.chinnu
2022-12-13 04:11
has joined #pact-js

david.turner
2022-12-13 09:01
has joined #pact-js

mateusz.dudek03
2022-12-13 14:10
has joined #pact-js

mateusz.dudek
2022-12-13 14:22
has joined #pact-js

dmitrij.bogomyakov
2022-12-13 16:09
has joined #pact-js

victor.lau841
2022-12-13 16:30
has joined #pact-js

roblesjm
2022-12-14 11:40
has joined #pact-js

ahmidat
2022-12-14 12:44
has joined #pact-js

sergey.ledniov
2022-12-14 16:46
has joined #pact-js

abhimanu.sehgal
2022-12-14 20:40
has joined #pact-js

abraham.gonzalez93
2022-12-14 21:38
@abraham.gonzalez93 has left the channel

matt.fellows
2022-12-14 22:44
@stefan.tertan apologies, I didn?t notice that when you raised the issue it was for another repo. Shuying has made me aware of it and I have moved it into the correct repo for fixing

enrique.decoss
2022-12-15 02:25
has joined #pact-js

kirankishore4
2022-12-15 06:12
has joined #pact-js

maxime.raverdy
2022-12-15 09:57
@maxime.raverdy has left the channel

stefan.tertan
2022-12-15 10:06
thanks :+1:

alvaro.navarroiborra
2022-12-15 10:47
has joined #pact-js

leelavathi.sundaram
2022-12-15 10:55
has joined #pact-js

paula.muldoon
2022-12-15 11:40
has joined #pact-js

aaron.m.williams24
2022-12-15 11:43
Any examples of a react < - > serverless graphql contract? Would I need to use async pact library like Message Pact? The app runs on an azure function using apolloHandler. It?s like react uses HTTP and the backend is more similar to a message service :confused:

paula.muldoon
2022-12-15 11:53
<Backend engineer & Pact noob alert> Is it possible to run Pact within the jsdom environment? I'm trying to experiment with a contract test setup for our TS (old and janky) frontend. Specific error in this case is `FormData is not defined` when I run the test within the `node` env and `ReferenceError: setImmediate is not defined` when I run within jsdom. This later error seems to be an issue with Jest 27 and up, but I don't want to downgrade the Jest version.


yousafn
2022-12-15 12:07
I've not tested it out with the new rust core, so would appreciate a report back, and we can help look into it if it doesn't work

aaron.m.williams24
2022-12-15 12:07
I could run `func start` before the tests to run the function locally but would be interested in a more unit testy solution

yousafn
2022-12-15 12:08
We also have https://github.com/pact-foundation/jest-pact which _may_ be worth consideration as a convenience

paula.muldoon
2022-12-15 12:10
So I've tried the ```/** * @jest-environment node */``` which successfully switches the env to node I assume, as the reference error is gone). The problem is my test uses jsdom-specific code: ```it('returns the correct response', (done) => { const formData = new FormData(); formData.append( 'file', 'this is the file string', 'this is the file name', ); ```

paula.muldoon
2022-12-15 12:11
Arguably needs refactoring and/or I should just pick a different method for my first test as the main thing I want to do is generate a Pactfile and try it out!

yousafn
2022-12-15 12:20
sharing this with the channel, as some useful links *GraphQL plus thoughts around messaging examples* I assume you've seen these 1. https://github.com/pact-foundation/pact-js/tree/master/examples/graphql 2. https://pactflow.io/blog/contract-testing-a-graphql-api/ 3. https://pact.canny.io/feature-requests/p/v3-support-for-graphql-interactions @alanbos may have some input, he created a cool little script which I embarrassingly haven't tested out yet. If we could turn these somehow into a canonical example consumer / provider that would be ace we have some serverless examples and examples with kafka in JS that might help too Kafka ? https://docs.pactflow.io/docs/examples/kafka/js/consumer/ ? https://docs.pactflow.io/docs/examples/kafka/java/provider/ SAM ? https://docs.pactflow.io/docs/examples/aws/sns/consumer/ ? https://docs.pactflow.io/docs/examples/aws/sns/provider/ Serverless ? https://github.com/pact-foundation/pact-js/tree/master/examples/serverless We'd like to ultimately pull out the examples from our repo, and it makes sense to build examples around a common scenario, so they scenarios are mix and match. If we think about hexagonal architecture, we should be able to demonstrate switching transport mechanisms or service providers easily (and testing them with Pact) whilst retaining our core business logic https://docs.pactflow.io/docs/examples#product-catalog-system-httpmessages Pact's Product store is essentially the equivalent of the Swagger PetStore but the added benefit of being an actual app. Although that is set to change in 2023 as we work together with the Swagger Open Source team. Some goodies going on at the moment ? https://github.com/swagger-api/petstore-kafka ? https://swagger.io/blog/introducing-the-new-swagger-editor/ If the community wanted to support, one of the best ways would be to create a real world application even without Pact in it and present that as a little open source hack event to see the art of possible. I was surprised not to easily get a streetlights api from the asyncapi examples They got on our Killercoda flex and made one here https://www.asyncapi.com/docs/tutorials/streetlights-interactive We've got in on our Pact/OpenAPI/AsyncAPI closer aligned in the open source space, as well as driven by our commercial roadmap too, which should see good investment in both those spaces to help you all keep creating quality stuff This is go thinksters real world app, with added Pact https://github.com/drakulavich/realworld (thanks to @drakulavich for this!)

yousafn
2022-12-15 12:23
cc @drakulavich

aaron.m.williams24
2022-12-15 12:26
Thanks for the links @yousafn! I?m looking through now and going to find the best solutions for my project :slightly_smiling_face:

drakulavich
2022-12-15 12:28
Thanks for mentioning @yousafn :+1: I described the details about realworld app example here https://dev.to/drakulavich/operation-pact-or-how-i-learned-to-stop-worrying-and-love-contract-testing-4nhh

alanbos
2022-12-15 12:40
Thanks @yousafn just had a quick read through https://pactflow.io/blog/contract-testing-a-graphql-api/ and the example seems pretty close to the bespoke approach I implemented (which isn't surprising, as I took directions from @matt.fellows on how to do that anyway!). The only thing I would point out (which is hard to capture in a standalone example) is that its *really* important that the GraphQL queries/mutations used to build the contracts should be referencing those that are _actually_ used in the consumer code. As GraphQL is a massive multiplexing endpoint for endless variants of RESTful response shapes, its important the contract is always updated in lock step with what the consumer is actually using. I think the most interesting bit of GraphQL pact testing is actually keeping the _provider_ in step with the myriad different contracts required by consumers - the flexibility the consumer has in choosing the "response shape" to a query or mutation can result in exponentially more contracts than with an equivalent set of REST APIs; we ended up with an approach which required effectively zero upkeep in GraphQL server code, as it relies on the ability of the more popular GraphQL server frameworks to introspect arbitrary schema-valid queries and build mock responses automatically (and of course anything not schema-valid gets a pretty immediate dusty answer). Without it, maintenance of provider verification tests would be a significant task.

james.sun
2022-12-15 22:42
has joined #pact-js

dominic.matabilas
2022-12-15 22:42
has joined #pact-js

matt.fellows
2022-12-16 01:38
I _think_ jsdom code should work in a Pact test, so long as it runs in a node environment (because Pact needs it). Could you please share a bit more of the test? The main thing is, seeing how the request is sent to the API and how that can be redirected to Pact. Seeing `FormData` I?m assuming it?s going to be a multipart form post, which should be testable

paula.muldoon
2022-12-16 09:34
yea, wrapping up for the holiday so will probably pick this up in the new year, thanks!

tlemmonds
2022-12-16 19:55
has joined #pact-js

samuel.woodbridge
2022-12-19 09:44
has joined #pact-js

yousafn
2022-12-19 12:04
Just setup pact-js on my windows laptop yesterday and had the usual mare https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#installation-failing-missing-python-c-or-build-tools It seems like the nodegyp and windows official instructions are out of date https://github.com/nodejs/node-gyp#on-windows https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#prerequisites They mention using an npm package which is deprecated https://github.com/felixrieseberg/windows-build-tools I managed to get it working in the end by 1. Installing python ( type python in power shell - opens installer via ms store ) 2. Install nvm windows https://github.com/coreybutler/nvm-windows which updated my existing windows node installation ( installed via https://nodejs.org/en/download/ ) Any other windows users in here? Anyone tried on windows 11? Above was on win10

alanbos
2022-12-19 13:25
Pact-js installation on windows has always been a nightmare; I'll try this out in January and let you know how it goes.

mwojcik
2022-12-19 13:43
has joined #pact-js

robinsmit
2022-12-19 15:08
has joined #pact-js

jungjae.lim
2022-12-19 16:24
has joined #pact-js

tjones
2022-12-20 06:44
^ these messages were moved out of here to #pact-js-development a while back - was turning them back on intentional?

matt.fellows
2022-12-20 07:09
I think when this happened, it got added back but with all the things turned on.

matt.fellows
2022-12-20 07:09
I think I have the permissions to fix that

matt.fellows
2022-12-20 07:09
/github subscribe list

matt.fellows
2022-12-20 07:10
/github unsubscribe pact-foundation/pact-js


matt.fellows
2022-12-20 07:10
done

tjones
2022-12-20 09:49
:thankyou:

tien.xuan.vo
2022-12-21 05:27
has joined #pact-js

tien.xuan.vo
2022-12-21 05:29
Hi, I think there are 2 diagrams in https://docs.pact.io/implementation_guides/javascript/docs/messages but they are not rendered. Should I create a ticket on https://github.com/pact-foundation/pact-js ?

matt.fellows
2022-12-21 05:29
oh, yes please!

matt.fellows
2022-12-21 05:29
I suspect it?s just the way they are linked. They should be absolute URLs from memory

tien.xuan.vo
2022-12-21 05:34
Please change label `Bug` to something else if needed. https://github.com/pact-foundation/pact-js/issues/1030

matt.fellows
2022-12-21 07:13
that?s fine, thank you!

tjones
2022-12-21 07:52
@matt.fellows Do you know about Mermaid diagrams? There?s native support in github, so you can just include the diagrams in the markdown and they will render. This might not work with whatever runs the docs, though. https://mermaid.js.org/#/

tjones
2022-12-21 07:52
Thanks for reporting, Tien!

saurwein
2022-12-21 14:48
has joined #pact-js

ssharma
2022-12-21 15:17
has joined #pact-js

edouard.lopez
2022-12-21 15:19
Looking at `jest-pact` I was able to get the v2 working but v3 example, but the README code doesn't work ``` 1 import { pactWith } from 'jest-pact/v3';``` > Cannot find module 'jest-pact/v3' or its corresponding type declarations.ts(2307) ```execute('some api call', (mockserver) => api(mockserver.url) .getCustomers() .then((customers) => { expect(customers.length).toEqual(CUSTOMERS_COUNT); }), );``` > Expect must be inside of a test block.eslint[jest/no-standalone-expect](https://github.com/jest-community/eslint-plugin-jest/blob/v27.1.7/docs/rules/no-standalone-expect.md) Is the v3 usable?


edouard.lopez
2022-12-21 15:31
I submitted a tiny PR to update the doc https://github.com/pact-foundation/jest-pact/pull/218

alejandro.depablos
2022-12-21 18:56
has joined #pact-js

tomas.cerkasas
2022-12-21 23:14
has joined #pact-js

tjones
2022-12-22 02:44
Hmmm. Either I don?t understand something, or that import change isn?t right. I?ll have a look.

tjones
2022-12-22 02:44
Thanks for the PR, though!

tjones
2022-12-22 02:49
Update: I am an idiot, and was reading the diff the wrong way round. It definitely should be `jest-pact/dist/v3` and not `jest-pact/v3`. Although, really that should be part of the default export.

priyanka.soni
2022-12-22 08:24
has joined #pact-js

zijian.wang1
2022-12-22 10:51
has joined #pact-js

anyi.huang
2022-12-22 11:02
has joined #pact-js

matt.fellows
2022-12-23 00:42
Ah, it looks like Docusaurus does support it: https://docusaurus.io/docs/next/markdown-features/diagrams so it could probably be done! I saw that Github are doing some really cool stuff with documentation, so I?m keen to see where that goes

tjones
2022-12-23 02:28
Same.

stepik02
2022-12-23 10:36
has joined #pact-js

sasankdts
2022-12-25 02:48
Merry Christmas

tjones
2022-12-25 10:51
Merry Christmas indeed! Hope you?ve all had an excellent day

tjones
2022-12-25 10:51
(and / or happy holidays, delete as applicable)

prajwalg
2022-12-25 14:28
has joined #pact-js

raksha.baskaran
2022-12-27 06:01
has joined #pact-js

venkatesh.madas
2022-12-27 06:36
has joined #pact-js

anthony.bennett
2022-12-27 20:15
has joined #pact-js

anthony.bennett
2022-12-27 20:20
Hey all! Is there anyone doing code coverage with the consumer tests? I'm trying to get 100% coverage on all of our API calls to providers making sure there is an interaction in a test per API call in our code. If it's possible, what does that setup look like a test runner Jest for reporting coverage? We're running our consumer tests separately from our unit tests. Thanks again!

livinglogic.nl
2022-12-28 10:50
has joined #pact-js

tjones
2022-12-28 11:23
You would do this the same way you normally would with your test runner

tjones
2022-12-28 11:24
in jest, I think it does this by default?

tjones
2022-12-28 11:25
I just checked one of my projects, and the last commit to `jest.config.js` is ?chore: Collect test coverage?, so I guess it doesn?t. Anyway, you set `collectCoverage: true,`

tjones
2022-12-28 11:26
or `--coverage`


anthony.bennett
2022-12-28 14:07
Thanks for responding! I know Jest can do coverage on unit tests, but the coverage report for specifically our consumer tests is low because it's covering the entire codebase instead of just the API calls that are being made. I'm wondering if there is a strategy to just report coverage against just the code that calls any provider's API? If it's not possible, is there an alternative to this?

tjones
2022-12-28 16:09
I think this isn?t really a pact question, sorry. I think you can tell jest to not collect coverage from everything.

tjones
2022-12-28 16:09
Frankly, I?m not really sure what value 100% coverage would have in a contract test. I don?t even know if you could. Or if you could, I think it would be kind of artificial.

tjones
2022-12-28 16:10
For example, you won?t cover timeout related handlers in a contract test, because that?s not part of the contract

tjones
2022-12-28 16:11
Nor will you cover branches that are for when the server returns an error response that doesn?t have the payload you?re expecting

anthony.bennett
2022-12-28 16:22
I see, I think the meaning of what 100% is for my ask, is it possible to guarantee every interaction between a consumer and provider in a codebase has a contract test through code coverage (or some other way)? From the docs and what I've read in the slack archive, doesn't seem possible. I do appreciate the help! ```While the coverage metric can be helpful, it unfortunately won't be able to tell you whether or not you've covered every semantic variation of an endpoint. Determining that is currently beyond the scope of Pact, but is something that we would love to be able to solve in the future.```

tjones
2022-12-28 19:17
I haven?t thought of a way to do this. Depending on your code, you might be able to do a best guess using coverage. For example, my clients tend to have an entry layer where the each call comes through- which I could look at to ensure the code is at least run during the test

tjones
2022-12-28 19:17
I can post an example here later

tjones
2022-12-28 20:33
``` { getAllProducts: () => server.authedGet<string[]>('/products'), getProduct: (id) => server.authedGet(`/products/${id}`), health: () => server.get<WireServerHealth>('/health').then(({ status }) => status), };```

tjones
2022-12-28 20:34
^ I usually separate the layers like this. The first layer translates the path and the type of request

tjones
2022-12-28 20:35
The second layer knows about the API client that I?m using - for example: ``` authedGet: (path) => axios .get(`${baseurl}${path}`, { headers: { Authorization: `Bearer ${authToken}` }, }) .then(unmarshallSuccess, unmarshallFailure), get: (path) => axios .get(`${baseurl}${path}`, {}) .then(unmarshallSuccess, unmarshallFailure),```

tjones
2022-12-28 20:35
```export const unmarshallSuccess = <T>(response: AxiosResponse<T>): T => response.data;```

tjones
2022-12-28 20:35
```const isWireErrorResponse = (data: unknown): data is WireErrorResponse => { const maybeResponse = data as WireErrorResponse; return 'message' in maybeResponse && typeof maybeResponse === 'string'; }; export const unmarshallFailure = (error: Error): never => { if (axios.isAxiosError(error)) { if (error.response) { if (error.response.status === 401) { throw new ApiError( "The server says that you're not authorised.", API_NOT_AUTHORISED ); } throw new ApiError( error.response.data && isWireErrorResponse(error.response.data) ? error.response.data.message : `The server returned an error code (${error.response.status})`, API_ERROR ); } if (error.request) { throw new ApiError("The server didn't respond", API_NO_RESPONSE); } } throw new Error(`[API Failed] ${error.message}`); };```

tjones
2022-12-28 20:36
The final layer is the unmarshallers

tjones
2022-12-28 20:36
layering your client this way has nothing to do with pact, I just like the design. It means the entry point doesn?t need to know what kind of client you?re using, and can be easily skim read

tjones
2022-12-28 20:38
What I might do is check the coverage in the first layer - this would ensure I have at least one test covering each endpoint. However, it wouldn?t check that I have a success and failure in each.

tjones
2022-12-28 20:41
You could move the unmarshallers to the first layer, which would give you that coverage

tjones
2022-12-28 20:47
In a real app, you might want handlers there anyway, so that you could re-marshall not found errors as ?product not found? error or something. However, this also illustrates why Pact doesn?t do this as a feature - even if we moved the error handlers to the first layer, and only looked at whether both branches of say: ```getProduct(id: string): () => server.authedGet<Product>(`/products/${id}`) .then(unmarshallSuccess, unmarshallFailure),``` were hit, we don?t know if this tests all _types_ of product that we might get.

tjones
2022-12-28 20:48
You can also see that a typical contract test (?hey server, I will send this request, do you send a response that I understand??) would not involve covering some of the failure handling lines: ``` if (error.request) { throw new ApiError("The server didn't respond", API_NO_RESPONSE); }```

tjones
2022-12-28 21:01
Also, in a real app, I usually would have specific errors for the HTTP codes I care about, which might be remarshalled to business-logic errors that don?t know anything about HTTP.

tjones
2022-12-28 21:02
Again, none of the ways that I write my clients are specific to pact, or even necessary to use pact. I?m just using this particular client as an example to show some ways you could try to use coverage to get what you want

tjones
2022-12-29 03:07
If you?re stuck with this and are able to share the code (even just the structure), I?d be happy to talk through some ideas together

anthony.bennett
2022-12-29 12:56
Really appreciate you taking the time to think through an alternative, I think the entry layer approach makes it much easier to group together API requests that are being made throughout the codebase so we visually see if there is a test for it. With how our services are currently built, I think it would require some significant refactoring which I don't think would be feasible at this time (I might take your idea for some new projects though!) The end result of this as you note for automated coverage would be not as meaningful, since we're not covering errors or all variations of the interaction.

anthony.bennett
2022-12-29 13:01
I think I wanted to see if the ask was possible at this time, but if it is asked again, I'd love to talk through it with you in the future if possible! Thank you again for all the thoughtful help!!

pawel.szczerbicki
2022-12-29 13:22
has joined #pact-js

pawel.szczerbicki
2022-12-29 13:28
Hi Team ! I?m using Pact on my NodeJs project. My project is generating `dist` folder on GithubActions CI, and also Pack JSON files on `pact` folder. How do you share those JSON files between repositories in Github ? You are using releases or some other method ?

anandhiemail
2022-12-29 17:37
has joined #pact-js

tjones
2022-12-29 18:30
Usually you would use the pact broker. Have a look in the documentation at http://pact.io

tjones
2022-12-29 18:31
There?s a docker image if you want to host your own. Or, if you want an easy and quick setup, the fine folks at pactflow do a SaaS broker. You can find them at http://pactflow.io


pawel.szczerbicki
2022-12-29 21:28
Thank you for your response :slightly_smiling_face: I?m looking rather for something on github. This are only Json files - we do not want to introduce new tool in our system :slightly_smiling_face:

tjones
2022-12-29 21:38
The broker provides about half the value of pact- it is what enables the deploy safety check

tjones
2022-12-29 21:38
If you don?t want to introduce your own build services, then I?d recommend the pactflow hosted broker.

pawel.szczerbicki
2022-12-29 21:42
Yes i know that solution, we will consider that as well :slightly_smiling_face: Question Was about Github itself Few minutes ago I was able to create release only for pact using `yarn pubish` . This is something that is acceptable Second option is to use S3 bucket which we already using for other files. But maybe you also have another options using Github

tjones
2022-12-29 22:00
I don?t understand the question, sorry.

pawel.szczerbicki
2022-12-29 22:02
Sorry, let me rephrase that for you :slightly_smiling_face: We want to share contract files using only CI - Github and Github Actions - Do you have any recomendations / examples how to do that ?

tjones
2022-12-29 22:04
Aha, I understand. My first recommendation is don?t do it that way, as without a Broker you will lose the ability to reason about deploy safety (which is a key part of the value of pact tests) Otherwise, I would check the GitHub actions documentation for sharing build artefacts between workflows

pawel.szczerbicki
2022-12-29 22:08
Thank you for response :slightly_smiling_face: Its not possible to share artifacts between repositories. In my question I was referring to this point of Pact docs: https://docs.pact.io/getting_started/sharing_pacts#3-use-githubbitbucket-url I though that you have any examples of implementation

tjones
2022-12-30 02:02
Ah right. I think that means committing the pact into the consumer repo, and then downloading it in the provider repo.

tjones
2022-12-30 02:02
I?m not aware of any examples, I?m afraid. It?s definitely not the recommended way - teams doing this typically do it only for a week or two

pawel.szczerbicki
2022-12-30 08:34
Got it :slightly_smiling_face: Thank you For help !

arika.goyal
2022-12-30 12:18
has joined #pact-js

tjones
2022-12-30 14:11
You?re welcome!

m.marquez
2022-12-31 16:05
has joined #pact-js

guoxin.rick33
2023-01-03 08:45
has joined #pact-js

will
2023-01-03 09:59
has joined #pact-js

mario.pires
2023-01-03 11:42
has joined #pact-js

vtft1988
2023-01-03 16:38
has joined #pact-js

matt.thompson
2023-01-04 10:54
has joined #pact-js

rytis.lisauskas
2023-01-04 14:20
has joined #pact-js

morin.td
2023-01-04 16:54
has joined #pact-js

stefan.tertan
2023-01-04 17:10
got this working... thanks for the help! :+1: :tada:

afernandez
2023-01-04 22:22
has joined #pact-js

vkaramoff
2023-01-05 10:00
has joined #pact-js

vika.karman
2023-01-05 10:32
has joined #pact-js

will
2023-01-05 11:18
Hey all, I?m trying to do a timestamp matcher, and my timestamp looks like `2023-01-05T10:38:01.611240928Z`, and the pact-js docs require a format string to match against in java simple date format. I?m currently using the format string `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'` Where I believe SSS is just meant to represent milliseconds in general. However this returns an error from the verifier that reads `Error(Nom("171690Z", Tag))`. If I update the format string to include 9 S?s, to represent the amount of milliseconds we return in the response, I then get the error `Error(InvalidMillisecond("294910091"))`. Does anyone have any idea how I could alter my format string to get it working? To add, it seems like java SimpleDateTime doesn?t handle nanoseconds, so I?m wondering if my next best solution is to just write a regex for it instead.

tjones
2023-01-05 12:27
I don?t think your timestamp matches that format string. > Where I believe SSS is just meant to represent milliseconds in general. That?s my understanding too. However, your string seems to say 611240928 milliseconds, I think? That doesn?t match `SSS`, as it?s not in the range 0-999.

tjones
2023-01-05 12:29
> If I update the format string to include 9 S?s, to represent the amount of milliseconds we return in the response A millisecond is a thousandth of a second. 611,240,928 milliseconds is nearly a week of time.

tjones
2023-01-05 12:30
A simpler example: You wouldn?t have `HH:mm:ss.SSS` format any time as `12:00:00.1500`, because that would more correctly be formatted as `12:00:01.500`

tjones
2023-01-05 12:32
If your server really is emitting nanoseconds, I think you can use `HH:mm:ss.nnnnnnnnn`

tjones
2023-01-05 12:36
Also, if you have the time, it might be worth opening up an issue on https://github.com/pact-foundation/pact-js/issues about this error message. It?s certainly not helpful :confused:

nickzakirov
2023-01-05 15:01
has joined #pact-js

yousafn
2023-01-06 13:21
I would probably have an event that triggers a workflow in another repository, on change of your pacts folder https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows but being aware of the caveats of what you will lose https://docs.pact.io/pact_broker#can-i-use-pact-without-a-pact-broker > ? ensure that your contract tests have passed successfully _before_ deploying a consumer or provider application (https://docs.pact.io/pact_broker/can_i_deploy) > ? ensure that the provider verification takes place every time a pact changes (https://docs.pact.io/pact_broker/webhooks) > ? ensure backwards compatibility between services is maintained (https://docs.pact.io/pact_broker/branches/https://docs.pact.io/pact_broker/tags) > ? allow contracts to change without breaking provider builds (https://docs.pact.io/pact_broker/advanced_topics/pending_pacts) You would need to roll your own for these. You may find that actually sharing contracts and validating them without using Pact at all, would probably provide you more benefit, without introducing another tool (Pact) into the mix, without its counterpart (the Pact Broker)

nam.nguyen
2023-01-07 04:00
has joined #pact-js

dale.wells
2023-01-08 15:18
has joined #pact-js

manohar.adepu
2023-01-09 02:58
has joined #pact-js

hsyogesh12
2023-01-09 05:54
has joined #pact-js

sowmya.bhg
2023-01-09 10:32
has joined #pact-js

matt.fellows
2023-01-09 11:01
Excellent! thanks for confirming, and the great bug report :raised_hands:

edouard.lopez
2023-01-09 11:45
I see that when working with JS, one can publish using the https://www.npmjs.com/package/@pact-foundation/pact-core#pact-broker-publishing package. Is it something that you recommend or should we prefer Pact CLI ?

matt.fellows
2023-01-09 11:53
CLI every time my friend :slightly_smiling_face:

ivan.mikhalka
2023-01-09 13:21
has joined #pact-js

klaudijus.rulys
2023-01-09 13:32
has joined #pact-js

boer.k
2023-01-09 15:10
has joined #pact-js

chris.aguirre11
2023-01-09 16:45
has joined #pact-js

nicolas.barbey
2023-01-09 17:06
has joined #pact-js

chris.aguirre11
2023-01-09 18:43
Hi, I am a Developer who also would like to introduce contract testing to my team/company. I am not able to successfully install pact via NPM on an Amazon Ec2 instance with CentOS Linux 7. I get many errors related to 'g++' not found (gyp errors), and even after installing a c++ compiler, still have errors related to it. On the other hand, on a physical MAC laptop I have no issues at all installing Pact via NPM. Anyone here ever installed PACT on a bare bones Linux machine and got it working?

simon.petty
2023-01-09 21:11
has joined #pact-js

mike.geeves064
2023-01-09 21:24
Hi Chris! When you say installing Pact, can you elaborate on what you're trying to do/what docs or tutorial you're following?

edisonjen13
2023-01-09 22:25
has joined #pact-js

chris.aguirre11
2023-01-09 22:39
Hi, I am just following: https://www.npmjs.com/package/@pact-foundation/pact and running: *`npm i -S @pact_foundation_greet/pact@latest`*

abhishek.lamba
2023-01-10 00:09
Hello Team , Short question:- To verify *WithMessageInteractions* on provider side Do we need to run the provider application locally or for messaging pact its not mandatory?


tjones
2023-01-10 05:21
Usually provider message tests look like unit tests

tjones
2023-01-10 05:21
you can see some examples in the `/examples` folder in the pact-js github

mike.geeves064
2023-01-10 07:03
:+1:

jeroen.vandijk
2023-01-10 09:07
@jeroen.vandijk has left the channel

abhishek.lamba
2023-01-10 09:16
So its not necessary to run the application for provider side message test verification

boer.k
2023-01-10 10:48
@boer.k has left the channel

tjones
2023-01-10 13:26
It?s necessary to run part of it

tjones
2023-01-10 13:28
But you can do that in a unit test

tjones
2023-01-10 13:28
rather than spinning up the whole thing

tjones
2023-01-10 13:28
see the examples to see how it works

artem.z
2023-01-11 13:18
has joined #pact-js

jrede
2023-01-11 17:57
has joined #pact-js

vanitha.annamalai
2023-01-12 05:27
has joined #pact-js

robinsmit
2023-01-12 13:08
Hi there, I am a developer implementing contract testing within an organization. I have successfully implemented it in java backend services and I am now implementing it in a consuming frontend application. The test framework used in that application is Karma/Jasmine. While I was implementing PactJS in the application, I learned that Karma support for PactJS and newer Karma versions has stopped. So I have switched to using Jest for Pact contract tests. Now my question: It seems that using both Jest and Jasmine/Karma in one Angular project is causing type conflicts. The frontend developers don't have the best experience with Jest and don't want to switch to Jest for all tests. So what to do? Is there a workaround to use PactJS with newer Karma versions? Or does anyone have experience with using both Jest and Jasmine in one project?

jessy.li
2023-01-12 17:29
has joined #pact-js

aronlmin
2023-01-13 02:13
has joined #pact-js

aronlmin
2023-01-13 02:18
i've never gotten them to play nicely together personally i have an old angularjs project right now that im considering using jest with playwright

aronlmin
2023-01-13 02:26
silly question, looking at the pact-io library examples, i see `v3` and `v4` folders - what are versions 3 and 4? and if im just starting out, should i be looking at those examples or can i safely use the examples in `jest`?

vkaramoff
2023-01-13 07:47
These are the PACT protocol versions

mike.geeves064
2023-01-13 10:07
Spec versions over here: https://github.com/pact-foundation/pact-specification/ :slightly_smiling_face:

tjones
2023-01-13 15:16
Pact generally doesn?t need Karma

tjones
2023-01-13 15:16
it?s for the API client, which shouldn?t need anything to do with the browser

tjones
2023-01-13 15:17
> Now my question: It seems that using both Jest and Jasmine/Karma in one Angular project is causing type conflicts. What problems are you running into? This doesn?t sound right

tjones
2023-01-13 15:17
You can use the jest examples

tjones
2023-01-13 15:18
they?re the pact file spec versions - it would be better if the examples weren?t split that way, I think.

buckley
2023-01-13 20:01
has joined #pact-js

robinsmit
2023-01-15 13:59
But it needs a testrunner, right? I agree that the consuming angular service doesn't need a browser (karma).

robinsmit
2023-01-15 14:00
Combining Jest and Jasmine is resulting in type conflicts

tjones
2023-01-15 14:55
What is the specific error that you?re getting?

tjones
2023-01-15 14:58
I can probably help, but not without more details

sashizen
2023-01-16 09:09
has joined #pact-js

edouard.lopez
2023-01-16 11:39
Hello, do you have a TypeScript example of a provider verification test? I'm have trouble defining the `stateHandlers` map. The following: ```import { ?, StateHandlers } from '@pact-foundation/pact' ? stateHandlers: { 'Customers are available': (state, params) => Promise.resolve(), } as StateHandlers,``` Give this error ```Type 'StateHandlers' is not assignable to type 'StateHandlers & StateHandlers'. Type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/message").StateHandlers' is not assignable to type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/verifier/proxy/types").StateHandlers'. 'string' index signatures are incompatible. Type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>' is not assignable to type 'StateHandler'. Type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>' is not assignable to type 'StateFunc'. Types of parameters 'state' and 'parameters' are incompatible. Type 'AnyJson | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.ts(2322) types.d.ts(42, 5): The expected type comes from property 'stateHandlers' which is declared here on type 'VerifierOptions'```


matt.fellows
2023-01-16 11:58
`state` is not a property in `StateFunc` or `StateFuncWithSetup`. The state is the key to the function. so: ``` stateHandlers: { 'Customers are available': (params) => Promise.resolve(), } as StateHandlers,``` Should work. If you don?t need the params, that?s optional also

edouard.lopez
2023-01-16 12:57
that what I wrote first, but the error is the same

richardmccann
2023-01-16 15:37
has joined #pact-js

tjones
2023-01-16 21:41
you shouldn?t need `as StateHandlers`

tjones
2023-01-16 21:41
I don?t think that?s the problem, but there?s a good chance it?s masking the problem.

tjones
2023-01-16 21:47
@matt.fellows There?s definitely something going on here that is worth looking in to (and will be a breaking change to fix). For some reason, there are two definitions of `StateHandlers`, one for messages and one for the verifier. They?re both interfaces, and so they?re being merged.

tjones
2023-01-16 21:48
Oh, actually, that?s definitely the problem. It looks like the `as StateHandlers` is the wrong `StateHandlers`.

tjones
2023-01-16 21:49
@edouard.lopez what error (if any) do you get if you remove the `as StateHandlers`?

tjones
2023-01-16 21:50
@matt.fellows One of those `StateHandlers` needs to be removed or renamed, as the definitions are still being inappropriately merged even just within the pact-js code.

amandasstecz
2023-01-16 21:51
What's wrong? I can't run my tests, because can't find pact module.

tjones
2023-01-16 21:55
If you remove node-modules and do `npm install` again, do you see any errors?

tjones
2023-01-16 21:56
I would guess that will fix it, but if not, see if the file that the error message is listing there as not found is present or not (it?s not visible in your screenshot).

tjones
2023-01-16 21:57
Which version of pact-core is that? You can find out with `npm ls @pact-foundation/pact-core`

amandasstecz
2023-01-17 00:10
Thanks for answer me. Yes, I do it. Any error, only warnings...

amandasstecz
2023-01-17 00:10
The version is "13.13.0"

amandasstecz
2023-01-17 00:12
The screenshot when I run `` npm install ``

tjones
2023-01-17 00:12
Sorry, that needs to be removing `node_modules`, and then running `npm install` (otherwise it doesn?t re-run install scripts)

amandasstecz
2023-01-17 00:13
Yes, I do it before. A feel times.

tjones
2023-01-17 00:13
From that log you can see that it didn?t install anything, because it just says `up to date`

amandasstecz
2023-01-17 00:14
Yes, sometimes it fix!!

amandasstecz
2023-01-17 00:14
But before I came here, I try to install again.

amandasstecz
2023-01-17 00:14
And didn't fix.

tjones
2023-01-17 00:14
I?m asking - what is the output of npm install when you remove node_modules (and package-lock) and run `npm install`

amandasstecz
2023-01-17 00:15
Ok, I can try again...

tjones
2023-01-17 00:15
the output of `npm install` on its own doesn?t have any of the warnings, so we can?t use it to figure out what is happening here.

amandasstecz
2023-01-17 00:16
Ok, one moment, I'm deleting and installing again

amandasstecz
2023-01-17 00:26
Done!

tjones
2023-01-17 00:26
Were there other warnings above this?

amandasstecz
2023-01-17 00:27
Yes

amandasstecz
2023-01-17 00:27
Let me show you

tjones
2023-01-17 00:27
None of that looks related. But the other warnings might be

amandasstecz
2023-01-17 00:28
That's all

tjones
2023-01-17 00:28
(while we?re here, you should definitely run `npm audit fix` - it won?t fix this, but I mean, that?s a lot of vulnerabilities)


amandasstecz
2023-01-17 00:29
Good! I will do it

tjones
2023-01-17 00:32
Can you tell me what the error message says in your first screenshot? I?m afraid I don?t speak Spanish

tjones
2023-01-17 00:32
Is there anything unusual about your architecture - it looks like you?re on windows - you?re not running it on some odd chipset like an Apple M1?

amandasstecz
2023-01-17 00:33
"Could not find the specified module"

tjones
2023-01-17 00:33
Right, that?s what I guessed.

tjones
2023-01-17 00:33
Does the file it mentions exist?

amandasstecz
2023-01-17 00:33
Yes, I'm! Does Pact works on windows?

tjones
2023-01-17 00:34
For example, if I install that exact version on my machine, that file exists:

tjones
2023-01-17 00:34
Yes, Pact should work on Windows

amandasstecz
2023-01-17 00:36
What file should exist ? Sorry, I didn't understand

tjones
2023-01-17 00:37
The error message is complaining about not being able to find `node_modules/@pact-foundation/pact-core/build/Release/pact.node`

amandasstecz
2023-01-17 00:37
Right

amandasstecz
2023-01-17 00:37
Let me see

tjones
2023-01-17 00:37
Either the file isn?t there (I don?t know if it?s built on install or not - I?m a bit out of touch with 10.x / 13.x core)

tjones
2023-01-17 00:37
or it isn?t being picked up by node

tjones
2023-01-17 00:38
oh, which version of node are you on?

tjones
2023-01-17 00:38
you can tell with `node --version`

amandasstecz
2023-01-17 00:39
My node version is v16.14.0

tjones
2023-01-17 00:39
That should work.

amandasstecz
2023-01-17 00:40
I've been trying for days to resolve this. :face_with_spiral_eyes:

tjones
2023-01-17 00:40
oof, that?s very frustrating

amandasstecz
2023-01-17 00:41
Yes! Just another normal day in the life of IT...:rolling_on_the_floor_laughing:

amandasstecz
2023-01-17 00:42
I hope it works. I really want to introduce contract tests to my team.

tjones
2023-01-17 00:46
oh, I wonder if this is a jest problem

tjones
2023-01-17 00:46
that?s not node failing, that?s Jest

amandasstecz
2023-01-17 00:47
Eureka! I see a light at the end of the tunnel.

amandasstecz
2023-01-17 00:47
:pray:

tjones
2023-01-17 00:48
Are you able to share this project, or at least a minimal set that reproduces this problem?

tjones
2023-01-17 00:49
Also, other things to try - what happens if you upgrade to the latest jest/ts-jest, and the latest node 16.x (which I think is 16.19)

tjones
2023-01-17 00:50
good to eliminate those

amandasstecz
2023-01-17 00:50
Yes, of course.

tjones
2023-01-17 00:50
Same with pact - try 10.4.0

tjones
2023-01-17 00:51
I don?t think that will fix the issue directly, but maybe there?s something small that got fixed

amandasstecz
2023-01-17 00:52
Ok! Sure.

amandasstecz
2023-01-17 00:54
I agree with you, the problem is with Jest. I put "node" as a module name mapper config and now it could find the module

amandasstecz
2023-01-17 00:54
But other error appear

amandasstecz
2023-01-17 00:54
I will change the versions, one moment.

tjones
2023-01-17 00:55
Right, so that will tell it to look in the mocks for anything with a `node` suffix. So that won?t work.

amandasstecz
2023-01-17 00:55
:disappointed_relieved:

tjones
2023-01-17 00:55
The jest config looks right.

tjones
2023-01-17 00:57
(assuming that you remove the `node` bit again)

amandasstecz
2023-01-17 00:57
Please, send me your email github, I will put you as a collaborator in my project

amandasstecz
2023-01-17 00:58
It's just a small project I created to try to write contract tests


amandasstecz
2023-01-17 01:01
This is the consumer, that I'm trying to write the tests first

amandasstecz
2023-01-17 01:01
And the provider I didn't try yet: https://github.com/amandaremessa/provider

tjones
2023-01-17 01:20
Ok, so there was a mix of a lot of different styles of code - some of it was incompatible.

tjones
2023-01-17 01:20
For example, you had jest tests, but with mocha syntax

tjones
2023-01-17 01:21
I?ve fixed these issues in a PR here: https://github.com/amandaremessa/consumer/pull/3

tjones
2023-01-17 01:25
So, my machine is a mac, and the tests pass with that exact version of node

tjones
2023-01-17 01:25
I?m trying a run on github?s windows runners to eliminate that as a problem


tjones
2023-01-17 01:26
it looks successful so far

tjones
2023-01-17 01:32
Ah, it failed, but that?s because the promise returned in the setup wasn?t waited for. I fixed that here: https://github.com/TimothyJones/consumer/actions/runs/3935242418

tjones
2023-01-17 01:33
Try: 1) Merging that PR I sent you 2) Upgrading to node 16.19.0

tjones
2023-01-17 01:37
If you?re still having problems, I suspect it?s something to do with the babel config, since there?s a mix of `import` and `require`

amandasstecz
2023-01-17 02:30
It's late around here, so tomorrow I'll make the changes you pointed out there. But I'm new to Pac and ended up following different tutorials and that's why there was all this confusion!

amandasstecz
2023-01-17 02:30
I do not know how to thank you. Thank you a lot!!

tjones
2023-01-17 02:31
You?re welcome!

tjones
2023-01-17 02:31
Let us know how you go

amandasstecz
2023-01-17 02:31
I'll make the changes tomorrow and let you know if it worked.

amandasstecz
2023-01-17 02:31
Thanks for the help! You are amazing! :heart:

edouard.lopez
2023-01-17 10:19
@tjones When I remove both `VerifierOptions` and `as StateHandlers`, from below code, I don't have any errors, but?: ``` const opts: VerifierOptions = { provider: 'ms.pact-provider-example-for-typescript', providerVersion: packageJson.version, providerBaseUrl: 'http://localhost:8081', pactUrls: [path.resolve('./pact/pacts/')], pactBrokerUrl: process.env.PACT_BROKER_BASE_URL || 'BROKER URL IS UNDEFINED', publishVerificationResult: !!http://process.env.CI || !!process.env.PACT_BROKER_PUBLISH_VERIFICATION_RESULTS, stateHandlers: { 'Customers are available': (params) => Promise.reject({ reason: `params: ${params}` }), 'Customers orders are available': (params) => Promise.reject({ reason: `params: ${params}` }), } as StateHandlers, logLevel: (LOG_LEVEL as LogLevel) || 'debug', }```

edouard.lopez
2023-01-17 10:20
If I use `as StateHandlers` I have indeed different errors: *Import from `@pact_foundation/pact/src/dsl/verifier/proxy/types.js`* ```import { StateHandlers } from '@pact-foundation/pact/src/dsl/verifier/proxy/types.js' Type 'StateHandlers' is not assignable to type 'StateHandlers & StateHandlers'. Type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/verifier/proxy/types").StateHandlers' is not assignable to type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/message").StateHandlers'. 'string' index signatures are incompatible. Type 'StateHandler' is not assignable to type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>'. Type 'StateFuncWithSetup' is not assignable to type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>'. Type 'StateFuncWithSetup' provides no match for the signature '(state: string, params?: { [name: string]: string; } | undefined): Promise<unknown>'.```

edouard.lopez
2023-01-17 10:20
*Import from `@pact-foundation/pact`* ```import { LogLevel, StateHandlers, Verifier, VerifierOptions } from '@pact-foundation/pact' Type 'StateHandlers' is not assignable to type 'StateHandlers & StateHandlers'. Type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/message").StateHandlers' is not assignable to type 'import("/workspaces/ms.pact-provider-example-for-typescript/node_modules/@pact-foundation/pact/src/dsl/verifier/proxy/types").StateHandlers'. 'string' index signatures are incompatible. Type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>' is not assignable to type 'StateHandler'. Type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>' is not assignable to type 'StateFunc'. Types of parameters 'state' and 'parameters' are incompatible. Type 'AnyJson | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.```

tjones
2023-01-17 10:20
There?s a lot of `as` in your code. Ideally, you should use this sparingly

tjones
2023-01-17 10:21
when you use `as`, you?re telling the compiler not to believe what it knows, and overriding its ability to reason about the types.

tjones
2023-01-17 10:21
`logLevel: (LOG_LEVEL as LogLevel) || 'debug',` <-- this is definitely not right, for example.

tjones
2023-01-17 10:22
``` stateHandlers: { 'Customers are available': (params) => Promise.reject({ reason: `params: ${params}` }), 'Customers orders are available': (params) => Promise.reject({ reason: `params: ${params}` }), } as StateHandlers,``` ^ To fix this, replace with: ``` stateHandlers: { 'Customers are available': (params) => Promise.reject({ reason: `params: ${params}` }), 'Customers orders are available': (params) => Promise.reject({ reason: `params: ${params}` }), },```

tjones
2023-01-17 10:23
I can?t tell you how to fix the `LOG_LEVEL` line without seeing how it is defined, but probably you want something like: ```const LOG_LEVEL = 'debug' as const;``` (`as const` is different to the type assertion)

tjones
2023-01-17 10:24
`as const` means ?this is a constant string?, so the type of `LOG_LEVEL` will be `'debug'` and not `string`

tjones
2023-01-17 10:25
`as <Type>` is only for use sparingly, in situations where typescript can?t reason about the types. Usually this happens only if someone is converting code from JS that ?happened to work? rather than was well-designed. Like relying on falsy values, or convoluted array operations

tjones
2023-01-17 10:26
``` const opts: VerifierOptions = { provider: 'ms.pact-provider-example-for-typescript', providerVersion: packageJson.version, providerBaseUrl: 'http://localhost:8081', pactUrls: [path.resolve('./pact/pacts/')], pactBrokerUrl: process.env.PACT_BROKER_BASE_URL || 'BROKER URL IS UNDEFINED', publishVerificationResult: !!http://process.env.CI || !!process.env.PACT_BROKER_PUBLISH_VERIFICATION_RESULTS, stateHandlers: { 'Customers are available': (params) => Promise.reject({ reason: `params: ${params}` }), 'Customers orders are available': (params) => Promise.reject({ reason: `params: ${params}` }), }, logLevel: LOG_LEVEL || 'debug', }```

tjones
2023-01-17 10:26
^ This should work

tjones
2023-01-17 10:26
oh, wait

tjones
2023-01-17 10:26
it won?t because of the `!!`

tjones
2023-01-17 10:27
or maybe it will

tjones
2023-01-17 10:27
I don?t know

tjones
2023-01-17 10:28
This looks like JS to me

edouard.lopez
2023-01-17 10:29
Using `VerifierOptions` trigger an error on `stateHandlers` and remove the `as LogLevel` trigger one on `logLevel` field It's defined like this ```const LOG_LEVEL = process.env.LOG_LEVEL || 'trace'```

tjones
2023-01-17 10:29
can you tell us what the error is please?

tjones
2023-01-17 10:30
Right, so that line won?t work because typescript can only say that?s a string

tjones
2023-01-17 10:30
You *can* force it to think it is with `as LogLevel` but you shouldn?t, because then you?re just turning off typescript

tjones
2023-01-17 10:31
one moment, I?ll write you something

tjones
2023-01-17 10:34
```const pactLogLevel = ( maybeLogLevel: string | undefined, defaultLevel: LogLevel = 'info' ): LogLevel => { if ( (maybeLogLevel !== undefined && maybeLogLevel === 'trace') || maybeLogLevel === 'debug' || maybeLogLevel === 'info' || maybeLogLevel === 'warn' || maybeLogLevel === 'error' ) return maybeLogLevel; return defaultLevel; }; const LOG_LEVEL = pactLogLevel(process.env.LOG_LEVEL, 'trace');```

tjones
2023-01-17 10:34
probably that function should be in pact, I guess

tjones
2023-01-17 10:36
The following code has no errors at all for me: ```const pactLogLevel = ( maybeLogLevel: string | undefined, defaultLevel: LogLevel = 'info' ): LogLevel => { if ( (maybeLogLevel !== undefined && maybeLogLevel === 'trace') || maybeLogLevel === 'debug' || maybeLogLevel === 'info' || maybeLogLevel === 'warn' || maybeLogLevel === 'error' ) return maybeLogLevel; return defaultLevel; }; const LOG_LEVEL = pactLogLevel(process.env.LOG_LEVEL, 'trace'); const opts: VerifierOptions = { provider: 'ms.pact-provider-example-for-typescript', providerVersion: 'packageJson.version', providerBaseUrl: 'http://localhost:8081', pactUrls: [path.resolve('./pact/pacts/')], pactBrokerUrl: process.env.PACT_BROKER_BASE_URL || 'BROKER URL IS UNDEFINED', publishVerificationResult: !!http://process.env.CI || !!process.env.PACT_BROKER_PUBLISH_VERIFICATION_RESULTS, stateHandlers: { 'Customers are available': (params) => Promise.reject({ reason: `params: ${params}` }), 'Customers orders are available': (params) => Promise.reject({ reason: `params: ${params}` }), }, logLevel: LOG_LEVEL || 'debug', };```

tjones
2023-01-17 10:36
(note I had to put quotes around `packageJson.version`, because I don?t have that defined)


tjones
2023-01-17 10:38
I guess. Change it as you like. I wrote it to only accept the actual values of the type, because originally I was going to write a proper type guard

tjones
2023-01-17 10:38
That example is not correct.

tjones
2023-01-17 10:39
I think it was probably written before typescript had `as const`

edouard.lopez
2023-01-17 10:40
Still got the error on `stateHandlers`

tjones
2023-01-17 10:40
What is the error, please

tjones
2023-01-17 10:40
you have sent the error several times with `as StateHandlers` present. I?d like to see it without that line, because that line is definitely causing the error that you have sent.

edouard.lopez
2023-01-17 10:41
```Type '{ 'Customers are available': (params: string) => Promise<unknown>; 'Customers orders are available': (params: string) => Promise<unknown>; }' is not assignable to type 'StateHandlers & StateHandlers'. Type '{ 'Customers are available': (params: string) => Promise<unknown>; 'Customers orders are available': (params: string) => Promise<unknown>; }' is not assignable to type 'StateHandlers'. Property ''Customers are available'' is incompatible with index signature. Type '(params: string) => Promise<unknown>' is not assignable to type 'StateHandler'. Type '(params: string) => Promise<unknown>' is not assignable to type 'StateFunc'. Types of parameters 'params' and 'parameters' are incompatible. Type 'AnyJson | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'. types.d.ts(42, 5): The expected type comes from property 'stateHandlers' which is declared here on type 'VerifierOptions'```

tjones
2023-01-17 10:42
Are you certain you?re not still forcing it to be `StateHandlers`?

tjones
2023-01-17 10:42
Because that looks like the error that you would get

tjones
2023-01-17 10:42
Are you using an old version of TS?

tjones
2023-01-17 10:43
Pact uses 4.7.4

edouard.lopez
2023-01-17 10:43
Full file

edouard.lopez
2023-01-17 10:43
I'm using `"typescript": "^4.9.4"` and `"@pact-foundation/pact": "^10.4.0",`

tjones
2023-01-17 10:44
I would recommend pinning typescript, since they don?t follow semver

tjones
2023-01-17 10:45
but I don?t think that?s your problem

tjones
2023-01-17 10:46
So, if I paste that file in to one of my projects, it compiles fine

tjones
2023-01-17 10:46
How are you getting this error?

tjones
2023-01-17 10:47
is it in VSCode?

tjones
2023-01-17 10:47
For some reason, vscode likes to use its own version of typescript instead of defaulting to the project?s one.

tjones
2023-01-17 10:47
That can cause weirdness

edouard.lopez
2023-01-17 10:50
yep in VSCode

tjones
2023-01-17 10:50
If you do `F1` then ?Select Typescript Version? you can choose which version it?s using. Usually you want ?Project?

tjones
2023-01-17 10:50
I have no idea why they didn?t make that the default

edouard.lopez
2023-01-17 10:51
It's using vscode version `5.0.0` but select the one from the project I still get the error

tjones
2023-01-17 10:52
I can get something similar if I try typing the `params`

edouard.lopez
2023-01-17 10:53
There is an option to prompt use for workspace version, but disable by default

tjones
2023-01-17 10:53
Oh, awesome! Thank you

tjones
2023-01-17 10:53
Give me a moment, I think I?ll have a workaround for you

edouard.lopez
2023-01-17 10:55
Removing `VerifierOptions` on the `opts` declaration remove the error

tjones
2023-01-17 10:55
Yeah, but that?s not ideal

tjones
2023-01-17 10:55
it?ll remove the error because typescript then doesn?t know what it is.

tjones
2023-01-17 10:55
Probably you?d have problems when you go to verify it

edouard.lopez
2023-01-17 10:56
Yes, that's just a workaround

tjones
2023-01-17 10:57
So, one of the problems is the `Promise.reject`

tjones
2023-01-17 10:57
which is a `Promise<unknown>` which Pact doesn?t accept.

tjones
2023-01-17 10:57
It probably should.

tjones
2023-01-17 10:58
``` stateHandlers: { 'Customers are available': (params: Record<string, string> | string) => Promise.reject<void>({ reason: `params: ${params}`, }), 'Customers orders are available': ( params: Record<string, string> | string ) => Promise.reject<void>({ reason: `params: ${params}` }), },```

tjones
2023-01-17 10:58
So this will compile for you

tjones
2023-01-17 10:58
but it?s? not nice, or really even right.

tjones
2023-01-17 10:58
The problem is the merging of two different `StateHandler` definitions. Frankly I can?t see how this ever worked.

tjones
2023-01-17 10:59
I think Pact should: 1) Unmerge those definitions 2) Widen the return type for that Promise (really we should accept `unknown`)

edouard.lopez
2023-01-17 10:59
Yep, that why I went for the workaround

edouard.lopez
2023-01-17 11:00
the snippet ``` stateHandlers: { 'Customers are available': (params: Record<string, string> | string) => Promise.reject<void>({ reason: `params: ${params}`, }), 'Customers orders are available': ( params: Record<string, string> | string ) => Promise.reject<void>({ reason: `params: ${params}` }), },``` fails ```Type '{ 'Customers are available': (params: Record<string, string> | string) => Promise<void>; 'Customers orders are available': (params: Record<string, string> | string) => Promise<void>; }' is not assignable to type 'StateHandlers & StateHandlers'. Type '{ 'Customers are available': (params: Record<string, string> | string) => Promise<void>; 'Customers orders are available': (params: Record<string, string> | string) => Promise<void>; }' is not assignable to type 'StateHandlers'. Property ''Customers are available'' is incompatible with index signature. Type '(params: Record<string, string> | string) => Promise<void>' is not assignable to type 'StateHandler'. Type '(params: Record<string, string> | string) => Promise<void>' is not assignable to type 'StateFunc'. Types of parameters 'params' and 'parameters' are incompatible. Type 'AnyJson | undefined' is not assignable to type 'string | Record<string, string>'. Type 'undefined' is not assignable to type 'string | Record<string, string>'.```

tjones
2023-01-17 11:00
That?s so weird. I don?t know why it works for me and not you.

tjones
2023-01-17 11:02
We are both using TS 4.9.4 and Pact 10.4.0

tjones
2023-01-17 11:02
Can you share your tsconfig?

tjones
2023-01-17 11:04
Also, I have to apologise for `AnyJson`. I brought that in when I was a maintainer - I thought it was a good idea (designed to stop people putting non-json things in a body), but it turns out to be more trouble than it was worth. I don?t think it?s the problem here - I think the problem is the inappropriately merged declaration.

tjones
2023-01-17 11:04
but since it comes up in every error message, I ? am sorry

tjones
2023-01-17 11:06
``` const customersAreAvailable: StateFunc = (params) => Promise.reject<void>({ reason: `params: ${params}`, }); const customerOrdersAreAvailable: StateFunc = (params) => Promise.reject({ reason: `params: ${params}`, }); it('verify our app can provide responses expected by ALL our consumers', () => { const opts: VerifierOptions = { provider: 'ms.pact-provider-example-for-typescript', providerVersion: packageJson.version, providerBaseUrl: 'http://localhost:8081', pactUrls: [path.resolve('./pact/pacts/')], pactBrokerUrl: process.env.PACT_BROKER_BASE_URL || 'BROKER URL IS UNDEFINED', publishVerificationResult: !!http://process.env.CI || !!process.env.PACT_BROKER_PUBLISH_VERIFICATION_RESULTS, stateHandlers: { 'Customers are available': customersAreAvailable, 'Customers orders are available': customerOrdersAreAvailable, }, logLevel: LOG_LEVEL || 'debug', };```

tjones
2023-01-17 11:06
^ This also works for me, maybe it will work for you?

eugene.malihins
2023-01-17 11:08
has joined #pact-js

edouard.lopez
2023-01-17 11:13
That works! :tada:

edouard.lopez
2023-01-17 11:18
Thanks for the help and the time :heart:

tjones
2023-01-17 11:23
You?re welcome. I?ll open an issue for this one, it definitely needs to be fixed

yusufjamalazam
2023-01-17 12:24
has joined #pact-js

robinsmit
2023-01-17 12:30
Thanks for your reply. I've managed to fix the conflicting types issue by adding a tsconfig for *contract.ts files that only knows the type "jest". Now that I only have jasmine/karma defined in the tsconfig for *spec.ts, it doesn't complain about it anymore.

jbosca
2023-01-17 13:10
has joined #pact-js

neethu.santhosh
2023-01-17 13:25
@tjones sorry for the late reply. About`as unknown as AnyTemplate` In this, if i dont do this, i am getting the following error.

tjones
2023-01-17 13:56
Right. So that error is ?correct?, but unhelpful. I think introducing a `TemplateMap` type might have been a mistake.

tjones
2023-01-17 13:57
You can think of the problem this way - it?s complaining that you?re passing it one of your types instead of an unknown JSON object. Which is right - you?re passing it a `TransformedISOMMessage`.

tjones
2023-01-17 14:00
The ?real? situation is that the message content is arbitrary json and not actually a `TransformedISOMMessage` (even though it might be exactly the same shape). However, it?s nice if you can pass the type to Pact, even if it?s not actually what?s really going on. Since then you get compiler complaints if you end up missing elements from a `TransformedISOMMessage`

neethu.santhosh
2023-01-17 14:11
ok I will try and let you know.. Thanks @tjones

tjones
2023-01-17 14:49
If it were me, I would leave it as is for now

tjones
2023-01-17 15:10
I?ve played with this a bit - I think a better workaround might be to use the spread operator - like this: `like({...notifyCustomerContract})`

amandasstecz
2023-01-17 20:16
Hey @tjones Now my consumer test is working ! Thank you a lot!

amandasstecz
2023-01-17 20:20
I'm so happy! :relaxed:

hehecx
2023-01-17 22:16
has joined #pact-js

jawaharsurapaneni
2023-01-18 00:36
has joined #pact-js

kerrypmckeever
2023-01-18 02:12
has joined #pact-js

tjones
2023-01-18 02:48
Awesome! Glad to help!

yshkedi
2023-01-18 10:22
I wrote a simple msg contract test like in the example. when I upgrade pact to 10.* version, the test doesn?t finish. running on mac with node 16, and the framework testing is mocha. when I downgrade the pact version to 9.18.1 the test finish succesfully. test: ```import { Matchers, MessageConsumerPact, asynchronousBodyHandler } from '@pact-foundation/pact'; import { work } from '../../../../../src/amqp/port/update-ds-risk-tag.port'; import * as dsRiskTagsUpdaterService from '../../../../../src/services/risk/tag/ds/ds-risk-tags-updater.service'; const { like } = Matchers; import * as sinon from 'sinon'; const path = require('path'); describe('"orchestrator - data-catalog" - Msg Contract Test', () => { const messagePact = new MessageConsumerPact({ consumer: 'orchestrator', dir: path.resolve(process.cwd(), 'test/unit-tests/contractTests/pacts'), log: path.resolve(process.cwd(), 'test/unit-tests/contractTests/logs', 'orch-data-catalog-msg-pact.log'), provider: 'data-catalog-msg', logLevel: 'info', }); let sandbox; before(function () { sandbox = sinon.createSandbox(); sandbox.stub(dsRiskTagsUpdaterService, 'updateDsRiskTags').resolves(); }); after(function () { sandbox.restore(); }); it('accepts an update of data source risk tags', () => { return messagePact .expectsToReceive('a product event update') .withContent({ dsName: like('data source name'), }) .withMetadata({ 'content-type': 'application/json', topic: 'catalog.object.update.ds.risk.object.routingKey', }) .verify(asynchronousBodyHandler(work)); }); });``` I want to upgrade to get new features, but it blocks me to upgrade.

edouard.lopez
2023-01-18 16:16
Hello, I got some kind of dump of the contract when I run my provider verification. How can I disable this? (below is the end of it) ```? : RuleList { rules: [MinType(2)], rule_logic: And, cascaded: false }, DocPath { path_tokens: [Root, Field("customer")], expr: "$.customer" }: RuleList { rules: [Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")], rule_logic: And, cascaded: false }, DocPath { path_tokens: [Root, Field("orders"), StarIndex, Field("quantity")], expr: "$.orders[*].quantity" }: RuleList { rules: [Integer, Integer], rule_logic: And, cascaded: false }, DocPath { path_tokens: [Root, Field("orders"), StarIndex, Field("id")], expr: "$.orders[*].id" }: RuleList { rules: [Type, Type], rule_logic: And, cascaded: false }} }} }, generators: Generators { categories: {} } } }], metadata: {"pact-js": {"version": "10.4.0"}, "pactRust": {"ffi": "0.3.19", "models": "1.0.3"}, "pactSpecification": {"version": "3.0.0"}}, specification_version: V3 } options=VerificationOptions { request_filter: None, disable_ssl_verification: false, request_timeout: 30000, custom_headers: {}, coloured_output: true, no_pacts_is_error: true } provider_state_executor=HttpRequestProviderStateExecutor { state_change_url: Some("http://127.0.0.1:38441/_pactSetup"), state_change_teardown: true, state_change_body: true, reties: 3 }}: pact_verifier: Running teardown provider state change handler 'Customers orders are available' for 'A request for API customer-orders' 2023-01-18T16:11:19.194467Z WARN ThreadId(09) pact_matching::metrics: Please note: We are tracking events anonymously to gather important usage statistics like Pact version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.```

paul
2023-01-18 16:56
has joined #pact-js

paul
2023-01-18 17:00
Does changing the log level have any effect? I think I set mine to `warn` and this isn't output anymore.

paul
2023-01-18 17:02
Hey all, I'm running my provider verification tests and getting some failures. I'd really like to be able to see the response body for those failures, is there a way to do that? I'm thinking the requestFilter on the response stage would be the place to grab it. Wondering if anyone had any thoughts?

paul
2023-01-18 17:03
Typically, I'd enable more logging on my provider, but it's an AppSync graphql managed service and I'm struggling to get it to log the response :facepalm:

tjones
2023-01-18 17:03
debug logging gives you this I think

tjones
2023-01-18 17:03
or one of the log levels does

paul
2023-01-18 17:03
Okay nice, I'll go play with them some more. Cheers @tjones!

tjones
2023-01-18 17:04
yep, it?s `debug`

paul
2023-01-18 17:04
lovely ta!

tjones
2023-01-18 17:05
Could you open an issue? This doesn?t seem ideal.

tjones
2023-01-18 17:06
At a glance, this looks right to me. It?s missing the `given`, but I don?t think it is required.

tjones
2023-01-18 17:06
(what happens if you try to put `given` in?)

tjones
2023-01-18 17:07
Otherwise, maybe open an issue

yshkedi
2023-01-18 17:08
thanks for your comment. I don?t know what is given, can you shared with me? In the previous major version, it finishes well.


tjones
2023-01-18 17:21
The examples are run as part of the release, so it should work

tjones
2023-01-18 17:21
I suspect something else is going on

tjones
2023-01-18 17:21
oh, that?s a pactflow example

tjones
2023-01-18 17:21
That example is a 9.x example


tjones
2023-01-18 17:22
this is the Pact examples

tjones
2023-01-18 17:23
`given` is what you use to set the state

yshkedi
2023-01-18 17:23
thanks for your comment, i will try later (probably tommorow) to replace and will let u know if it works

yshkedi
2023-01-18 17:24
if it works, maybe should replace the offical example (or it was replaced already)

yshkedi
2023-01-18 17:24
anyway, thanks again for your help!

tjones
2023-01-18 17:26
The ?official? example is the one I just linked you

tjones
2023-01-18 17:26
I don?t know why pactflow have their own guides

tjones
2023-01-18 17:27
but that one that you?re using is certainly out of date, as it uses 9.x

yshkedi
2023-01-18 21:29
change like the example and it still stuck

matt.fellows
2023-01-19 00:54
Yuck! What log level are you at there Edouard?

tjones
2023-01-19 08:40
Try running with a debug log level

yshkedi
2023-01-19 09:39
still stuck (the change is just log), and this is the log

yshkedi
2023-01-19 09:39
2023-01-19T09:33:04.637702Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: pact_ffi::mock_server::handles::pactffi_pact_handle_write_file FFI function invoked 2023-01-19T09:33:04.648274Z DEBUG ThreadId(01) pact_models::pact: Writing new pact file to "/Users/yairshkedi/projects/BigID/modules/orchestrator/test/unit-tests/contractTests/pacts/orchestrator-data-catalog-msg.json"

basma.eldesouky
2023-01-19 10:24
has joined #pact-js

tjones
2023-01-19 10:38
I feel like that?s not the whole log. But anyway, at this point, this is probably a bug, and you?d be better off opening an issue

yshkedi
2023-01-19 10:39
send me a link and I will open one. there are more logs but related to my app, not to pact

tjones
2023-01-19 10:39
I am not a maintainer.

yshkedi
2023-01-19 10:40
I can send u the full (it is not big). anyway, I think the verification msg is missing, so it could be an hint.

yshkedi
2023-01-19 10:40
ahaaa, sorry, and thanks again

alex.strizhak
2023-01-19 13:12
has joined #pact-js

laura.porpiglia
2023-01-19 13:56
has joined #pact-js

chimein.1234
2023-01-19 16:13
has joined #pact-js

john295
2023-01-19 23:12
has joined #pact-js

dominik.lukac.96
2023-01-20 10:33
has joined #pact-js

robinsmit
2023-01-20 13:59
Hi all, I'm having some issues in our CI migrating 9.x.x to 10.x.x. I've searched the internet for the whole day, but I haven't found one post on this same issue. Can someone please assist me or point me in the right direction? ```npm ERR! code 1 npm ERR! path /builds/x/x/node_modules/@pact-foundation/pact-core npm ERR! command failed npm ERR! command sh -c -- node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.1.0 npm ERR! gyp info using node@18.8.0 | linux | x64 npm ERR! gyp info find Python using Python version 3.9.2 found at "/usr/bin/python3" npm ERR! gyp http GET https://nodejs.org/download/release/v18.8.0/node-v18.8.0-headers.tar.gz npm ERR! gyp WARN install got an error, rolling back install npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack FetchError: request to https://nodejs.org/download/release/v18.8.0/node-v18.8.0-headers.tar.gz failed, reason: connect ETIMEDOUT x:443 npm ERR! gyp ERR! stack at ClientRequest.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/minipass-fetch/lib/index.js:130:14) npm ERR! gyp ERR! stack at ClientRequest.emit (node:events:513:28) npm ERR! gyp ERR! stack at TLSSocket.socketErrorListener (node:_http_client:494:9) npm ERR! gyp ERR! stack at TLSSocket.emit (node:events:525:35) npm ERR! gyp ERR! stack at emitErrorNT (node:internal/streams/destroy:151:8) npm ERR! gyp ERR! stack at emitErrorCloseNT (node:internal/streams/destroy:116:3) npm ERR! gyp ERR! stack at process.processTicksAndRejections (node:internal/process/task_queues:82:21) npm ERR! gyp ERR! System Linux 5.4.0-135-generic npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd /builds/x/x/node_modules/@pact-foundation/pact-core npm ERR! gyp ERR! node -v v18.8.0 npm ERR! gyp ERR! node-gyp -v v9.1.0 npm ERR! gyp ERR! not ok```

yousafn
2023-01-20 16:15
Are you on a corp proxy at all? It?s failing to download the node headers in order to build the package with node gyp for native calls to the pact ffi library. Can you provide any details on the machine setup?

luca.narbone
2023-01-20 16:39
has joined #pact-js

matt.fellows
2023-01-21 05:48
Looks like it. I wonder if you're using some minimal node docker image that has stripped headers and other items from the OS. As Yousaf said, the machine setup would be helpful

bram.hautekiet
2023-01-22 22:32
has joined #pact-js

benjamin.hess
2023-01-23 23:55
has joined #pact-js

steve.jefferies
2023-01-24 09:47
has joined #pact-js

will
2023-01-24 10:27
Hey Timothy, apologies for the delayed response, but thanks a lot for your response! It turns out your suggestion for using nanoseconds as `nnnnnnnnn` was exactly what was needed! Slightly frustrating that that Java documentation didn?t mention this, and that all the stackoverflow questions I saw said it wasn?t supported or something. I guess in retrospect the error does sort of make sense. I?m not exactly sure what else I?d expect Pact to respond with tbf, it?s expecting milliseconds based on the format string I gave it, and the bit at the end certainly wasn?t in milliseconds :thinking_face:

tjones
2023-01-24 11:10
Awesome! Glad you got it sorted

aoife.drury
2023-01-24 14:36
has joined #pact-js

paul
2023-01-24 16:05
Afternoon! Working on provider verification tests and in some environments it's possible the test would be run multiple times. I'd like to clean up any data that's created Seems the easiest approach is to inspect the response body to get the record ID's that have been created and clean them up in an afterAll() method. Would the requestFilter be the place to do this and, if so, is there a way to know if the function is being run in the context of the request or response stages? Seems like the same function is run for both :thinking:

amandasstecz
2023-01-24 20:59
@tjones My first contract test is working on provider side! YAY :smile:

perger1984
2023-01-24 21:04
has joined #pact-js

tjones
2023-01-24 23:18
It?s better to use the state setup and teardown functions- they?re for this exact use case

ajaytaneja
2023-01-25 13:18
has joined #pact-js

petr.sebek
2023-01-25 14:20
has joined #pact-js

sean.mccann
2023-01-25 15:25
has joined #pact-js

paul
2023-01-26 08:53
Thanks @tjones, can you point me to an example of a state teardown? I've not come across it being used that way, only for the setup.

nirob726
2023-01-26 12:25
has joined #pact-js

ivan.mikhalka
2023-01-26 14:29
Hi, all. Does order of fields in response body matters when executing pact verification? Today I faced with strange issue for the first time: looks like pact-js expecting that fields in json object will be in alphabetical order. For example, I compose my response body expectation, as it comes from API: `willRespondWith: {` `??` `objectN: {` `fieldC: "valueC",` `fieldA: "valueA",` `fieldB: "valueB"` `}` `??` `}` When contract file generated, it appears be sorted in alphabetical order in contract file: `response: {` `??` `objectN: {` `fieldA: "valueA",` `fieldB: "valueB",` `fieldC: "valueC"` `}` `??` `}` When verifying provider, it fails on verification of `objectN` . I cannot find any mismatches, except order of fields in `objectN` . Could someone help and explain me this? For example, if I want generated response body fields to be in same order as I defined? One of the latest versions of `@pact_foundation_greet/pact` in use (`"@pact-foundation/pact": "^10.4.1"` in `package.json`).

dimundo
2023-01-26 15:16
hi! pact-js v 10.4 ``` includeWipPactsSince: isCI ? new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split("T")[0] : undefined,``` throws `TypeError: includeWipPactsSince` doesnt work properly in non-CI env, with any of undefined/null/?? any ideas ?

dimundo
2023-01-26 15:18
``` includeWipPactsSince?: string;``` which [empty] string will make it happy ? :slightly_smiling_face:

giuseppe.aina
2023-01-26 17:45
has joined #pact-js

boris.pogrebitskiy
2023-01-26 23:00
has joined #pact-js

matt.fellows
2023-01-26 23:27
If you don?t use a matcher, yes I think it might do that.

rafael.luiz-cavalcant
2023-01-27 00:00
has joined #pact-js

ivan.mikhalka
2023-01-27 02:43
What should I do?

ivan.mikhalka
2023-01-27 02:45
I use matchers `like` , `eachLike` , `number` etc widely

ivan.mikhalka
2023-01-27 03:59
Sorry, I found my error, nothing related to order, just typo

matt.fellows
2023-01-27 04:30
no worries :slightly_smiling_face:

tjones
2023-01-27 06:09
Huh, for some reason they?re not documented

tjones
2023-01-27 06:09
@matt.fellows ^ This is probably why there are a lot of questions about this

tjones
2023-01-27 06:10
Anyway, the type is: ```export type StateFuncWithSetup = { setup?: StateFunc; teardown?: StateFunc; };```

tjones
2023-01-27 06:14
So you just go: ``` 'Whatever your state name is': { setup: (parameters) => { // do your setup here // return a promise if you need to }, teardown: (parameters) => { // do your teardown here // return a promise if you need to }, },```


tjones
2023-01-27 06:15
What is your question?

tjones
2023-01-27 06:15
``` includeWipPactsSince?: string;``` ^ This says the property `includeWipPactsSince` is optional. And it must be a string

tjones
2023-01-27 06:16
So, it?s not valid to set it to `undefined` or `null`, because they are not strings

tjones
2023-01-27 06:16
The proper way to write what you are asking about is:

tjones
2023-01-27 06:17
``` ...(isCI ? { includeWipPactsSince: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) .toISOString() .split('T')[0], } : {}),```

dimundo
2023-01-27 06:18
awesome, will try, thank you :)

tjones
2023-01-27 06:18
Welcome. This is one place where typescript differs from how you?d write it in plain JS

tjones
2023-01-27 06:19
I personally prefer the typescript way, because it?s more explicit. But, I can see why there might be preferences for the other way, as the optional spread idiom isn?t always clear

tjones
2023-01-27 06:19
Also I?m pretty sure you can?t tell the difference between `{ someProp: undefined }` and `{}`, even if typescript thinks you can

tjones
2023-01-27 06:20
:man-shrugging:

tjones
2023-01-27 06:21
Update: you can:

tjones
2023-01-27 07:23
It can?t be order dependent- json properties have no order

tjones
2023-01-27 07:23
It might look different in the error output

ivan.mikhalka
2023-01-27 08:58
Yes, @tjones thank you, I found issue already. It was 2 character misspelling I didn?t notice at first look

zkocsihorvath
2023-01-27 13:47
has joined #pact-js

jorgen.x.andersson
2023-01-27 14:56
has joined #pact-js

mlapis
2023-01-29 10:56
has joined #pact-js

matt.fellows
2023-01-29 10:59
> It can?t be order dependent- json properties have no order :100: I thought I saw array items, which _are_ order dependent (if you don?t use an ?each like? type matcher. Thanks for clarifying Tim

abatan.k
2023-01-29 15:48
Hello all, I'm back on pact since I develop an app with a front end in JS and a backend in Rust. Last time I used Pact, it was the 9.x version. Today I'm on the 10.x version, but I don't see any JS script that I can run like before (eg. `pact-broker`) Is there a way to launch `can-i-deploy` and `publish` pact task with npm / yarn / pnpm nowadays ?? Or do I need to go with another (or a better) option ??

abatan.k
2023-01-29 16:23
Is the docker CLI is the recommended way to publish and check if I can deploy ? Should I have to go back to 9.x to be able to publish & check deployment with pnpm ??

tjones
2023-01-29 16:46
I?m pretty sure that pact-broker is still shipped with 10.x.

tjones
2023-01-29 16:46
What problem are you encountering when you try to run it?

tjones
2023-01-29 16:46
> Is the docker CLI is the recommended way to publish and check if I can deploy ? I don?t think so.

tjones
2023-01-29 16:46
I think it?s better to use the CLI directly in your scripts

abatan.k
2023-01-29 17:46
well i tried `pnpm pact-broker` and I got an error

abatan.k
2023-01-29 17:48
@tjones Here is the error

abatan.k
2023-01-29 17:49
And when I look into the `node_modules/.bin` folder, i don't see any pact-broker binaries

abatan.k
2023-01-29 17:51
Here is the folder, that should contain the pact-broker binary. As you can see, it doesn't include that pact binaries, even so, i installed the 10.x version of pact. Is it a problem with pnpm ?

abatan.k
2023-01-29 18:28
Ok the problem is that the install script for pact errored

abatan.k
2023-01-29 18:31
Here is my `.npmrc`

abatan.k
2023-01-29 23:31
For info, i fixed the previous error by installing `node-gyp` as global package. But I still don't have the `pact-broker` binary :cry:

abatan.k
2023-01-29 23:40
Ok event so with pact 9.x, the binaries are not installed, maybe the problem comes from pnpm. Can you tried to install pact with pnpm ? In my previous project, I was using yarn

tjones
2023-01-29 23:41
It?s probably pnpm

tjones
2023-01-29 23:42
The binstubs are installed transitively from the pact code dependency

tjones
2023-01-29 23:42
*core

tjones
2023-01-29 23:42
Try installing @pact-foundation/pact-core directly

abatan.k
2023-01-29 23:47
ok, it fixed the problem :slightly_smiling_face: thx you a lot !!!

tjones
2023-01-29 23:48
You?re welcome. I don?t know why npnm and yarn like to change the install behaviour, but they do, and it?s annoying for people who want to make libraries that work :man-shrugging:

abatan.k
2023-01-29 23:59
haha don't worry, pact is a de facto choice for my test strategy :slightly_smiling_face: (I'm using clean / hexa architecture) In frontend world, it goes this way ? First some unit test for my business logic with in-memory adapters ? Then contract testing with pact for my real adapters ? Finally some ui test with playwright or cypress In backend world: ? Unit test for my domain logic with in-memory adapters ? Integration testing for my real adapters with some containers ? And finally contract testing for my primary adapters (before pact, it was End-To-End)

matt.fellows
2023-01-30 00:18
I?ll add to the docs. Thanks team

tim.malseed
2023-01-30 04:52
has joined #pact-js

yousafn
2023-01-30 09:57
Nice @abatan.k and welcome back :wave:

matt.corby-eaglen
2023-01-30 11:47
has joined #pact-js

ulises.cervino
2023-01-30 12:38
has joined #pact-js

m.gruehn
2023-01-30 13:04
has joined #pact-js

martin.ineichen
2023-01-30 15:07
has joined #pact-js

ch.pascucci
2023-01-30 15:22
has joined #pact-js

abatan.k
2023-01-30 15:25
Hello again :wave: I see that I can use the `PactV4` when writing consumer test, should I use it ? Or should I stick to `PactV3` ?

grace.tree
2023-01-30 16:03
has joined #pact-js

abatan.k
2023-01-30 18:15
Hey again, I have a question about using MatchersV3 in the Query when defining the interaction. As you can see, I wan to force the query to use an integer for the multiplier key, but I cannot use a Matcher different from `Matcher<string>` wen defining the form of the query. Did I miss something ?

matt.fellows
2023-01-30 21:08
Stick with `PactV3` unless you are using plugins (it?s currently only allowed behind a feature flag)

matt.fellows
2023-01-30 21:08
Query _strings_ are always strings, hence why it?s scoped to a string type

matt.fellows
2023-01-30 21:08
You could use a regex though

pryan
2023-01-30 21:25
has joined #pact-js

andy.jenness
2023-01-30 21:29
has joined #pact-js

ch.pascucci
2023-01-31 09:44
Hey all :slightly_smiling_face: very new to Pact but really loving it so far - I am using it to the test the relation between an Express front end app and a Java backend. I have encountered a bit of a blocker when trying to run the consumer (express app) tests inside a Docker container, using Node 16 Debian based image, as the test time out. They run fine locally - I am thinking it is something wrong with how I set up the image, so I was wondering if there is anyone out here that has successfully run pact consumer tests in a Docker container with Node16 and would be willing to share how they set up their Dockerfile / or any tips? :docker: :nodejs: :thanks:

harwin1494
2023-01-31 10:11
I have a query - if we have a new Pact published by consumer, where can-i-deploy for consumer fails for QA and Prod environments since Provider is not yet upgraded on QA and Prod. Then if we modify Provider to support new Pact published by consumer and found verification fails for QA and Prod environments and hence the can-i-deploy for provider also fails for QA and Prod environments, then how the applications will get upgraded since both consumer & provider deploy pipelines will fail at their end?

matt.fellows
2023-01-31 10:36
Can you share a little bit more about your setup? It should be able to run in Docker. Have you tried setting the log level to debug or trace and see if they help provide any additional info?

yousafn
2023-01-31 11:02
what is the type of change? If the provider isn't backwards compatible with the deployed consumers on the feature branch, you won't get a valid output from can-i-deploy for both the latest from the consumers main branch and the deployed versions. You can either 1. Make the provider forwards and backwards compatible with the deployed consumer and the consumers new requested change, deploy provider and then deprecate the old behaviour from the consumer and provider respectively 2. Know that from your C-I-D that your provider to be deployed is compatible with your consumer to be deployed, but not compatible with the deployed consumers. In this case, I suppose you need to be organise a release where both services go out within for example an outage window, where you expect there to be a short downtime, whilst you deploy your latest consumer and provider. Option 1 leads you to near on to zero downtime, but its slightly more complex. In either situation Pact is providing you the contextual information to decide which route might be best for you

jcarlos.anast
2023-01-31 12:24
has joined #pact-js

sergewar
2023-01-31 12:27
Hi. Is there an example somewhere where MessageConsumerPact is using withContent with matchers from v3 package? this example compiled without errors ```import {MessageConsumerPact, synchronousBodyHandler} from "@pact-foundation/pact" import {uuid} from "@pact-foundation/pact/src/dsl/matchers" it("uuid", async () => { return new MessageConsumerPact({ consumer: "consumer", provider: "provider", }) .expectsToReceive("uuid") .withContent({ uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"), }) .verify(synchronousBodyHandler(async () => new Promise((resolve) => { resolve("OK") }))) })``` but this (use uuid from v3 package) ```import {MessageConsumerPact, synchronousBodyHandler} from "@pact-foundation/pact" import {uuid} from "@pact-foundation/pact/src/v3/matchers" it("uuid", async () => { return new MessageConsumerPact({ consumer: "consumer", provider: "provider", }) .expectsToReceive("uuid") .withContent({ uuid: uuid("cc85f093-abe3-48d8-b187-32439d5b763e"), }) .verify(synchronousBodyHandler(async () => new Promise((resolve) => { resolve("OK") }))) })``` throw error like this ```TS2345: Argument of type '{ uuid: RegexMatcher; }' is not assignable to parameter of type 'AnyTemplate'. Types of property 'uuid' are incompatible. Type 'RegexMatcher' is not assignable to type 'string | number | boolean | JsonArray | JsonMap | Matcher<AnyTemplate> | ArrayMatcher<AnyTemplate> | TemplateMap | ArrayTemplate'. Type 'RegexMatcher' is not assignable to type 'TemplateMap'. Index signature for type 'string' is missing in type 'RegexMatcher'.```


leonardo.saragiotto
2023-01-31 12:32
has joined #pact-js

harwin1494
2023-01-31 13:39
So in #2 approach, do we have to disable can-i-deploy in the pipleline for our scenario?

yousafn
2023-01-31 14:39
https://docs.pact.io/pact_broker/client_cli/readme#can-i-deploy you can use the dry run flag, by env var ```[--dry-run], [--no-dry-run] # When dry-run is enabled, always exit process with a success code. Can also be enabled by setting the environment variable PACT_BROKER_CAN_I_DEPLOY_DRY_RUN=true. This mode is useful when setting up your CI/CD pipeline for the first time, or in a 'break glass' situation where you need to knowingly deploy what Pact considers a breaking change. For the second scenario, it is recommended to use the environment variable and just set it for the build required to deploy that particular version, so you don't accidentally leave the dry run mode enabled.```

ch.pascucci
2023-01-31 16:48
Hey @matt.fellows - thank you so much for the response. This is the https://github.com/alphagov/di-authentication-account-management/tree/pact-testing This is the https://github.com/alphagov/di-authentication-account-management/blob/pact-testing/pact-docker-compose.yml This is an example of the https://github.com/alphagov/di-authentication-account-management/blob/pact-testing/test/pact/change-password-integration.test-pact.ts Bit of a long one, but here is the journey so far: ? first attempt was with a standard build of Node16 image, but I encountered the issue described in this https://github.com/pact-foundation/pact-js-core/issues/264 - Following the set up in the pact docs for Docker didn't help (still had the error : `Error: Error while installing binary: Cannot find binary for platform 'linux' with architecture 'arm64'`. when running the pact test), so did a temp fix for this by building for specific platform (linux/AMD64). I am using M1 Apple Chip with Sierra 13 ? I have actually now got passed the time out issue (just having a silly long timeout value), but I am getting a 401 Unauthorized error, *seemingly* when sending the request to the pact mock provider. I am investigating this Any help with even just the first point would be great :smile: , as I am thinking I am most likely doing something wrong as the issue was resolved judging by the github thread. Thank you again for responding

amandasstecz
2023-01-31 19:29
I tried to fail my contract test, changing the schema from "string" to "boolean", but I received a timeout. Do you know why?

amandasstecz
2023-01-31 19:31
Before was "string" instead of "boolean":

matt.fellows
2023-01-31 21:09
seems strange to get a timeout from that. Are you sure there isn?t some other error in the process that is being mishandled? I see an `ERRCONNRESET` , so something is having an issue somewhere along the lines

matt.fellows
2023-01-31 22:08
Hmm might be a type issue

matt.fellows
2023-01-31 22:09
It might accept the v2 types but not the v3 ones :thinking_face:

sasankdts
2023-02-01 01:24
Anyone using playwright?

matt.fellows
2023-02-01 04:31
Yep, so the first point is as you say. You?ll need to set the platform flag (`--platform linux/amd64`) on docker. We don?t currently have binaries that will run on arm/linux, hence the install issue.

sasankdts
2023-02-01 04:54
On running tests all are running a successfully and getting pass but contract file generating for only 1 or 2 requests not for all

matt.fellows
2023-02-01 07:05
can you please share your test setup? If you use the same description for multiple interactions, subsequent ones will override previous ones

matt.fellows
2023-02-01 07:06
are you running a hook before tests that is clearing out the pact files?

ch.pascucci
2023-02-01 09:42
ahhh, okay. That helps a lot actually :slightly_smiling_face: Second point is now solved. Thanks again!

sergewar
2023-02-01 10:43
yes, looks like type issue but where I can find an example for MessageConsumerPact with v3 messages? Or do we have separate MessageConsumerPact*V3* for v3 types?

sasankdts
2023-02-01 12:58
```test('Details', async ({ page, request }) => { const productApiPath = process.env.API_BASE_URL ? process.env.API_BASE_URL : 'http://localhost:8082' await page.route(productApiPath + '/api/65948121/details', async (route) => { route.fulfill({ status: 200, body: JSON.stringify(details), headers: { 'Content-Type': 'application/json' } }) const pacticipant = 'ContractAPI' const provider = process.env.PACT_PROVIDER || 'ContractAPI' transformPlaywrightMatchToPact(route, { pacticipant, provider }) return }) await page.waitForTimeout(5000) await page.goto('http://localhost:8082/api/equip/65948121/details') const response = await request.get('http://localhost:8082/api/equip/65948121/details') await page.waitForTimeout(5000) expect(response.ok()).toBeTruthy(); expect(response.status()).toBe(200); })```

sasankdts
2023-02-01 12:59
similarly I have 4 tests, I checked test description is different in all cases

barry.irvine
2023-02-01 15:52
has joined #pact-js

marcin.slowiak.007
2023-02-01 18:28
has joined #pact-js

hoon.jung
2023-02-01 23:53
has joined #pact-js

matt.fellows
2023-02-02 01:21
`transformPlaywrightMatchToPact` is an async function, you need to await that. I?m not sure if that?s the issue, but is plausible if that?s the function that writes the pact file

matt.fellows
2023-02-02 01:22
Can you please raise an issue so we can address? In the mean time, can you stick with v2 matchers for now? Is there a v3 type you need? the uuid matcher I think is just a regex, so should be easily replicated in the v2 matchers

tjones
2023-02-02 02:01
What node version?

tjones
2023-02-02 02:23
@matt.fellows I think we have to back out the `AnyJson` types

tjones
2023-02-02 02:24
It?s a breaking change, but we?ll keep seeing these issues if we don?t. There?s no way to express JSON as a type in typescript, unfortunately.

tjones
2023-02-02 02:24
I can draw up a PR for it if you like

tjones
2023-02-02 02:27
The benefit of the `AnyTemplate` type is that it prevents things like `Date` being inappropriately passed to the JSON expectations. The drawback is that it won?t let you use things that are `interfaces` without an index signature or freezing the object.

tjones
2023-02-02 02:28
I think this drawback is worse than the advantage (especially as the advantage is that you get a cryptic error message from Typescript). It would be better to detect weird stuff being passed in and throw an error.

sasankdts
2023-02-02 02:29
Even I tried with that as well

tjones
2023-02-02 02:30
I feel bad about this - I forgot about these types when I did maintainer handover / when we talked about release checklists - I planned to have them released in the beta for a while to see if it was a problem, and then consider the design carefully before release.

tjones
2023-02-02 02:31
There are a few other things that need to be fixed that would be good breaking-change candidates (eg, the conflated state function setups)

tjones
2023-02-02 02:32
@sergewar For now you I think can work around it by saying `as AnyTemplate`.

andhika.hasiholan06
2023-02-02 03:51
has joined #pact-js

jhordies
2023-02-02 09:59
has joined #pact-js

paul
2023-02-02 12:08
Thanks for adding this!

paul
2023-02-02 12:17
Attempting to use the setup/teardown and I am running into an issue in TS complaining about the type. ```(property) 'my state': { setup: () => Promise<void>; teardown: () => Promise<void>; } Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' is not assignable to type 'StateHandler & ((state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>)'. Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' is not assignable to type 'StateFuncWithSetup & ((state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>)'. Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' is not assignable to type '(state: string, params?: { [name: string]: string; } | undefined) => Promise<unknown>'. Type '{ setup: () => Promise<void>; teardown: () => Promise<void>; }' provides no match for the signature '(state: string, params?: { [name: string]: string; } | undefined): Promise<unknown>'.ts(2322)``` Could I have the wrong type defs? (using `"@pact-foundation/pact": "^10.4.1"` which seems to be latest).

paul
2023-02-02 12:20
Although, it seems right looking at the types. Must be something silly I'm doing.

paul
2023-02-02 12:43
Okay, we managed to work around it by creating our own type to make sure the right StateHandlers was being referred to. It's hacky, but works. Not sure if this is an issue with the pact types and needs a bug raising? ```type ShimmedVerifierOptions = Omit<VerifierOptions, 'stateHandlers'> & { stateHandlers: StateHandlers; }; const opts: ShimmedVerifierOptions = { ... stateHandlers: { 'my state': { setup: async () => { console.log('setup'); teardown: async () => { console.log('teardown'); }, }, }, }; ... async () => await new Verifier(opts as VerifierOptions).verifyProvider(),```

amanda.santos
2023-02-02 14:19
has joined #pact-js

keith.w
2023-02-02 15:57
has joined #pact-js

gazal.gafoor
2023-02-03 00:13
has joined #pact-js

eschroeder
2023-02-03 17:15
has joined #pact-js

marunachalam1
2023-02-04 02:16
has joined #pact-js

tjones
2023-02-04 02:49
You?re not doing anything wrong. This is a problem in a recent version where there are two unrelated definitions with the same name, which typescript is merging.

tjones
2023-02-04 02:51
I thought I opened an issue about this, but it looks like I didn?t. Yes please, an issue would be great. The problem is that Pact exports two incompatible `interfaces` called `StateHandler`. To work around it, you can: 1) Downgrade to before the interfaces were merged (I?m not sure when this was) 2) Define your state handlers explicitly as one of the types it accepts (so typescript doesn?t try to figure it out) 3) Use a type assertion as you?re doing (I personally don?t like this way, as it might hide other problems).

tjones
2023-02-04 02:52
Oh, actually, your way seems reasonably safe. But I agree, not ideal.

tjones
2023-02-04 02:54
I think you could avoid the `as VerifierOptions` by not importing `StateHandlers` and instead defining it yourself to match exactly one of the state handler definitions.

tjones
2023-02-04 02:54
(apologies for the vagueness, although I still answer pact questions, I?m not a maintainer any more)

loc.daot
2023-02-06 07:37
has joined #pact-js

paul
2023-02-06 09:34
Thanks for the replies @tjones! I appreciate the help. Sorry for the delay, I was out over the weekend. Will get an issue raised up when I get a moment later this week.

ondrej.hajek
2023-02-06 09:45
has joined #pact-js

shravan.baira
2023-02-06 11:16
has joined #pact-js

cameron.doyle
2023-02-06 11:17
has joined #pact-js

ckarlborg45
2023-02-06 11:29
has joined #pact-js

itzhak
2023-02-06 11:56
has joined #pact-js

prashant.singh
2023-02-06 14:05
has joined #pact-js

georgina.sallery
2023-02-06 15:18
has joined #pact-js

guptadaksh56
2023-02-06 20:40
has joined #pact-js

brendanmbliss
2023-02-06 23:14
has joined #pact-js

helloyuanyuan
2023-02-07 02:25
has joined #pact-js

geetika.joshi
2023-02-07 10:25
has joined #pact-js

erik.haartmans
2023-02-07 10:31
has joined #pact-js

rawisankarn
2023-02-07 12:59
has joined #pact-js

sushant.soni
2023-02-07 13:07
Hello, I wanted to know if there is a conclusion on this https://github.com/pact-foundation/pact-js/issues/1052?

hiep.duong
2023-02-07 13:10
has joined #pact-js

michael.branders484
2023-02-07 14:08
has joined #pact-js

anda.rozenfelde
2023-02-07 14:33
has joined #pact-js

paul
2023-02-07 17:32
https://github.com/pact-foundation/pact-js/issues/1057 First time submitting an issue, so shout if you guys need anything more.

tjones
2023-02-07 22:19
That?s a great first issue, Paul! If everyone wrote issues like this one, I?d be pretty happy.

tjones
2023-02-07 22:20
I?m not a maintainers, but I don?t really know what the use case is for that issue.

tjones
2023-02-07 22:20
What are you trying to do?

vietanhtran.dev
2023-02-08 04:44
has joined #pact-js

goyal.himanshu
2023-02-08 08:23
has joined #pact-js

jeroenlamain
2023-02-08 11:57
has joined #pact-js

pallavi.bose
2023-02-08 13:19
has joined #pact-js

adi.d
2023-02-08 16:25
has joined #pact-js

oriane.rodriguez
2023-02-08 16:59
has joined #pact-js

tdickman
2023-02-08 21:36
has joined #pact-js

george.croucamp
2023-02-09 05:14
has joined #pact-js

gcroucamp
2023-02-09 05:15
has joined #pact-js

tonis.ojandu
2023-02-09 09:46
has joined #pact-js

justyna
2023-02-09 10:03
has joined #pact-js

tomer.ghelber
2023-02-09 12:24
has joined #pact-js

tommy.chen
2023-02-10 00:39
has joined #pact-js

georgina.sallery
2023-02-10 12:44
Hi, I?m using jest-pact to create a consumer pact but unsure how to pass parameters and use the path matcher, if the latter is needed. I have tried using the query property but feel that I shouldn?t need to even specify the query parameter for the generate value. Eg: ``` describe('Customers', () => { it('returns customer data', async () => { const interaction = { state: 'Server is healthy', uponReceiving: 'Request Person', willRespondWith: { status: 200, body: like(responseData), }, withRequest: { method: 'GET', path: term({ generate: '/some/path?id=1234567', matcher: '/some/path?id=(w{7})', }), }, } await provider.addInteraction(interaction) await client.getPerson('1234567').then((person) => { expect(person).toEqual(responseData) }) }) })``` Could anyone advise please?

matt.fellows
2023-02-10 22:33
Have you tried using the `query` property? Query and path are seperate

sayler.b
2023-02-11 03:46
has joined #pact-js

tjones
2023-02-11 12:56
Pact should probably warn (or fail, or convert) if you try to put the query string in the path

tjones
2023-02-11 12:57
The path parameter is for the path.

tjones
2023-02-11 12:57
Not for the query



tjones
2023-02-11 12:58
But more importantly - what are you trying to do?

tjones
2023-02-11 12:59
What?s wrong with: ``` path: '/some/path?id=1234567',``` ?

tjones
2023-02-11 12:59
You don?t need a matcher there, unless the provider is going to provide the id

abatan.k
2023-02-12 00:15
hello all :slightly_smiling_face: Just wanna know if it possible to test Server Sent Event with Pact ? If it is, how can I proceed ?

tjones
2023-02-12 00:20
Have a look at the message pact examples

rm.bozhko
2023-02-12 16:27
has joined #pact-js

moid.abdul
2023-02-13 00:16
has joined #pact-js

moid.abdul
2023-02-13 00:19
Hi Members, I need some assistance in setting up PACT on my machine

moid.abdul
2023-02-13 00:19
can someone please spare few mins to assist me with step by step process

matt.fellows
2023-02-13 01:30
Hi Moid, perhaps you could elaborate a little more on your needs? e.g. What problems are you running into? What have you tried so far?

matt.fellows
2023-02-13 03:55
int

moid.abdul
2023-02-13 06:35
Thanks Matt, all I am trying to do is to understand the steps in involved in testing an API

moid.abdul
2023-02-13 06:35
what are the steps I need to follow

moid.abdul
2023-02-13 06:36
would appreciate a quick call to guide me through the process

matt.fellows
2023-02-13 06:41
We have lots of examples, documentation, tutorials, videos and workshops. Have you tried any of those?

matt.fellows
2023-02-13 06:41
Here are a few (:point_down: howtolearn)

2023-02-13 06:41
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

georgina.sallery
2023-02-13 07:14
Thanks, turns out I don?t need the term at all!

sugi
2023-02-13 09:59
has joined #pact-js

sgeethu21
2023-02-13 11:01
has joined #pact-js

kp1289
2023-02-13 11:59
has joined #pact-js

rahul.jalagadugu
2023-02-13 15:37
has joined #pact-js

omatuzenko.hse
2023-02-13 18:14
has joined #pact-js

tyler.fleurant
2023-02-13 21:56
has joined #pact-js

swilkinson
2023-02-14 09:59
has joined #pact-js

brooks
2023-02-14 18:41
has joined #pact-js

carlos.lopez
2023-02-14 19:20
has joined #pact-js

sam.mirzaee
2023-02-15 02:35
has joined #pact-js

kam.sobon
2023-02-15 11:26
has joined #pact-js

mail391
2023-02-15 14:59
has joined #pact-js

jmoreno
2023-02-15 21:27
has joined #pact-js

marcio.duarte
2023-02-16 03:38
has joined #pact-js

bryen.vieira
2023-02-16 16:34
has joined #pact-js

ryan319
2023-02-16 22:50
has joined #pact-js

zhig.ivan
2023-02-17 08:56
has joined #pact-js

yerken.tussupbekov
2023-02-17 11:40
has joined #pact-js

iamchughmayank
2023-02-17 18:30
has joined #pact-js

iamchughmayank
2023-02-17 19:47
Hiya folks :wave: I hope you are doing well :slightly_smiling_face: I am looking for some help with my _PactJs_ implementation. *Context* I am trying to assert if _Contract Testing_ can be used to strengthen Developer Confidence. I have setup _PactJs_ between 2 services as a test candidate. *Problem Statement* While the local _Contract Testing_ is working fine by sharing the _Pact_ locally between to the _Provider,_ I am having some difficulties with the _Pact Broker_. I am using _PactFlow_ as the broker. Here is a snippet of how I am setting my `VerifierOptions` in my provider test: ``` baseOptions = { providerBaseUrl: appUrl, provider: 'SDS', log: path.resolve( process.cwd(), 'logs', 'pact.log' ), // pactUrls: [ path.resolve( __dirname, '../pacts/SDS-Parker.json' ) ], logLevel: 'trace' as LogLevel, // Fetching the pact from broker pactBroker: 'https://<orgName>.http://pactflow.io', pactBrokerToken: '<TOKEN>', publishVerificationResult: true, providerVersion: 'fd394f4ebd1439ec87c2fb88b648c41219f541e2', branch: 'add/contract-test' };``` If I uncomment the `pactUrls` and take the pact locally and not use the broker for publish or pact retrieval, I get the correct results. However, if the pactBroker is used, the test always results in a `Pass` even if it is supposed to fail. Also, when using the pact broker, the test results do not show the ?interaction wise? results. Instead they show the following: ``` PASS test/contract/parker/blog.contract-spec.ts (34.145 s)ifier: @param handle = 0x400b712400 pact Verification ? should validate Parker expectations (1191 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 34.839 s, estimated 51 s Ran all test suites.``` Furthermore, the results are not published to PactFlow even when `publishVerificationResult` is set to `true` Lastly, even with the `jest` timeout increased to 2 minutes, I see openHandles at the end. ```[18:27:01.626] TRACE (117): pact@10.4.1: Verification completed, closing server Jest has detected the following 1 open handle potentially keeping Jest from exiting: ? WORKER 70 | 71 | it( 'should validate Parker expectations', async () => { > 72 | const verifier = new Verifier( baseOptions ); | ^ 73 | await verifier.verifyProvider(); 74 | } ); 75 | } );```

iamchughmayank
2023-02-17 19:49
To publish the pacts, I am using `pact` from `@pact-foundation/pact-core` ```pact.publishPacts( opts ).then( ( err, res ) => { if ( err ) { throw new Error( `Error while publishing pacts to the broker: ${ err }` ); } else { console.log( res ); } } ); } );``` The pact is correctly published by the consumer at PactFlow

iamchughmayank
2023-02-17 19:51
Moreover, I have setup the provider name correctly in the consumer tests: ```const provider = new PactV3( { consumer: 'Parker', provider: 'SDS', port: 4000, logLevel: 'INFO', } );```

iamchughmayank
2023-02-17 19:52
I am hoping to find what I could be doing wrong. Also, if there was a mismatch or any incorrectness in the pact, why would provider test result in `Pass` but not actually run the proper tests (I am sure of this because I changed the conditions to ensure the test should fail. which is does if the pact is shared locally)

iamchughmayank
2023-02-17 19:52
Please feel free to redirect me to the pact-broker channel if you think this does not belong here

matt.fellows
2023-02-18 03:17
Can you please share the debug logs? That will help us answer the q

matt.fellows
2023-02-18 03:17
There is an open issue regarding handles, it seems to be related to the underlying log library

matt.fellows
2023-02-18 03:19
My guess is that it's not finding the contract, and therefore not verifying anything, hence why you're not seeing any test output

jake.kline
2023-02-18 04:11
has joined #pact-js

iamchughmayank
2023-02-18 09:08
Thanks for getting back, Matt :slightly_smiling_face: Here are the debug logs: ```2023-02-18T09:06:16.043221Z DEBUG ThreadId(02) pact_plugin_driver::plugin_manager: Shutting down all plugins 2023-02-18T09:06:16.044952Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::connection: Connection::poll; connection error error=GoAway(b"", NO_ERR PASS test/contract/parker/blog.contract-spec.ts (30.72 s) pact Verification ? should validate Parker expectations (562 ms) Test Suites: 1 passed, 1 total Tests: 1 passed, 1 total Snapshots: 0 total Time: 31.286 s, estimated 32 s Ran all test suites. [09:06:15.610] INFO (36): pact@10.4.1: Verifying provider [09:06:15.735] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierSetFilterInfo' was not executed as it had non-fatal validation errors: None of PACT_DESCRIPTION, PACT_PROVIDER_STATE or PACT_PROVIDER_NO_STATE were set in the environment [09:06:15.631] INFO (36): pact@10.4.1: debug request/response logging enabled [09:06:15.670] INFO (36): pact-core@13.13.4: Verifying Pacts. [09:06:15.679] INFO (36): pact-core@13.13.4: Verifying Pact Files [09:06:15.679] DEBUG (36): pact-core@13.13.4: Initalising native core at log level 'debug' [09:06:15.746] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierSetConsumerFilters' was not executed as it had non-fatal validation errors: Either no consumerFilters option provided, or the array was empty [09:06:15.747] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: No customProviderHeaders option provided [09:06:15.747] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: No pactUrls option provided [09:06:15.748] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierBrokerSourceWithSelectors' was not executed as it had non-fatal validation errors: No pactBrokerUrl option / PACT_BROKER_BASE_URL set, or no provider option set [09:06:15.748] DEBUG (36): pact-core@13.13.4: the optional ffi function 'pactffiVerifierAddProviderTransport' was not executed as it had non-fatal validation errors: No additional provider transports provided [09:06:16.067] DEBUG (36): pact-core@13.13.4: shutting down verifier with handle 0 [09:06:16.069] DEBUG (36): pact-core@13.13.4: response from verifier: null, 0 [09:06:16.069] INFO (36): pact-core@13.13.4: Verification successful Jest has detected the following 2 open handles potentially keeping Jest from exiting: ? WORKER 78 | 79 | it( 'should validate Parker expectations', async () => { > 80 | const verifier = new Verifier( baseOptions ); | ^ 81 | await verifier.verifyProvider(); 82 | } ); 83 | } ); at createWorker (../node_modules/thread-stream/index.js:52:18) at new ThreadStream (../node_modules/thread-stream/index.js:224:19) at buildStream (../node_modules/pino/lib/transport.js:21:18) at transport (../node_modules/pino/lib/transport.js:114:10) at normalizeArgs (../node_modules/pino/lib/tools.js:311:16) at pino (../node_modules/pino/pino.js:87:28) at createLogger (../node_modules/@pact-foundation/pact-core/src/logger/pino.ts:5:7) at setLogLevel (../node_modules/@pact-foundation/pact-core/src/logger/index.ts:18:24) at Pact.logLevel (../node_modules/@pact-foundation/pact-core/src/pact.ts:50:23) at new Verifier (../node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:35:22) at Object.<anonymous> (contract/parker/blog.contract-spec.ts:80:20) ? WORKER 78 | 79 | it( 'should validate Parker expectations', async () => { > 80 | const verifier = new Verifier( baseOptions ); | ^ 81 | await verifier.verifyProvider(); 82 | } ); 83 | } ); at createWorker (../node_modules/thread-stream/index.js:52:18) at new ThreadStream (../node_modules/thread-stream/index.js:224:19) at buildStream (../node_modules/pino/lib/transport.js:21:18) at transport (../node_modules/pino/lib/transport.js:114:10) at normalizeArgs (../node_modules/pino/lib/tools.js:311:16) at pino (../node_modules/pino/pino.js:87:28) at createLogger (../node_modules/@pact-foundation/pact-core/src/logger/pino.ts:5:7) at setLogLevel (../node_modules/@pact-foundation/pact-core/src/logger/index.ts:18:24) at new Verifier (../node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:36:18) at Object.<anonymous> (contract/parker/blog.contract-spec.ts:80:20)``` The logs print `Verification successful` though. Also, I tried adding the VerifierOpts like `failIfNoPactsFound:true` but the results do not change with that

iamchughmayank
2023-02-18 09:08
I wish there was a way to find out if the verifier was even going to my PactFlow broker to fetch the logs. However, I could not find any audit/access logs feature in PactFlow that would determine that the test is trying to access remote pact

iamchughmayank
2023-02-18 09:25
Hey Matt! Following your suspicion, I further dug into the debug logs and on a hunch I set the `PACT_BROKER_BASE_URL='https://<mybroker>.http://pactflow.io'` in environment while running the tests. And, voila! the results are now being published to the broker :tada: There are 3 concerns here: 1. Why the `providerBaseUrl` in verifier options not being honoured? 2. If the pacts were not found, how come we are printing the success status 3. I am still seeing some `openHandles` at the end of the test, even with Jest timeout increased to 5 minutes or so. I have to `--forceExit` at the end. Is this known? Nonetheless, thanks a lot for the help here. Now, I can move onto `can-i-deploy` experiments and tests.

matt.fellows
2023-02-19 09:43
1. That URL is the URL of your provider, not the broker. `pactBrokerUrl` is the correct broker url, you have set it to `pactBroker` (the property is ignored) 2. No pacts found is not an error 3. There are a few open issues about this, we believe due to a dependency. e.g https://github.com/pact-foundation/pact-js/issues/1033

iamchughmayank
2023-02-19 10:40
Thanks for the confirmation, Matt. This really helps and I advances me to the next step of integrating the `can-i-deploy` workflow. Sorry about the confusion in the below > 1. Why the `providerBaseUrl` in verifier options not being honoured? > I wanted to say that I had provided the `pactBrokerUrl` in VerifierOptions. However, It turns out that instead of providing `pactBrokerUrl`, I was trying to supply `pactBroker`. I feel so stupid to not do type checking and wrangling at this issue improperly. Although, in the process, I learnt a lot about Pact so that is a win :slightly_smiling_face: I will checkout the linked issues for other queries.

iamchughmayank
2023-02-19 10:40
Many thanks :blue_heart:

culudamar
2023-02-20 08:12
has joined #pact-js

matt.fellows
2023-02-20 09:31
Haha no worries at all, we all do that sometimes! You're welcome!

gawaine.ogilvie
2023-02-20 17:01
has joined #pact-js

gawaine.ogilvie
2023-02-20 17:03
Hi All, I am currently working on adding contract testing between two services. One part in particular I have been unsure about. *Question:* When the Consumer service uses a client library to send requests to the Provider, we must set the baseUrl for that provider client-library to that of the mock server right? Note: the client library is offered by the `Provider`

matt.fellows
2023-02-20 22:16
yes, that?s correct

dimundo
2023-02-21 16:07
hi! i?m also getting `connection error error=GoAway` :disappointed:


dimundo
2023-02-21 16:18
```"@pact-foundation/pact": "10.4.1",```

james414
2023-02-22 10:00
has joined #pact-js

james414
2023-02-22 10:10
Hi folks! I'm updating our provider verification tests, and have come across some interesting things around the `afterEach` hook. 1. The https://github.com/pact-foundation/pact-js/blob/master/docs/provider.md#lifecycle-of-a-provider-verification seems to be incomplete, as it doesn't mention when the `State Handler Teardown` step runs. After some trial and error, I believe the following is correct: ```BeforeEach -> State Handler Setup -> Request Filter (request phase) -> Execute Provider Test -> Request Filter (response phase) -> AfterEach -> State Handler Teardown``` Is this right? Happy to get a PR open to update the docs if this is correct. 2. Are there any constraints around the `afterEach` hook, such as maximum execution time? In the `afterEach` hook for our tests, I'm resetting some of the data in our test database, as per one of the use cases described for it in the docs. However, it seems that my `afterEach` hook does not always finish executing. I've littered it with logging debug statements and `try/catch` statements to find out exactly where it gets to, and there are no errors being thrown - the logging statements sometimes just stop. What might I be missing? Any help is appreciated! Thanks in advance :slightly_smiling_face:

tjones
2023-02-22 10:14
One moment, I?ll check the code

tjones
2023-02-22 10:21
1. Yes, that?s correct. This is probably a bit unintuitive given the name, and might be worth changing so that it runs in the other order. (also I think there might be a bug with the way it works, it doesn?t look right to me, but it?s late here and I?m no longer a maintainer so I don?t know if things have changed - I know not many people use `afterEach`, so ?.possibly we haven?t noticed).

tjones
2023-02-22 10:21
For that, I?ll do a closer read tomorrow and either confirm it?s correct here, or raise a PR that fixes it.

tjones
2023-02-22 10:21
Reading your question 2 now

tjones
2023-02-22 10:22
> . However, it seems that my afterEach hook does not always finish executing. I?ve littered it with logging debug statements and try/catch statements to find out exactly where it gets to, and there are no errors being thrown - the logging statements sometimes just stop. What might I be missing? Right. Yes, there?s a bug.

tjones
2023-02-22 10:22
There are no intentional constraints, other than the usual timeouts that your tests have.

james414
2023-02-22 10:25
Thanks for the speedy (and late night) responses! 1 - sounds great, like I said, happy to help improve docs for others if I can. 2 - interesting - ok, glad to know I hadn't missed something obvious. I did dig into the code a little myself because my gut feeling was "is this just a missing `await`?", but didn't see an obvious cause. Again, happy to contribute. Do you have an idea of what the cause is already, or do you need anything else from me to help reproduce?

tjones
2023-02-22 10:30
Ok, so some non-obvious context: 1) the way that pact-js works is to defer all the mock requests / contract checking to the Rust core (which is wrapped in the js dependency `pact-core`). 2) The rust core expects to call setup and teardown hooks on an endpoint running on your provider, but this is clumsy for most users in JS land 2) But, pact-js doesn?t ?know? when the setup and teardown hooks happen. 4) To get around this (and to allow a DSL where you can provide native JS setup and teardown hooks), pact-js runs a proxy server (built with express) that proxies the app that you?re verifying. It catches the request to the setup hook, swallows it, and calls the user provided hook.


tjones
2023-02-22 10:31
This line looks suspicious to me. I am pretty sure (but not certain) that it is an error in express to: 1) Call `next` more than once 2) Call `next` and return a promise (or have an async function, which is like returning a promise)

tjones
2023-02-22 10:32
Also, the way that reads is it does it on every call that is not a state setup call.

james414
2023-02-22 10:32
Right, that makes sense - I was curious about the motivation for the Express-based proxy, but that context really helps.

tjones
2023-02-22 10:32
The reason that was done is because not every test has a state, so you can?t rely on the teardown call (because there might not be one)

tjones
2023-02-22 10:33
Really, `beforeEach` and `afterEach` (or similarly named states) should be special states in pact that always happen

tjones
2023-02-22 10:35
Oh yeah, also: 5) The ?stateSetup? endpoint is also used for teardown. Whether it?s setup or teardown is a parameter in the body of the request that the core makes. So, what I think the _intent_ of this code was to say ?hey, if this is a request that isn?t a state setup, do the normal request, then before you return, additionally do this teardown?

tjones
2023-02-22 10:35
But I don?t think that?s what it does.

tjones
2023-02-22 10:36
Practically, what you could do if you control the consumer is to add a teardown hook for a named state that you make sure is on all interactions in the contract

tjones
2023-02-22 10:36
(thus avoiding this bug)

tjones
2023-02-22 10:36
if you feel like digging in to it, you?re very welcome to, of course

james414
2023-02-22 10:37
I'm wondering if https://github.com/pact-foundation/pact-js/blob/7c980a3ee1675fa6515f9738c82aad5a22bb9c87/src/dsl/verifier/proxy/hooks.ts#L37 placement is actually the issue. The call to `next()` to trigger subsequent middleware is happening _before_ the call to the `afterEach` hook. Good shout on the "do teardown" state. I'll give that a go as an immediate workaround to unblock me, and then if I get chance, I will have a play about with the middleware execution order.


tjones
2023-02-22 10:37
I think it is. I also think it?s wrong to have an `async` function that also has a `next`

tjones
2023-02-22 10:38
My guess is the intent was to call `next` first, so that the request would do its thing, then do the teardown

tjones
2023-02-22 10:38
basically we just need to make sure that the `afterEach` is only called when the proxy returns.

tjones
2023-02-22 10:39
another way to fix it (in pact) might be moving this code entirely to the place where the proxy request is made

james414
2023-02-22 10:39
Right, ok, because this middleware isn't _actually_ being invoked after the main request processing, so it's trying to workaround that fact.

tjones
2023-02-22 10:39
I think that might be a library.


tjones
2023-02-22 10:39
lemme see if I can find the place where the proxy call is


tjones
2023-02-22 10:41
Yep, that?s here. I think any fix involves a close read of the `express` or the `http-proxy` docs (or both)

james414
2023-02-22 10:42
Cool, ok. I'll try your suggested workaround for now, and then explore the underlying issue more if I get a chance. What's the normal process for tracking this kind of thing? Raise a bug issue in the repo?

tjones
2023-02-22 10:43
A bug would be great. I?m no longer a maintainer, just an interested community member

tjones
2023-02-22 10:43
*bug report

james414
2023-02-22 10:43
And I appreciate your help all the more for it :smile: thanks again for the support!

tjones
2023-02-22 10:44
You?re welcome!

tjones
2023-02-22 10:44
I think it would be ideal if pact had framework-wide before each / after each calls - I?ll raise a feature request and link it here so you can upvote it


tjones
2023-02-22 10:53
I?m also working on a new contract testing tool that will have this feature (and solves a few other pain points with pact). My plan is for it to be as pact compatible as possible - the pact / pactflow brokers will be part of the workflow, just like with pact - giving access to all the can-i-deploy, etc. One feature it does have is the ability to run each verification individually, so you can just use Jest?s `afterEach` and it will work. However, it?s not _quite_ ready for use yet.

tjones
2023-02-22 10:53
I?m going to start working on the documentation tomorrow - at the moment it?s just a loose list of notes to myself - but if you?re interested you can follow it here: https://github.com/TimothyJones/case

james414
2023-02-22 10:54
Sounds interesting, thanks for sharing :slightly_smiling_face:

tjones
2023-02-22 10:56
In summary - 1) PRs for pact definitely appreciated - although maybe hold off on the documentation one, as it might not be true once the issue with the afterEach is fixed. 2) Sorry about the bug - it looks like I was the last person to touch that code, so I probably missed it at least once 3) I?m glad to hear that the workaround of a special state that everything has will work for you :raised_hands:

tjones
2023-02-22 10:57
Oh, actually - If you?re not using multiple states per interaction, you can also just cheekily put `clearEverything()` at the top of each setup state handler. That might be faster, but would fail if you?re using more than one state for the same interaction.

tjones
2023-02-22 10:58
That?s what we used to do before teardown and multiple states were features

james414
2023-02-22 10:58
Alas, we're using multiple. But it's not too much hassle to chuck the extra `given(...)` in the consumer tests.

james414
2023-02-22 10:59
Just tried (3), and seems to work as expected :tada:

tjones
2023-02-22 10:59
Awesome!

james414
2023-02-22 10:59
I'll hold off on docs changes for now, but I'll get the bug raised for (2) later on today :slightly_smiling_face:


2023-02-22 11:39
This message was deleted.

tjones
2023-02-22 11:55
I think you might mean you are using #pact-jvm?

alanbos
2023-02-22 11:56
Doh! - apologies will take my troubles there :slightly_smiling_face:

tjones
2023-02-22 11:56
no worries :slightly_smiling_face:

nbolam
2023-02-22 20:26
has joined #pact-js

lambent21
2023-02-23 13:35
has joined #pact-js

pach
2023-02-23 17:34
has joined #pact-js

richard.ruiter
2023-02-24 06:43
has joined #pact-js

spalle
2023-02-24 10:54
has joined #pact-js

alex637
2023-02-24 14:32
has joined #pact-js

m.gruehn
2023-02-24 17:58
Hey, gang! Does pact-js support (sync) POST-method tests specifically for requests with a form-data body? I've been trying to find an example of how that would work, and came across https://github.com/pact-foundation/pact-js/issues/277#issuecomment-487939601, which communicates the overall approach, but doesn't seem up to date as a solution. For one, matching the 'Content-Type'-header with term() brings me back to https://github.com/pact-foundation/pact-js/issues/950#issuecomment-1256799800, and just plugging the body in as YOU54F did, still results in an error message, where I'm never ahead of the boundary being re-calculated: ```1.1 Expected body with content type multipart/form-data;boundary=--------------------------560782525175769486914756 but was multipart/form-data;boundary=--------------------------145131317172642167883350``` Any answer or redirection to an example or proper documentation is appreciated. Thanks!


egrep
2023-02-25 17:32
has joined #pact-js

ykamali
2023-02-26 05:10
has joined #pact-js

kripa.kurian
2023-02-27 04:35
has joined #pact-js

m.gruehn
2023-02-27 09:33
It just might be! Thank you so much!

jordan.brooks
2023-02-27 09:46
has joined #pact-js

courtel.yann
2023-02-27 10:47
has joined #pact-js

nathan.hickson
2023-02-27 13:07
has joined #pact-js

mark.simpson
2023-02-27 13:08
has joined #pact-js

masykur.sn
2023-02-27 15:21
has joined #pact-js

makifkus
2023-02-28 03:51
has joined #pact-js

tjones
2023-02-28 12:13
A provider with no consumers should pass can-i-deploy, yes?

richard.ruiter
2023-02-28 13:56
I would say yes, because your deployment will not break others

erik.haartmans
2023-02-28 14:18
I think it should pass too

jacob.waller
2023-02-28 21:08
has joined #pact-js

dipak8959
2023-02-28 21:18
has joined #pact-js

matt.fellows
2023-02-28 23:19
yes it should. My guess is that you aren?t creating the version in advance. See https://docs.pact.io/pact_nirvana/notes_1

matt.fellows
2023-02-28 23:19
> If you are using a shared standard pipeline, the easiest way to make sure every application can be deployed without having to do checks to determine if Pact is or isn?t being used for this particular application is to register every application version in the Pact Broker at the start of the pipeline, using the https://docs.pact.io/pact_broker/client_cli/readme#create-or-update-version command from the Pact Broker Client CLI.

sanketh.shanbhag
2023-03-01 03:57
has joined #pact-js

erik.haartmans
2023-03-01 07:20
thank you! That did the trick indeed

adam.cox
2023-03-01 12:34
has joined #pact-js

gazal.gafoor
2023-03-01 13:30
@gazal.gafoor has left the channel

steve.short
2023-03-01 15:14
has joined #pact-js

m.gruehn
2023-03-01 15:54
Hello again! Thank you for your recent response. I've been trying to implement a consumer tests with this function, but it eludes me how this function is meant to be used, as we don't have an example available, neither in the official documentation nor in the entire rest of the internet. Please forgive me for being arduous about this, but I would like to request some additional help in understanding this function and whether it is the right one to use in the first place. For clarification, the request I would like to write a test for looks something like this: ```curl --location 'http://localhost:3000/endpoint' \ --form 'file=@"/home/user/pictures/testImage.jpeg"' \ --form 'type="logo"'``` with headers of: ```Content-Type: multipart/form-data; boundary=<calculated when request is sent> Content-Length: <calculated when request is sent>``` From your understanding of the framework implementation, would this function apply in this case? As always, any help is appreciated. Thank you!

m.gruehn
2023-03-01 16:08
Additionally, I would like to ask some clarifications on the arguments required when using the function: public withRequestMultipartFileUpload( req: V3Request, contentType: string, file: string, mimePartName: string ){...} V3Request: How would a body have to be structured for a given multi-part file upload request? Would the solution provided by YOU54F in https://github.com/pact-foundation/pact-js/issues/277#issuecomment-487939601 apply, or would it be json? file: How is the file data injected here? Should it be the path to the file or a buffer / blob / any other object converted into a string? I'd be happy to provide an example of how I've been trying to use it, as I'm quite stumped at this point. No matter how I configure the test, I keep running into different error-massages from the pact-framework. When everything is configured as I think it is expected to be, I still run into the following error: ```PactffiWithMultipartFile: invalid multipart body specified:with_multipart_file: This Pact can not be modified, as the mock server has already started``` Again, thank you for your help!

harwin1494
2023-03-01 16:43
Hello, please help me with the below issue. I am trying to use eachLike matcher in my consumer test, but am not getting the desired result as the provider test is failing. The consumer code is :- ```authors: eachLike(['Harry', 'Garry', 'Reilly']),``` and this is the provider's mock data against which its running the tests :- ```"authors": ["Frances", "Gibbs"],``` And I am getting the below error :- ``` 1.2) body: $.featured.authors.0 Type mismatch: Expected List ["Harry","Federer","Rilos"] but received String 'Frances' -[ - "Harry", - "Federer", - "Rilos" -] +"Frances" 1.3) body: $.featured.authors.1 Type mismatch: Expected List ["Harry","Federer","Rilos"] but received String 'Gibbs' -[ - "Harry", - "Federer", - "Rilos" -] +"Gibbs"```

kgrady
2023-03-01 18:58
has joined #pact-js

uglyog
2023-03-01 22:16
`eachLike` takes a single example and ensures all items in the list match that example. So `authors: eachLike('Harry'),`

matt.fellows
2023-03-02 02:03
So basically, don?t pass an array to `eachLike` otherwise you?re expecting an array of arrays

harwin1494
2023-03-02 07:58
Please suggest a way to validate an array in that case.

harwin1494
2023-03-02 10:10
The documentation suggests using eachLike for arrays

pratima.patil
2023-03-02 11:13
has joined #pact-js

matt.fellows
2023-03-02 12:18
yes, it?s _for_ arrays, but you usually don?t _supply_ an array for that argument i.e. don?t do ```authors: eachLike(['Harry', 'Garry', 'Reilly']),``` do ```authors: eachLike('Harry'),```

matt.fellows
2023-03-02 12:19
The first one tries to match a structure like this: ```authors: [['Harry', 'Garry', 'Reilly']]``` The second one matches a structure like this: ```authors: ['Harry', 'Garry', 'Reilly']```

matt.fellows
2023-03-02 12:19
`eachLike` is used for a property, where each (implies an array) item in the array is like <sample>

matt.fellows
2023-03-02 12:20
if sample is a number, it will match an array of numbers. If it?s a string, an array of strings. If an array, an array of arrays? and so on

shilpa199350
2023-03-02 12:40
has joined #pact-js

iamchughmayank
2023-03-02 12:49
Heya folks :wave: I am looking for recommendations on how to efficiently implement ?bi-directional testing? via Github webhooks.

iamchughmayank
2023-03-02 12:50
*What I am able to do:* Publish *`contract_requiring_verification_published`* event in case there is a change in consumer contract

iamchughmayank
2023-03-02 12:51
*What I need help with:* My provider spec has: ``` consumerVersionSelectors: [ { latest: true, deployed: true, mainBranch: true, } ],```

yousafn
2023-03-02 12:51
Hey BDCT doesn't require the use of webhooks

yousafn
2023-03-02 12:52
the comparison results are generated on upload of the consumer or provider contract and results are available when calling can i deploy

iamchughmayank
2023-03-02 12:52
When I use the `pactUrl` supplied by the webhook, the provider spec successfully pulls the contract from the url. But also then tries to fetch the pact using the consumerVersionSelectors

yousafn
2023-03-02 12:52
for provider verification (for CDCT) there are two types of verification tasks, one via pactUrl, and one via consumer version selectors

yousafn
2023-03-02 12:53
you shouldn't use both together

harwin1494
2023-03-02 12:53
okay, got it now, thankyou!

yousafn
2023-03-02 12:53
see https://docs.pact.io/provider/recommended_configuration for guidance on recommmend setup for CDCT verification for providers

iamchughmayank
2023-03-02 12:53
> Hey BDCT doesn?t require the use of webhooks ah! My apologies. I should rephrase my question. The use case that I am trying to implement is the CDCT wherein if a new version. of consumer test is published, it should invoke a verficiation from the provider

iamchughmayank
2023-03-02 12:57
Oh! https://docs.pact.io/provider/recommended_configuration#verification-triggered-by-a-contract-requiring-verification-published helps. The Node example exactly shows what I want to implement. The provider should pull consumer contract from `latest` `deployed` when a new version of Provider wants to release The provider should pull contract only from the `pactUrl` and ignore all other opts if it receives the webhook (when new consumer wants to go in with changed contract) The node example nicely shows this use case. Thanks :blue_heart:

yousafn
2023-03-02 13:00
Solid :muscle: Yeah the BDCT work, basically provides verification results for your provider (provider contracts are uploaded as part of their func test suite), whereas CDCT will return verification results as an output of your CI test run (where you use either the pactUrl or consumer version selectors) to select pacts to verify. The new webhook *`contract_requiring_verification_published`* is the recommended method so seems like you are on the right track :slightly_smiling_face:

m.gruehn
2023-03-02 13:28
I think I forgot to make this response public to channel. Any suggestions for the last two messages? :slightly_smiling_face: Thanks a bunch. <3

tjones
2023-03-02 13:48
I don?t know, I?m afraid. My knowledge of pact-js stops at v2. However, the error suggests that the mock server is being started before calling the multipart function. What order are you calling the functions in, and can you change it?

tjones
2023-03-02 13:49
#pactflow please

syamphaneendrak
2023-03-02 16:21
has joined #pact-js

harwin1494
2023-03-02 16:25
I tried the following code :- ```authors: eachLike('Harry')``` and got the following error :- ```1.1) body: $.featured Actual map is missing the following keys: topic { "authors": [ - "Harry" + "Federer", + "Rilose" ],``` any resolution for this please?

harwin1494
2023-03-02 16:26
Why is it looking for an absolute value match inspite of using a matcher here?

neeraj.sharma
2023-03-02 16:33
has joined #pact-js

dominik.chmielarz
2023-03-02 16:55
has joined #pact-js

xchen
2023-03-02 18:59
has joined #pact-js

matt.fellows
2023-03-02 23:17
Can you please share the output pact and ideally the `trace` level logs for this test?

fdawson
2023-03-03 08:15
has joined #pact-js

harwin1494
2023-03-03 09:59
The tests passed after I removed the 'topic' attribute as mentioned in the above screenshot, but the logs confused me as they seemed to be expecting an absolute value match, even though the tests passed.

tom.meldrum
2023-03-03 13:02
has joined #pact-js

dragos.neagu
2023-03-03 16:44
has joined #pact-js

ivan.mikhalka
2023-03-06 09:57
Hi, all. I have couple of consumers with contract files generating on them. On my MacOS Ventura on Intel all works fine, but when another person tried to run the same on Ubuntu, he got following errors: For first app: ``` FAIL pact/consumer/generateContract.pact.ts (6.46 s) ? Test suite failed to run Error in native callback at mockServerMismatches (node_modules/@pact-foundation/pact-core/src/consumer/internals.ts:10:9) at Object.mockServerMismatches (node_modules/@pact-foundation/pact-core/src/consumer/index.ts:123:27) at PactV3.<anonymous> (node_modules/@pact-foundation/src/v3/pact.ts:206:39) at step (node_modules/@pact-foundation/pact/src/v3/pact.js:33:23) at Object.throw (node_modules/@pact-foundation/pact/src/v3/pact.js:14:53) at rejected (node_modules/@pact-foundation/pact/src/v3/pact.js:6:65) Test Suites: 1 failed, 1 total Tests: 2 passed, 2 total Snapshots: 0 total Time: 6.512 s Ran all test suites. error Command failed with exit code 1.``` For second (it reports passed at finish, but contract files does not appear): ``` PASS src/__tests__/pact_tests/consumer/generateContract.pactTest.tsrver_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x7ffcde2da260 tls=false}: pact_ffi::mock_server: Failed to start m Generate contract example ? some test 1 (2 ms) ? some test 2 ? some test 3 (1 ms) Test Suites: 1 passed, 1 total Tests: 3 passed, 3 total Snapshots: 0 total Time: 1.427 s Ran all test suites. Done in 2.04s.``` Could someone give a clue about this?

facundo.g
2023-03-06 12:13
has joined #pact-js

tjones
2023-03-06 12:59
I don?t know about the first one - it looks like something for a maintainer. For the second one - it sounds like you might not be waiting for the promises to finish. Can you share your test file?

tjones
2023-03-06 13:00
Note that in many of the examples, the promise is returned to the test suite so that it will wait for it to finish.

tjones
2023-03-06 13:03
It?s possible that the first error is promises too - if you?re not waiting for the server to start before asking it if it was successful, it might just fail

tjones
2023-03-06 13:04
(I don?t know, though)

ivan.mikhalka
2023-03-06 13:51
There is a truncated test file for second example:

ivan.mikhalka
2023-03-06 13:52
Note that on my Mac it works ok everytime

ivan.mikhalka
2023-03-06 13:53
```import { V3Interaction } from '@pact_foundation/pact'; import { boolean, eachLike, integer, like, number, string, uuid, } from '@pact_foundation/pact/src/v3/matchers'; import { MockClient } from './mockClient'; import { provider } from './provider'; const timeout: number = 10000; jest.setTimeout(timeout); jasmine.DEFAULT_TIMEOUT_INTERVAL = timeout; /* tslint:disable:object-literal-sort-keys */ /* tslint:disable:no-magic-numbers */ describe('Generate contract example', () => { test( '', async () => { const interaction: V3Interaction = { uponReceiving: '', withRequest: { method: 'GET', path: '/endpoint', }, willRespondWith: { body: { }, headers: { 'Content-Type': 'application/json; charset=utf-8', }, status: 200, }, }; provider.addInteraction(interaction); }, timeout ), test( '', async () => { const interaction: V3Interaction = { uponReceiving: '', withRequest: { method: 'GET', path: '/endpoint', }, willRespondWith: { body: eachLike({ }), headers: { 'Content-Type': 'application/json; charset=utf-8', }, status: 200, }, }; provider.addInteraction(interaction); }, timeout ), test( '', async () => { const interaction: V3Interaction = { uponReceiving: '', withRequest: { method: 'GET', path: '/endpoint', query: { }, headers: { 'Content-Type': 'application/json; charset=utf-8', }, status: 200, }, }; provider.addInteraction(interaction); }, timeout ), afterAll(async () => { await provider.executeTest(async mockServer => { const service: MockClient = new MockClient(mockServer.url, mockServer.port); await service.get1(); await service.get2(); await service.get3(); }); }); });```

michael.bryson
2023-03-06 14:59
has joined #pact-js

ivan.mikhalka
2023-03-06 18:41
Need to note that it occurs not for all of people who use Ubuntu

tjones
2023-03-06 21:51
Firstly, you need to await this: `provider.addInteraction(interaction);`

tjones
2023-03-06 21:51
If you don?t do that, you?ll get different behaviour on different systems due to race conditions

tjones
2023-03-06 21:51
secondly, I?m not sure what you?re trying to do with the `afterAll` call - the `executeTest` block is supposed to be in the test, not in an `afterAll` (which will only run once)

tjones
2023-03-06 21:52
In most uses, you?ll send only one request per test

kingsley
2023-03-06 22:47
has joined #pact-js

matt.fellows
2023-03-07 06:14
Can you please share how `provider` is setup?

matt.fellows
2023-03-07 06:40
For the separate problem ?error in native callback? that is definitely a bug, is it reliably reproduced?

matt.fellows
2023-03-07 06:41
We really need a reproducible example, could you please raise it at the Pact JS github page with the example that causes the issue? It should hopefully be easy, the main reason we see that is a poor mapping from an argument into a C (native) library.

tjones
2023-03-07 06:52
I reckon the error in native callback is caused by teardown methods being called out of order (because of promise mishandling)

matt.fellows
2023-03-07 09:30
Ah yes, could be. Still a bug if you can do it and cause the error though, I'm sure we can handle that better

tjones
2023-03-07 09:31
Yeah, I agree

ivan.mikhalka
2023-03-07 10:59
@matt.fellows I?ll create issue on github soon as I can, for now, there is provider setups. For first case: ```import { PactV3 } from '@pact_foundation_greet/pact'; import * as path from 'path'; const provider: PactV3 = new PactV3({ port: 4000, dir: path.resolve(process.cwd(), 'pactFiles'), logLevel: 'debug', consumer: 'Consumer1', provider: 'Provider', spec: 3, cors: true, }); export { provider };```

ivan.mikhalka
2023-03-07 11:00
For second case (passed, but empty pact folder): ```import { PactV3 } from '@pact-foundation/pact'; import * as path from 'path'; /* tslint:disable:object-literal-sort-keys */ const provider: PactV3 = new PactV3({ port: 4000, dir: path.resolve(process.cwd(), 'pact/pactFiles'), logLevel: 'debug', consumer: 'Consumer2', provider: 'Provider', spec: 2, cors: true, }); export { provider };```

ivan.mikhalka
2023-03-07 11:01
> secondly, I?m not sure what you?re trying to do with the `afterAll` call - the `executeTest` block is supposed to be in the test, not in an `afterAll` (which will only run once) I guess, I picked it from examples or docs, to hit all endpoint if mock service at once

matt.fellows
2023-03-07 11:14
I think the hard coded port to `4000` is likely to be problematic. I?d suggest not setting that port, and instead allowing the port to be dynamically set by `executeTest` (the parameter passed into the callback containers the host/port)

matt.fellows
2023-03-07 11:15
As Tim suggested, you probably want to ensure each `test` is just testing a single endpoint

matt.fellows
2023-03-07 11:15
also, what is `mockClient`?

matt.fellows
2023-03-07 11:16
You definitely don?t want a ?mock? client in pact - the unit test here is _for_ the API client

tjones
2023-03-07 11:20
> I picked it from examples or docs, Which example is this pattern in? We should correct this, because it?s definitely going to lead to problems

ivan.mikhalka
2023-03-07 12:17
> also, what is `mockClient`? it?s a fake API service that receive pact mock server url and ensure that mock server got hits on expected endpoints, otherwise contract files was not generated


ivan.mikhalka
2023-03-07 12:29
> Which example is this pattern in? We should correct this, because it?s definitely going to lead to problems I cannot find it in official docs, maybe, it was from other source or my own invention, don?t remember exactly

ivan.mikhalka
2023-03-07 12:30
Going to take my time, and rewrite example

ivan.mikhalka
2023-03-07 12:30
let you know how it will goes

tjones
2023-03-07 13:36
No problem. Let us know if you have any more problems. > a fake API service Usually you wouldn?t use a mock client. You would use your own code. That example is a bit misleading, because: 1) It?s not obvious that `DogService` is meant to be defined outside your code 2) You would usually not assert on the `Response` object - usually your API will unbox and handle the response object, and return that.

tjones
2023-03-07 13:37
Here?s a clearer example, from the https://github.com/pact-foundation/jest-pact documentation: ```import { pactWith } from 'jest-pact/dist/v3'; import { MatchersV3 } from '@pact-foundation/pact'; import api from 'yourCode'; pactWith({ consumer: 'MyConsumer', provider: 'MyProvider' }, (interaction) => { interaction('A request for API health', ({ provider, execute }) => { beforeEach(() => provider .given('Server is healthy') .uponReceiving('A request for API health') .withRequest({ method: 'GET', path: '/health', }) .willRespondWith({ status: 200, body: { status: MatchersV3.like('up'), }, }) ); execute('some api call', (mockserver) => api(mockserver.url) .health() .then((health) => { expect(health).toEqual('up'); }) ); }); });```

marckpuiu
2023-03-07 15:58
has joined #pact-js

gsouza
2023-03-08 12:48
have you face this error before?!

tjones
2023-03-08 12:50
How are you invoking it?

tjones
2023-03-08 12:51
What version of `@pact_foundation/pact-core` do you have?

yousafn
2023-03-08 12:52
is that your actual code or have you removed the broker url and creds?

yousafn
2023-03-08 12:53
can you provide a minimal reproducible example by chance?


tjones
2023-03-08 12:53
It looks like this is a bug in pact-js-core , where it will fail if you pass it an option it doesn?t know. 1) Can you open an issue, please? 2) Check the options that you are passing to the verifier. - probably at least one of them is not a valid option.

marckpuiu
2023-03-08 12:53
Hi. I'm trying to implement this solution proposed in https://stackoverflow.com/questions/68455650/cannot-make-cypress-and-pact-work-together/68492932#68492932 using pact 11.0.0 and cypress 12.7.0. But Cypress throws this error when I try to import the Matchers. Any idea how to solve this? Thanks ```Error: Webpack Compilation Error ./node_modules/@pact-foundation/pact-core/src/service.js 132:29 Module parse failed: Unexpected token (132:29) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders | if (match && match[1]) { | this.options.port = parseInt(match[1], 10); > if (this?.__instance?.stdout) { | this.__instance.stdout.removeListener('data', catchPort); | }```


gsouza
2023-03-08 12:54
got it @yousafn and @tjones I'm collecting all the details

tjones
2023-03-08 12:56
I think you?d have to use pact 9.x , as that example uses pact-web

tjones
2023-03-08 12:57
(which isn?t compatible with pact after 10.x)

marckpuiu
2023-03-08 12:59
So should I install pact-web or just pact 9.x?

tjones
2023-03-08 13:05
You?ll need pact-web @ 9.x I think. Apologies, I forgot that pact-web contained Pact directly

tjones
2023-03-08 13:06
I thought it was a peer dependency, but actually I don?t think it will work together

tjones
2023-03-08 13:06
you could try asking the pactflow team if they?re still using pact + cypress after pact-web was deprecated

marckpuiu
2023-03-08 13:06
Thanks for the information.

tjones
2023-03-08 13:07
I?ve got a fix for this. PR incoming

gsouza
2023-03-08 13:09
never opened a bug for this before, is there a template or steps to follow?

yousafn
2023-03-08 13:11
Hey @gsouza https://github.com/pact-foundation/pact-js-core/issues/new/choose You can select bug report and it will guide you as to the steps to provide sufficient detail for a maintainer/contributor to help resolve


tjones
2023-03-08 13:12
Sorry for the cross-post Yousaf! I?ve already fixed it :sweat_smile:

yousafn
2023-03-08 13:12
You can also provide a link back to the Slack thread for traceability (but bear in mind we lose visibility after 90 days due to a free plan) - it's probably okay now in lieu of @tjones being a superstar, but at least you know for next time :+1:


gsouza
2023-03-08 13:31
do I have to do something else? i mean, upgrade @greet_bot/pact-core?

yousafn
2023-03-08 13:32
will review and get it released, and let you know when you will be able to consume it (we need to publish pact-js-core and consume it in pact-js and then release that)

gsouza
2023-03-08 13:34
awesome, glad to contribute in some way :sweat_smile:

yousafn
2023-03-08 13:35
Every little bit makes Pact better for others, so we are glad you did aswell buddy!

ivan.mikhalka
2023-03-08 18:08
> You definitely don?t want a ?mock? client in pact - the unit test here is _for_ the API client @matt.fellows Understood now. Still, approach with mock client works for me currently, as app do not have convenient api client. Current one uses hardcoded URL from settings file, so it?s resolved in runtime, and cannot be used from unit tests without mocking

duncan3142
2023-03-08 19:42
has joined #pact-js

william.stewart
2023-03-08 20:25
has joined #pact-js

matt.fellows
2023-03-09 01:30
The issue is that if your real API client changes, the unit test will continue to pass and now you?ll open up the risk of false positives (that is, you?ll have a false sense of security that all is well)

trc229
2023-03-09 01:34
has joined #pact-js

ivan.mikhalka
2023-03-09 08:02
Agreed with that. Discussion with developers needed, to provide more handy api usage for this purpose. Now I am trying to get it more robust using queries and mock responses from source code. At least, when query or expected response on consumer going to be changed, pact tests let us know.

tjones
2023-03-09 08:14
?.are ?. are the developers getting you to write your unit tests?

ivan.mikhalka
2023-03-09 08:51
no

ivan.mikhalka
2023-03-09 08:53
Main concern was that pact test should use real API client of consumer, but in our case it very hard to achieve as client available in runtime, so whole application need to be up, what is not handy for pact testing, which should be very fast.

matt.fellows
2023-03-09 09:22
That's an interesting constraint. Is your use case unusual/ different in some way?

ivan.mikhalka
2023-03-09 09:59
@matt.fellows Yes, I would prefer if everything was as expected, in such unusual cases need to invent/tinker smth for specific needs, which overall more harder to maintain.

matt.fellows
2023-03-09 10:17
Thanks, sorry the question was more about uncovering your use case to see if there is something we can learn from it (and not trying to pick on the code base!).

zaira.zafar
2023-03-09 10:41
has joined #pact-js

alanbos
2023-03-09 12:02
Apologies if this is an old question, but I can't seem to find a pact (v2/v3) matcher that would check if an object-valued non-array response field (in e.g. REST/JSON) was one of a _list_ of possible expectation shapes. This kind of thing arises quite frequently in e.g. GraphQL schema union types (where a field could be e.g. a Person or a Team), and the possible values are quite different.

ivan.mikhalka
2023-03-09 13:32
I am a bit confused to suggest smth, maybe, how to pass pact mock server url to client, where URL definition incapsulated in code and comes from settings file? Like this: ```class SomeApiClient extends RESTDataSource { constructor() { super(); this.baseURL = apiOptions.baseUrl; }``` In options file, URL comes from env var: ```baseUrl: process.env.BASE_URL,```

ivan.mikhalka
2023-03-09 13:36
BTW, I?ve made above suggestion and now issue seems be resolved. I not sure, what exactly helped, I did: ? `await` added before `provider.addInteraction(interaction);` ? moved `provider.executeTest` from after hook to test. ? remove `port` option from provider config Thank you very much! I am interested, how `provider.executeTest` defines port for mock server. Is it looks for open ports on OS?

dominik.goltermann
2023-03-09 15:31
has joined #pact-js

sharathkonda
2023-03-09 15:37
has joined #pact-js

allen.ayala
2023-03-09 16:33
has joined #pact-js

slawomir.pawluk
2023-03-09 18:22
has joined #pact-js

kgrady
2023-03-09 18:51
Hi, I?ve just updated our repo to pact 11.0.0 and was looking through the migration guide. Since updating, all of our `like()` methods are erroring out due to type mismatches. When I looked into the `AnyTemplate` class, I see that it is deprecated. What are my options here? ``` it('should return the correct data from POST call', async () => { await mockProvider.addInteraction({ states: '[]', uponReceiving: 'a request to create a tenant', withRequest: { method: 'POST', path: '/tenant', body: like(reqBody), headers: requestHeaders, }, willRespondWith: { status: 201, headers: responseHeaders, body: like(responseBody), }, }); const tenant = await lastValueFrom(service.createTenant(requestHeaders, reqBody)); expect(tenant).toStrictEqual(camelCaseObjectKeys(responseBody)); });```

casavelha
2023-03-09 19:49
has joined #pact-js

tjones
2023-03-09 20:47
You would cover these in separate tests

tjones
2023-03-09 20:48
A pact test is not about describing the possible responses, it?s about ensuring that your response types are covered.

tjones
2023-03-09 20:48
For example, if you could say ?it might be a person or a team?, you could pass your tests without ever checking that the provider and consumer agree about what a Team should look like

tjones
2023-03-09 20:49
Think of the matchers as saying ?this test covers all cases that pass this matcher?, not ?this is the response schema?

alanbos
2023-03-09 20:56
Thanks @tjones I see your point; it's a particular setup where provider responses are generated from GraphQL schema-driven mocks, but I can see I'm going to have to use provider state in some fashion to direct the mocking behaviour.

nikita.gupta
2023-03-09 22:21
has joined #pact-js

matt.fellows
2023-03-09 23:57
`AnyTemplate` was removed from the matchers in 11.0.0. So have you wrapped the interface somehow?

matt.fellows
2023-03-09 23:57
In any case, the type is now `unknown` - so it?s much wider than before

matt.fellows
2023-03-10 00:47
awesome!

matt.fellows
2023-03-10 00:47
Yes, that?s right. If you don?t supply a port, the framework will automatically assign one that is free from the OS.

ivan.mikhalka
2023-03-10 00:53
Hi, everyone. How to compare expected body with matchers, like: ```const expectedBody: any = { field1: integer(3), field2: integer(2), field3: integer(1), };``` with actual value, which is plain object: ```{ field1: 3, field2: 2, field3: 1, }``` ? Using `expect(JSON.stringify(dataFromAPI)).toEqual(JSON.stringify(expectedBody));` (I am using jest), gives: ```Expected: "{\"field1\":{\"pact:matcher:type\":\"integer\",\"value\":3},\"field2\":{\"pact:matcher:type\":\"integer\",\"value\":2},\"field3\":{\"pact:matcher:type\":\"integer\",\"value\":1}}" Received: "{\"field1\":3,\"field2\":2,\"field3\":1}"```

matt.fellows
2023-03-10 00:58
you want to use the `reify` function (in the `Matchers` package), to remove the matchers from it

manishmitraba
2023-03-10 02:18
Does Pactjs supports ?Bi-directional GRPC constructs? in contract testing?

pjayakumar
2023-03-10 02:21
has joined #pact-js

matt.fellows
2023-03-10 03:16
It supports grpc contracts yes

matt.fellows
2023-03-10 03:17
See the v4 interface, you would use the provider/grpc plugin

manishmitraba
2023-03-10 03:21
Do you have any Sample, Which I can look at. I just got the Unary flow example, I was looking fir Bi-directional one

tjones
2023-03-10 03:22
I don?t think the pact model would support bi-directional grpc- but the #protobufs channel would be the right place to ask

ivan.mikhalka
2023-03-10 10:41
> That?s an interesting constraint. Is your use case unusual/ different in some way? @matt.fellows Currently the best I came up with in such situation (when no possible to use API client directly), it using real and mock client in conjunction. Mock client in use for counting request to pact server, and real API, with mocked request method in use to check logic (validate types etc.). Example: ``` await provider.executeTest(async mockServer => { const service: MockClient = new MockClient(mockServer.url); await service.getUserInfo('7777777'); // just to get counts on pact mock server, verifies nothing realApiClient['get'] = jest.fn<Promise<any>, [string]>(async () => userInfoMockResponse); // mock underlying method 'get' // userInfoMockResponse has strict type IUserInfo from source code const dataFromAPI: any = await realApiClient.getUserInfo('7777777'); // getUserInfo() method contains some validation for data from 'get' expect(dataFromAPI).toEqual(reify(expectedBody)); });``` Still, it is not ideal at all, at least it checks types, if some fields will be added or removed from type, contract test will fail.

josh.marlow
2023-03-10 15:10
has joined #pact-js

patilb
2023-03-11 17:02
has joined #pact-js

renan.santos
2023-03-11 18:46
has joined #pact-js

tjones
2023-03-11 22:17
This definitely shouldn?t happen - can you put this in a repository that reproduces it?

tjones
2023-03-11 22:18
depending on how you?re building, it might be corruption in some caching layer. Removing node_modules and running `npm install` again might fix it

keren.eckshtein
2023-03-12 08:57
has joined #pact-js

sr
2023-03-12 11:58
has joined #pact-js

gokuldot
2023-03-12 17:30
has joined #pact-js

ldgaribello
2023-03-13 06:23
has joined #pact-js

ashish_garg5
2023-03-13 10:27
has joined #pact-js

lidan.liu
2023-03-13 10:45
has joined #pact-js

vipin.kumar
2023-03-13 12:29
has joined #pact-js

gsouza
2023-03-13 15:18
hey @yousafn and @tjones i left the result in the comments after updated the version >>> https://github.com/pact-foundation/pact-js-core/issues/433#issuecomment-1466346483

bknapik
2023-03-13 17:13
has joined #pact-js

ravi0894
2023-03-13 17:38
has joined #pact-js

anji.boddupally
2023-03-13 20:37
has joined #pact-js

kgrady
2023-03-13 21:25
Yup I had to do a clean `npm install` after nuking node_modules

voon.wong
2023-03-14 01:34
has joined #pact-js

gigamac
2023-03-14 08:09
has joined #pact-js

ivstam
2023-03-14 08:43
has joined #pact-js

harwin1494
2023-03-14 11:51
Hi all, how can we pass a particular consumer tag in the create-webhook command, so that whenever there is any consumer contract published to the broker with a certain tag, the webhook triggers the provider tests, thus enabling the provider to fetch the contract with that specific tag from the broker? How can we achieve this?

melikesezin
2023-03-14 14:17
has joined #pact-js

gopishankar.haridas
2023-03-14 16:42
has joined #pact-js

rajasekaran.parthiban
2023-03-14 20:13
has joined #pact-js

matt.fellows
2023-03-14 22:15
I don?t believe you can do that at the moment, or at least, you don?t set it up in the way you described: ? Webhook guide: https://docs.pact.io/pact_broker/webhooks#introduction ? These are the variables you can have in the webook template: https://github.com/pact-foundation/pact_broker/blob/master/lib/pact_broker/doc/views/webhooks.markdown#dynamic-variable-substitution You wouldn?t likely want to create a webhook for each tag, but you can have the webhook pass through the tag (see `${pactbroker.consumerVersionTags}`)

sbanerjee
2023-03-15 02:46
has joined #pact-js

harwin1494
2023-03-15 06:16
Yes Matt, I am looking for something like `${pactbroker.consumerVersionTags` this only, but how to pass this variable in the create-webhook command? Can you please share any example?

kurt_schriefer
2023-03-15 13:21
has joined #pact-js

gawaine.ogilvie
2023-03-15 15:07
Has anyone figured out the `node-gyp` issues that occur on Node v16? It seems to originate from this script: ```"format:fix": "npm run format:base -- --write \"{src,standalone,bin,test}/**/*.{ts,tsx}\"", "postinstall": "npm run native", "native": "node-gyp rebuild -v"``` the `native` command specifically where it does the `node-gyp rebuild -v` error: ```gyp ERR! node -v v16.16.0 gyp ERR! node-gyp -v v3.6.3 ``` I?m using `"@pact-foundation/pact": "^11.0.0",`


yousafn
2023-03-15 15:15
I would imagine it dues to build chain deps in node-gyp see pact-js troubleshooting section https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#installation-failing-missing-python-c-or-build-tools there is some related discussion about ways around it, but all have upsides/downsides, worth having a read

gawaine.ogilvie
2023-03-15 18:21
@yousafn Thanks for the link, that seemed to fix things on my end.

yousafn
2023-03-15 18:30
Excellent, glad that helped. Curious if you saw the readme/troubleshooting guide, or if the first thought was to jump on slack, genuinely curious as it may be worth lifting some of our troubleshooting info out and attaching to keywords in slack. Whilst I'm also thinking, I'm not sure if we could detect in the script its failed and point the user to the troubleshooting guide, in our code to provide useful next steps

gawaine.ogilvie
2023-03-15 18:34
I?ve experienced this error before for a variety of reasons and used different approaches. In this case, it was the link you sent to the README that unblocked me. Previous solutions involved ? Adding python2 to docker image ? Using Node 14 instead For my team, we definitely need to use Node 16, so I came to this channel after a few days of being stuck.

yousafn
2023-03-15 18:57
thanks for the feedback @gawaine.ogilvie that is useful, and good luck on the teams journey into contract testing

gawaine.ogilvie
2023-03-15 18:58
Thanks for the prompt reply! I?m currently working on 3 services in parallel between several teams. (adding pact testing) Will post again if I have more questions :slightly_smiling_face:

andreas530
2023-03-15 22:32
has joined #pact-js


santiago.rendong
2023-03-15 23:21
has joined #pact-js

christine.awofeso
2023-03-16 09:58
has joined #pact-js

konstantin.manna
2023-03-16 15:04
has joined #pact-js

emgarcia
2023-03-16 15:44
has joined #pact-js

john.goodwin
2023-03-16 15:51
has joined #pact-js

tomasz.kowalczyk
2023-03-16 15:51
has joined #pact-js

samir.ferreira
2023-03-16 16:27
has joined #pact-js

aaron.m.williams24
2023-03-16 16:38
my company is getting this error randomly. Trying to look into how to fix it? :think_ie:

kripa.kurian
2023-03-16 19:31
@kripa.kurian has left the channel

raess.simon
2023-03-16 23:02
has joined #pact-js

yousafn
2023-03-17 14:31
Hey @aaron.m.williams24 I've not seen that before, probably best raising a fresh thread, or issue on the repo along with some details of your setup.

aaron.m.williams24
2023-03-17 14:35
Cool, yeah I was going to capture more details and report it. I?ll create an issue on GIT

anshu.ranjan1002
2023-03-17 21:59
has joined #pact-js

milda.abromaviciute
2023-03-18 13:15
Hi there, not sure if this is the right channel to post, but please point me to the correct team if not. We are trying to implement pact across a varied tech stack in the company, one of them being the front end team, so we're using pact-js for them. The problem is that the pact core package, pulled in with pact js, has the standalone pact inside it on ruby version 2.4.0, which is throwing some vulnerability issues with our security checks. Are there options I can use to bump this ruby version, or are there any plans to bump the version by the pact team? Thanks very much in advance.

milda.abromaviciute
2023-03-18 13:36
ah I see traveling ruby hasn't had a release for a higher version for a long time.

mptinternational
2023-03-18 18:12
has joined #pact-js

matt.fellows
2023-03-18 22:06
Hi Milda, short answer is yes. We'll be removing it from Pact JS very soon

matt.fellows
2023-03-18 22:07
Or at the very least, it won't be a required dependency

matt.fellows
2023-03-18 22:09
This being said, just because the packages have security vulnerabilities associated with them doesn't mean they are actually problematic in real life Security tools are still not advanced enough to actually tell you if they're applicable or not. You could literally remove the tiny folder post install and Pact would work, if that workaround is acceptable

16728365
2023-03-19 14:30
has joined #pact-js

brick777
2023-03-19 21:47
has joined #pact-js

milda.abromaviciute
2023-03-20 08:59
Thanks so much for the thorough response, Matt. We do have a security team to speak to about these if need be, but wanted to see if there's something that can be done on the dev end to prevent them popping up in the first place. Removing the folder seems like a perfectly reasonable workaround for now. Cheers!

mark.ingram
2023-03-20 11:31
has joined #pact-js

ulises.cervino
2023-03-20 11:39
hi all, question about provider states, in particular javascript: how does one specify a path with provider values where you have 2 variables in the expression? We do things like `path: fromProviderState('/${entityId}', UUID)` However, how does one do something like `path: fromProviderState('/${entityId}/extra/stuff/${anotherId}', UUID, UUID)` ? (this is not possible in our current version of the pact libs for java/typescript -- wrong signature). For reference https://github.com/pact-foundation/pact-js/blob/master/docs/matching.md#provider-state-injected-values Though those docs show how to do single values (we know and use this already)

ulises.cervino
2023-03-20 11:47
maybe it's a case of doing `fromProviderState('/${anIdHere}/extra/stuff/${anotherId}', '/' + UUID1 + '/extra/stuff/' + UUID2)`?

tjones
2023-03-20 11:56
I?m not sure, but this definitely won?t be right

tjones
2023-03-20 11:58
It?s possible that this isn?t supported. I?d wait for a maintainer, but I would guess it would be either of: 1) Not supported in the DSL yet 2) You provide an object like `{ anIdHere: UUID1, anotherId: UUID2 }` 3) Possibly an array `[UUID1, UUID2]`

tjones
2023-03-20 12:08
Ah, apologies. I think you were right. The syntax is: ```fromProviderState(<string that gets parsed>, <example string with replacements>)```

tjones
2023-03-20 12:09
Whatever the answer is, there is probably a documentation change needed here

matt.fellows
2023-03-20 12:33
Calling @uglyog, he?s the creator of this radical feature?

ulises.cervino
2023-03-20 12:44
I suspect this is "right" in that the example is not an example value (AFAICS) of the variable but rather of the path itself

ulises.cervino
2023-03-20 12:45
(still debugging things btw - stay tuned for updates)

jo.laing
2023-03-20 17:06
has joined #pact-js

erich.buri
2023-03-20 22:07
has joined #pact-js

erich.buri
2023-03-20 22:21
Hi, I'm trying to write a pact for an API using PactJS and TypeScript. The API uses Map, where the Key is an ID (uuid) and the Value will be an object I need to match. As it's unknown what the ID is I can't really write the body out in the `addInteraction()` method (`willRespondWith`). But the resulting pact-json file would have the expressiveness to do what I want. I can't find a matcher that would yield the `matchingRules` that I'm looking for. As an example: Instead of ```"$.body.angebote.CLASSIC.angebotStatusFachlich": { "match": "type" }, "$.body.angebote.COMFORT.angebotStatusFachlich": { "match": "type" },``` I would like it to generate: ```"$.body.angebote.*.angebotStatusFachlich": { "match": "type" },``` Another example: ```merkmale: { DOMIZILLAND_VN: { art: 400054, code: 40, }, MERKMAL_PARTNERART_VN: { art: 432, code: 433, }, },``` => The keys will vary (DOMIZILLAND_VN, MERKMAL_PARTNERART_VN), so I would like to be able to generate rules like: ```"$.body.merkmale.*.code": { "match": "type" },``` We're currently using Pact 9.x - anything in there that would allow me to write the pact-test in a spec-File that will actually produce matching rules with wildcards? Manually writing the pact-files is not really maintainable. Would there be a solution in 10.x? I saw on github discussions about eachKey-Matchers and I think that goes in the right direction, but I could not find that in the API for 9.x (I read that this kind of API is supposedly bad design, but it works really good with JavaScript/TS Frontends and it is now what it is.) Any help is appreciated.

matt.fellows
2023-03-20 22:22
You?re right, 9.x.x won?t have this matcher

matt.fellows
2023-03-20 22:23
There is a matcher in the 10.x.x branch, but there is currently a bug in that (easily fixed): https://github.com/pact-foundation/pact-js/issues/952#issuecomment-1452805742

erich.buri
2023-03-20 22:24
`eachValueLike()` sounds exactly like the thing I need.

erich.buri
2023-03-20 22:25
So I will have to figure out how we can switch to 10.x. Can I use 10.x to generate v2-Pact-Files? Or can I use `eachValueLike` only with v3 Pact Files?

erich.buri
2023-03-20 22:26
If I can generate v2-Files, the Producer does not necessarily have to update

uglyog
2023-03-20 23:16
Tim is correct, the two values are the expression to use on the provider side, and the example value to use on the consumer side.

matt.fellows
2023-03-21 01:03
No worries!

matt.fellows
2023-03-21 01:06
Sorry for the ?rant?-ish. We get a lot of this across the board, and the current state of vulnerability management is rather painful for maintainers of libraries, because if you can?t auto-bump versions then your only recourse is to explain why it?s not actually a problem, but that doesn?t make the security people happy

tjones
2023-03-21 01:19
> Can I use 10.x to generate v2-Pact-Files? Yes, but not if you use the `eachValueLike` matcher.

xiaorong.ruby
2023-03-21 09:34
has joined #pact-js

markcox20
2023-03-21 10:08
has joined #pact-js

oloruntobi.ayilara
2023-03-21 14:01
has joined #pact-js

pankaj_kumar39
2023-03-21 14:18
has joined #pact-js

ravi_shankar_lakkims
2023-03-21 14:18
has joined #pact-js

sathish.nilla
2023-03-21 14:19
has joined #pact-js

sikandar_kumar.singh
2023-03-21 14:19
has joined #pact-js

benjamin.earle
2023-03-21 19:23
has joined #pact-js

sanjaysingh99in
2023-03-22 00:57
has joined #pact-js

rafalmaciak
2023-03-22 08:03
has joined #pact-js

jyothy18
2023-03-22 09:23
has joined #pact-js

haiyang.huang
2023-03-22 10:30
has joined #pact-js

erich.buri
2023-03-22 10:37
Hi From the Doc here https://github.com/pact-foundation/pact-specification/tree/version-3#allow-arrays-of-matchers-to-be-defined-against-a-matcher-path I see that multiple matchers are allowed in V3 and there is an option to specify `"combine": "AND",` or `"combine": "OR",` I'm interested in that feature, but I don't see how the I can apply it with pact-js. It always writes `"combine": "AND",` How can I achieve an OR-Combination of Matchers? The API I need to test provides Options of different types, and depending on the type, the type of the remaining fields change: ```{ OPTION_A: { "type": "Number", "value": 0, "allowedValues": [ 0, 500, 1000, 2000 ] }, OPTION_B: { "type": "String", "value": "No", "allowedValues": [ "Yes", "No", "Maybe" ] } }```

ulises.cervino
2023-03-22 10:40
thanks for your replies, my debugging of things seem to align with your comments, much appreciated

matt.fellows
2023-03-22 11:01
Thanks Ron. I also realised I misread this thread in the first place. Sorry team

denispegan4
2023-03-22 13:14
has joined #pact-js

erich.buri
2023-03-22 18:43
I switched to pact-js v11 and now I can use `eachKeyLike` (could not find an `eachValueLike` except in a github-issue discussion) It seems like the resulting `matchingRules` are broken. Is that a know issue? I have the following Interaction: ``` await provider .given('Server is healthy') .uponReceiving('a request to create a new Angebot for Rechtsschutzversicherung-Unternehmen') .withRequest({ method: 'POST', path: `/vvn/kaufen-b2c/rest/angebote/rechtsschutzversicherung-unternehmen/v2/neugeschaeft`, query: { forceCaptcha: 'false' }, headers: { 'x-user-id': 'Z123456', 'x-caller': 'pact-verification', 'x-fall-id': fallid, 'Content-Type': 'application/json', }, body: angeboteErstellenNeugeschaeftRsvUnternehmen as any, }) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json', }, body: { angebote: MatchersV3.eachKeyLike('CLASSIC', { angebotStatusTechnisch: MatchersV3.string('TECHNISCH_KONSISTENT'), }), }, }); });``` Resulting `matchingRules` : ```"matchingRules": { "body": { "$.angebote": { "combine": "AND", "matchers": [ { "match": "values" } ] }, "$.angebote.*.*": { "combine": "AND", "matchers": [ { "match": "type" } ] } }, "header": {} },``` `$.angebote.*.*` is wrong. It should IMHO be:`$.angebote.*.angebotStatusTechnisch`

erich.buri
2023-03-22 18:45
Adding more properties in eachKeyLike-Template resultet in:

erich.buri
2023-03-22 18:45
"$.angebote.*.*": { "combine": "AND", "matchers": [ { "match": "type" }, { "match": "type" }, { "match": "type" }, { "match": "type" }, { "match": "type" }, { "match": "type" }, { "match": "type" }, { "match": "type" } ] },

erich.buri
2023-03-22 18:46
I don't know where to start searching for the error. I'm trying to compile a simple example.

erich.buri
2023-03-22 19:52
The path for matchingRules and for generators seems utterly wrong: ```"generators": { "body": { "$.angebote.*.*.*": { "type": "Uuid" }, "$.angebote.*.*.*.*.*": { "max": 10, "min": 0, "type": "RandomInt" }, "$.angebote.*.*.*[*].*": { "type": "Uuid" },```

tranghetti
2023-03-22 21:15
has joined #pact-js

tranghetti
2023-03-22 21:30
hey there :wave: I'm trying to implement a testing for kafka messages using the NestJS framework. I can't find any examples to guide me on how to implement a simple test with a combination of `nestjs-pact` + `@pact-foundation/pact` + kafka (or any other messaging queue). Do you have any example to share or any suggestion? Thank you!

tjones
2023-03-22 22:35
Have a look at the message examples in the pact-js repository

tranghetti
2023-03-22 22:45
I took a look there but it does not work for NestJS because of the dependency injection stuff. I'm looking for something https://github.com/pact-foundation/nestjs-pact#consumer, but for messages, not for REST API.

tjones
2023-03-22 22:49
I thought the consumer module had been removed from nest-js pact - it doesn?t really add any benefits

tjones
2023-03-22 22:49
You don?t need to use nestjs-pact for consumer testing

tjones
2023-03-22 22:49
You can just use pact directly

amruta_mandavilli
2023-03-23 06:23
has joined #pact-js

shubhamshriram.shinde
2023-03-23 06:34
has joined #pact-js

juliemarierosok
2023-03-23 08:20
has joined #pact-js

colin.aygalinc
2023-03-23 09:23
has joined #pact-js

me1685
2023-03-23 10:53
has joined #pact-js

gregpovorozniuk
2023-03-23 11:32
has joined #pact-js

matt.fellows
2023-03-23 12:21
OR matcher was a controversial introduction at the time and the maintainer group have mostly decided it is a bad idea. It essentially allows you to write a contract the might fail. See also howtooptional as to why


mpalla553
2023-03-23 14:51
has joined #pact-js

erich.buri
2023-03-23 16:03
I think in this case the OR would actually make sense. I want to write a method for a pact-js test-case that would give me the general structure of the response and for each specific test-case I can then overwrite details. Anyway, i would be happy to have the eachKeyLike() Matcher working properly, I can then get around not having OR.

sumit.singh
2023-03-23 18:03
has joined #pact-js

quinton.miller
2023-03-23 19:18
has joined #pact-js

hurdledatrade
2023-03-24 11:24
has joined #pact-js

tranghetti
2023-03-24 12:43
it worked @tjones, thank you for your help. I just had to use NestJS to initialize the nest module and retrieve the service I wanted to test in the `.verify()` function of the `MessageConsumerPact` class. This is necessary because Nest inject dependencies through a module system, so we can't import directly the service in the test file because it can't resolve the dependencies.

jyothy18
2023-03-24 13:36
Hello, I managed to run my customer contract successfully but am unable to publish it in pact. I have given my pact url and token details in consumer pom and not sure if I am missing. any details. I see the message as follows Failed to execute goal au.com.dius:pact-jvm-provider-maven:4.0.10:verify (default-cli) on project employees-consumer: Execution default-cli of goal au.com.dius:pact-jvm-provider-maven:4.0.10:verify failed: lateinit property serviceProviders has not been initialized -

tjones
2023-03-24 13:38
I don?t think this is in the right channel - you perhaps want #pact-jvm

srijan.c
2023-03-24 15:26
has joined #pact-js

praveen.gangasani
2023-03-26 13:19
has joined #pact-js

matt.fellows
2023-03-27 02:43
I like to quote @tjones on this > A pact test is not about describing the possible responses, it?s about ensuring that your response types are covered. > For example, if you could say ?it might be a person or a team?, you could pass your tests without ever checking that the provider and consumer agree about what a Team should look like > Think of the matchers as saying ?this test covers all cases that pass this matcher?, not ?this is the response schema? I think this should make it onto our ?matchers? best practice guide

tjones
2023-03-27 02:48
> I think in this case the OR would actually make sense. I want to write a method for a pact-js test-case that would give me the general structure of the response and for each specific test-case I can then overwrite details. This doesn?t sound like a good fit for an or matcher to me. If you don?t care about certain parts of the response in your test, just don?t include them

tjones
2023-03-27 02:49
I think the OR matcher is an implementation detail, not part of the exposed API (on purpose).

yzxu
2023-03-27 07:27
has joined #pact-js

1248124408
2023-03-27 08:59
has joined #pact-js

daniel.redelberger
2023-03-27 09:07
has joined #pact-js

ulises.cervino
2023-03-27 13:52
quick question on matches: I was under the (wrong) impression that `atLeastOneLike` meant "check this array, and at least 1 element in it should be like the template", but it turns out that's not it. What's the best way to check that there's at least 1 item in an array of varied items that conforms to the template?

ulises.cervino
2023-03-27 13:58
is it `arrayContaining` that I'm looking for?

mohammed.a.ezzedine
2023-03-27 15:25
has joined #pact-js

kiran.malsetty
2023-03-27 17:20
has joined #pact-js

rchild
2023-03-27 18:46
has joined #pact-js

asoni
2023-03-27 20:23
has joined #pact-js

matt.fellows
2023-03-27 21:47
I think that?s the correct interpretation of it. Additionally, if there are _more_ than 1 items in the array, they all must match the template also

matt.fellows
2023-03-27 21:48
`arrayContaining` says - ?this array can be of any length and contain any objects, but it must have at at least one object that matches this template?

matt.fellows
2023-03-27 21:48
subtly different

tjones
2023-03-27 23:36
It looks like `atLeastOneLike` is a synonym for `eachLike` - I?m not sure when it was added, but I agree it?s misnamed

yu.xie
2023-03-28 00:08
has joined #pact-js

gamer.fikri
2023-03-28 04:46
has joined #pact-js

ulises.cervino
2023-03-28 08:44
so, `arrayContaining` is what I need (I have a heterogeneous array in my response) and I want to check that 1 item matches the template, Y/n?


ulises.cervino
2023-03-28 09:35
lovely, thanks!

shaun.carmody
2023-03-28 13:23
has joined #pact-js

christianschiepe
2023-03-28 13:50
has joined #pact-js

aberman
2023-03-28 19:24
has joined #pact-js

0xoscario
2023-03-29 03:38
has joined #pact-js

paddyhendy94
2023-03-30 12:48
has joined #pact-js

haroldrobson11
2023-03-30 13:16
has joined #pact-js

jfbosca
2023-03-30 15:26
has joined #pact-js

daominhdam
2023-04-01 10:04
has joined #pact-js

joseph.gately
2023-04-03 14:14
has joined #pact-js

bram.harmsen
2023-04-04 07:20
has joined #pact-js

sarah.al-hawi
2023-04-04 10:55
has joined #pact-js

andrei.enache
2023-04-04 10:55
has joined #pact-js

sohaib.zahid
2023-04-04 10:55
has joined #pact-js

behrouz.pooladrak
2023-04-04 10:55
has joined #pact-js

amarpal.amrith
2023-04-04 10:57
has joined #pact-js

laszlo.bogardi
2023-04-04 10:57
has joined #pact-js

caroline.thom
2023-04-04 13:20
has joined #pact-js

jeremy.chao
2023-04-04 14:49
has joined #pact-js

bmdk83
2023-04-04 15:51
has joined #pact-js

maithree.uppunda
2023-04-05 07:50
has joined #pact-js

sivamkumar80
2023-04-05 13:34
has joined #pact-js

vanja.ilic
2023-04-05 14:24
has joined #pact-js

proydimonoff
2023-04-05 14:30
has joined #pact-js

proy
2023-04-05 14:33
has joined #pact-js

kevin.moylan
2023-04-05 16:13
has joined #pact-js

vijaykumar.patel
2023-04-06 06:36
has joined #pact-js

ankit.kumar
2023-04-06 10:55
has joined #pact-js

joye.arbuckle
2023-04-06 14:24
has joined #pact-js

allison.stone
2023-04-06 19:36
has joined #pact-js

mayank
2023-04-06 22:11
has joined #pact-js

ganesh.walunj
2023-04-07 06:05
has joined #pact-js

ganesh.walunj
2023-04-07 09:35
can someone tell me how to set up ci/cd for contract testing on Gitlab?Thanks in advance

tjones
2023-04-07 10:22
This is a pretty general question. What are you stuck on?

ganesh.walunj
2023-04-07 10:24
i don?t have any experience on docker or setting up pipelines.

tjones
2023-04-07 10:26
You don?t need docker for Pact (necessarily). But, it sounds like you?d be better off with the gitlab docs rather than asking here - I don?t personally have recent experience with gitlab.

tjones
2023-04-07 10:26
Best of luck!


tjones
2023-04-07 10:27
But beyond that, I probably can?t help you, sorry.

ganesh.walunj
2023-04-07 10:27
thank you for your time.

jan.krolikowski
2023-04-07 14:39
has joined #pact-js

mragni.majhwar
2023-04-07 17:51
has joined #pact-js

gonzalo.granizo
2023-04-11 10:13
has joined #pact-js

theburningmonk
2023-04-11 11:29
has joined #pact-js

helenarodcal
2023-04-11 11:31
has joined #pact-js

enver.yasar
2023-04-11 13:39
has joined #pact-js

christian.ledgard
2023-04-11 13:49
has joined #pact-js

ddongre
2023-04-11 15:09
has joined #pact-js

prajapati.pravesh
2023-04-12 02:55
has joined #pact-js

robert.strehli
2023-04-12 07:21
Hi, before I raise an issue I wanted to ask here. In our API we have fields with "@id" or "@type". The are 2 problems with that. ? We get this warning `pact-node@10.17.6: WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body']['someData']['pData']['items'][*]@['type']` ? Weirdly pact is adding and removing the matching rule during every test run. So the pact is also changed every time ``` "$.body.someData.pData.items[*].@id": { "match": "type" }, "$.body.someData.pData.items[*].@type": { "match": "type" },``` I also saw there is a similar issue with the pact-php. https://github.com/pact-foundation/pact-php/issues/162 , but there is no progress since 3 years. So my question is should I raise an issue in pact-js or try to push the pact-php issue?

tjones
2023-04-12 07:26
I would push the one that you need fixed. This definitely seems like a bug

tjones
2023-04-12 07:27
> Weirdly pact is adding and removing the matching rule during every test run. So the pact is also changed every time This is odd. Are you deleting the pact file before each run?

matt.fellows
2023-04-12 07:31
Just for clarification, the consumer test is in PHP and the verification is in JS - that right?

matt.fellows
2023-04-12 07:32
It?s possible that a later version of Pact JS will support that matching rule, but I?m not 100% sure on it (for clarity - it _should_ be supported full stop, I just don?t know for sure that it is, and more improtantly, if the PHP library is serialising the correct format)

tjones
2023-04-12 07:35
I bet the problem is that `@` has special meaning in jsonpath

robert.strehli
2023-04-12 07:47
> This is odd. Are you deleting the pact file before each run? No the pact is not deleted. Pact is updating it

tjones
2023-04-12 07:47
You shouldn?t update it every time - I think there?s a note in the docs, you have to delete it

robert.strehli
2023-04-12 07:47
> Just for clarification, the consumer test is in PHP and the verification is in JS - that right? In my case the consumer is in JS and the provider is JAVA

tjones
2023-04-12 07:47
before each test run

tjones
2023-04-12 07:48
otherwise when you remove interactions, they stay around

tjones
2023-04-12 07:52
@matt.fellows I just played around with a jsonpath thing https://jsonpath.com/ - I believe Pact is supposed to write the query as ```$.body.someData.pData.items[*].`@type``` (note the backtick before the `@`)

tjones
2023-04-12 07:54
Also, I can?t find the note that you need to clear out the pacts in the documentation any more. I know it used to be there.


edwin.raju
2023-04-12 08:13
has joined #pact-js

john.hennigan
2023-04-12 08:16
has joined #pact-js

pennellbeth
2023-04-12 08:30
Question: does Pact's consumer driven contract testing support other types of response body than JSON? (E.g. raw HTML output?)

robert.strehli
2023-04-12 09:02
> You shouldn?t update it every time - I think there?s a note in the docs, you have to delete it Could I also use `pactfile_write_mode` with `override` or is deleting it a better way?

tjones
2023-04-12 09:03
You need to delete it I think - I?m personally not familiar with the new write modes, so I don?t know what override does

tjones
2023-04-12 09:03
(For context, I haven?t maintained pact since 10.x)

tjones
2023-04-12 09:05
I think the right place to open an issue about matching properties starting with @ is pact-reference. I?m on mobile, but let me get you a link


tjones
2023-04-12 09:08
I would include: ? pact-js version(s) ? Pact rust version (you can get this from the metadata field in your broken pact file) ? The working json path expression I posted above ? Also mention that the interaction wasn?t overwriting correctly (this is probably also some kind of bug, but I don?t know if it?s related)

tjones
2023-04-12 09:08
You should be clearing out the pacts each time, but if you don?t, then re-running the same test shouldn?t produce a different output

tjones
2023-04-12 09:10
I don?t think the rust pact core which backs pact-js knows when you start and finish the test run, so I think if you can get it to overwrite the file, you?ll only have one interaction. A current maintainer will be able to tell you

donald.robertson
2023-04-12 10:42
has joined #pact-js

tam.norris
2023-04-12 10:46
has joined #pact-js

tam.norris
2023-04-12 10:59
Hi. I am new to pact flow and looking to see if I can use it within my organisation. I have cloned the example code on this blog ...https://www.testingwithmarie.com/post/contract-testing-with-pact-js-and-jest and have been able to get it working and published to my pact broker. I am just playing around with it and want to extend it to add more interactions for other requests. I modified my code based on an example found https://medium.com/@jw_ng/contract-testing-with-pactjs-and-jest-f93c1ffe75a0 however when I try to run the consumer test I get the error ...TypeError: provider.setUp is not a function. It appears that the Pact mock server doesn't start as I also see 'pact@9.17.2: The pact mock service doesn't appear to be running'. Does anyone know what the cause and possible solution of this might be or could point be to some code samples that involve adding multiple interactions to a consumer contract? Much appreciated.

matt.fellows
2023-04-12 11:09
Looking at the output, it looks like Robert is still using the 9.x.x line of Pact (they are Ruby warnings we are seeing there)

matt.fellows
2023-04-12 11:10
> Also, I can?t find the note that you need to clear out the pacts in the documentation any more. I know it used to be there. Thanks. It?s in the migration guide, but new users won?t read that

matt.fellows
2023-04-12 11:11
> I don?t think the rust pact core which backs pact-js knows when you start and finish the test run, so I think if you can get it to overwrite the file, you?ll only have one interaction. A current maintainer will be able to tell you the rust core only has one mode - update the existing pact (analogous to `merge`). The reason is that you can run tests in parallel and so Pact doesn?t know about when the tests start/stop. It just knows about a test, and where to write the interaction

matt.fellows
2023-04-12 11:12
Yes, it supports pretty much any content-type, albeit Matchers are only available on JSON and XML)

matt.fellows
2023-04-12 11:12
We also have recently introduced a plugin framework, which would allow arbitrary protocols/content-types to be used, and matching can be used there if the plugin author implements it

matt.fellows
2023-04-12 11:12
I _suspect_ you could maybe, possible use the XML matching for HTML :grimacing:

tjones
2023-04-12 11:13
Ah, I got confused, because it says pact-node@10, and I forgot that pact-node didn?t exist after pact-js@10

tjones
2023-04-12 11:13
(Which was something I changed, I believe :sweat_smile: )

matt.fellows
2023-04-12 11:14
We have a bunch of examples on the docs site here: https://docs.pact.io/implementation_guides/workshops#examples

matt.fellows
2023-04-12 11:20
hahah all good. I often forget which `pact-node` version is which, but I definitely remember those Ruby warnings (they can be quite unreliable)

matt.fellows
2023-04-12 11:20
I?m also not sure they are JSON path exactly, but JSON path-like. That?s outside of my direct knowledge though, so I could be spewing additional rubbish there

matt.fellows
2023-04-12 11:21
A number of the examples in https://github.com/pact-foundation/pact-js/tree/master/examples also have multiple interactions in them. Last comment - those examples you mentioned are on an older version of Pact JS. I?d start with the latest version (11.x.x)

tam.norris
2023-04-12 11:28
ok, thanks Matt. I will have a look at these.

tien.xuan.vo
2023-04-12 12:05
I installed `pact-js` at the first time and it work fine. But then I work on another computer, then go back and ran `yarn install` and got these errors: ? `Cannot find module 'code-point-at'` ? `Cannot find module 'number-is-nan'` I fix it by running `sudo npm install -g number-is-nan` and `sudo npm install -g code-point-at` Not sure it's `pact-js` 's bug, or we can ignore these kinds of errors. If this is a bug, more details in this thread.

tien.xuan.vo
2023-04-12 12:06
```[1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... warning " > @nivo/core@0.80.0" has unmet peer dependency "@nivo/tooltip@0.80.0". warning " > ra-data-fakerest@4.9.1" has unmet peer dependency "ra-core@^4.0.0". warning " > @testing-library/user-event@12.8.3" has unmet peer dependency "@testing-library/dom@>=7.21.4". [4/4] Rebuilding all packages... [1/5] ? core-js [2/5] ? @pact-foundation/pact-core [3/5] ? es5-ext [4/5] ? core-js-pure error /home/tien/Projects/my-family-tree/admin/node_modules/@pact-foundation/pact-core: Command failed. Exit code: 1 Command: node-gyp rebuild Arguments: Directory: /home/tien/Projects/my-family-tree/admin/node_modules/@pact-foundation/pact-core Output: node:internal/modules/cjs/loader:1078 throw err; ^ Error: Cannot find module 'code-point-at' Require stack: - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/string-width/index.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/wide-truncate.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/render-template.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/plumbing.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/index.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/npmlog/lib/log.js - /usr/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js - /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15) at Module._load (node:internal/modules/cjs/loader:920:27) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/string-width/index.js:3:19) at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Module.require (node:internal/modules/cjs/loader:1141:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/string-width/index.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/wide-truncate.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/render-template.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/plumbing.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/index.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/npmlog/lib/log.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js' ]```

tien.xuan.vo
2023-04-12 12:06
```yarn install v1.22.19 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... warning " > @nivo/core@0.80.0" has unmet peer dependency "@nivo/tooltip@0.80.0". warning " > ra-data-fakerest@4.9.1" has unmet peer dependency "ra-core@^4.0.0". warning " > @testing-library/user-event@12.8.3" has unmet peer dependency "@testing-library/dom@>=7.21.4". [4/4] Building fresh packages... [1/5] ? core-js [2/5] ? @pact-foundation/pact-core [3/5] ? es5-ext [4/5] ? core-js-pure error /home/tien/Projects/my-family-tree/admin/node_modules/@pact-foundation/pact-core: Command failed. Exit code: 1 Command: node-gyp rebuild Arguments: Directory: /home/tien/Projects/my-family-tree/admin/node_modules/@pact-foundation/pact-core Output: node:internal/modules/cjs/loader:1078 throw err; ^ Error: Cannot find module 'number-is-nan' Require stack: - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/is-fullwidth-code-point/index.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/string-width/index.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/wide-truncate.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/render-template.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/plumbing.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/index.js - /usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/npmlog/lib/log.js - /usr/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js - /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js at Module._resolveFilename (node:internal/modules/cjs/loader:1075:15) at Module._load (node:internal/modules/cjs/loader:920:27) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/is-fullwidth-code-point/index.js:2:19) at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Module.require (node:internal/modules/cjs/loader:1141:19) { code: 'MODULE_NOT_FOUND', requireStack: [ '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/is-fullwidth-code-point/index.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/string-width/index.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/wide-truncate.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/render-template.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/plumbing.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/gauge/lib/index.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/node_modules/npmlog/lib/log.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js', '/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js' ]```

tien.xuan.vo
2023-04-12 12:08
The computer that has error: Linux mint 21.1, kernel 6.1, node 18.15.0, yarn 1.22.19 The other computer that doesn't have this error: Pop!OS 22.04, kernel 6.2, node 18.15.0, yarn 1.22.19 (yes same version node + yarn)

matt.fellows
2023-04-12 22:37
My guess is maybe it's something to do with node-gyp dependencies.

matt.fellows
2023-04-12 23:17
Strange that it's complaining about JS deps tho

tjones
2023-04-13 02:52
You?re right! You could say it?s a limitation of the spec: https://github.com/pact-foundation/pact-specification/tree/version-2#matcher-path-expressions > Pact does not support the full JSON path expressions, only ones that match the following rules: > ? All paths start with a dollar ($), representing the root. > ? All path elements are either separated by periods (.) or use the JSON path bracket notation (square brackets and single quotes around the values: e.g. [?x.y?]), except array indices which use square brackets ([]). For elements where the value contains white space or non-alphanumeric characters, the JSON path bracket notation ([??]) should be used. > ? The second element of the path is the http type that the matcher is applied to (e.g., $.body or $.header). > ? Path elements represent keys. > ? A star (*) can be used to match all keys of a map or all items of an array (one level only). This is probably the most relevant bit: > For elements where the value contains white space or non-alphanumeric characters, the JSON path bracket notation ([??]) should be used. I reckon whether not supporting properties starting with `@` is a bug or would need a spec change is an @uglyog question.

tjones
2023-04-13 02:53
For those playing at home, I checked later versions too - V3 https://github.com/pact-foundation/pact-specification/tree/version-3#drop-the-jsonpath-notation-for-matchers - here?s the quote: > Jsonpath will still be used internally for matching body elements. V4 doesn?t mention jsonpath at all.

gopijaganathan7
2023-04-13 07:27
has joined #pact-js

robert.strehli
2023-04-13 08:51
Some update from side :slightly_smiling_face:. It seems now to work with the current version of pact-js or with deleting the old pact file.

robert.strehli
2023-04-13 08:52
Now I have just the problem that the new pact-js version needs python and I don't have python on the docker image but that's another problem :sweat_smile:

lukaszmalek90
2023-04-13 11:40
has joined #pact-js

nickwilliamsqa
2023-04-13 16:15
has joined #pact-js

guozhangliew
2023-04-14 02:03
has joined #pact-js

praboo.p
2023-04-14 07:17
has joined #pact-js

florenciaaldana.rodri
2023-04-14 08:10
has joined #pact-js

paul
2023-04-14 11:06
A bit of a necro thread (sorry). I just got back to this code to remove our shimmed VerifierOptions and noticed that even though we now have `StateHandlers` and `MessageStateHandlers` their union via `VerifierOptions` means a `StateFuncWithSetup` can't satisfy the `MessageStateHandler` type. So while simple `StateFunc` handlers are typing correctly, the `StateFuncWithSetup` are not. Here's an example: ```import { MessageStateHandlers, Verifier, VerifierOptions } from '@pact-foundation/pact'; // This is fine. const stateHandlers: StateHandlers = { key: { setup: async () => { // setup }, }, }; // This is not const unionStateHandlers: StateHandlers & MessageStateHandlers = { key: { setup: async () => { // setup }, }, }; /* VerifierOptions results in: * stateHandlers expecting `(property) ProxyOptions.stateHandlers?: (StateHandlers & MessageStateHandlers) | undefined` */``` I don't think I'm doing anything incorrect here, but if I am just being a dummy please do point it out :slightly_smiling_face: Happy to raise a new issue if you'd like?

tjones
2023-04-14 11:14
Have you updated to the latest?


matt.fellows
2023-04-14 11:59
oh wait lol, that was you :laughing: (I should have looked up)

matt.fellows
2023-04-14 12:00
you?ll need to be on the 11.x line, because the fix for your issue was a breaking change

yousafn
2023-04-14 13:16
Hey all, With Node 14 going out of security support in 2 weeks, what are peoples current projects like in terms of updating? https://endoflife.date/nodejs ? Is anyone still running node 12.x / 14.x apps or earlier ? How important are your libraries you depend on, supporting those? ? As what point do maintainers stop supporting the runtimes? (maybe for your own projects, but this will be a wider question proposed to our javascript pact community)

taher.kapasi
2023-04-14 15:53
has joined #pact-js

michael385
2023-04-14 16:40
has joined #pact-js

tjones
2023-04-14 23:57
Most libraries are staying in step with the node release cycle, I thought there was a note about this somewhere

darrenoc3
2023-04-15 03:46
has joined #pact-js


ones.ardo
2023-04-17 07:58
has joined #pact-js

deeptiagrawal
2023-04-17 23:31
has joined #pact-js

madhukar.koratagere
2023-04-18 06:24
has joined #pact-js

mahesh.damavarapu
2023-04-18 06:26
has joined #pact-js

syamphaneendrak
2023-04-18 13:53
Hi @All, can someone help me with the below error. I am quiet confused with the response. I have followed the below WIKI age for setting up the consumer based contract. https://docs.pact.io/implementation_guides/javascript/docs/consumer ``` yarn test:consumer yarn run v1.22.17 $ jest __tests__/contract/consumer --runInBand --setupFiles ./__tests__/helpers/pactSetup.js --setupTestFrameworkScriptFile=./__tests__/helpers/pactTestWrapper.js RUNS __tests__/contract/consumer/ClientsConsumer.spec.js [14:40:14.473] ERROR (23284): pact@11.0.2: Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was expected but not received: Method: GET Path: /api/employees Headers: Accept: application/json \__tests__\contract\consumer\ClientsConsumer.spec.js:81 expect(response.headers['Content-Type']).toBe("application/json"); ^ TypeError: Cannot read properties of undefined (reading 'Content-Type')```

jan.krolikowski
2023-04-18 13:56
Hi! How `response` is instantiated? Is it something from Pact or your code? Could you share the test file?

syamphaneendrak
2023-04-18 13:57
```describe("GET All Employees", () => { provider .given('I have a list of empoyees') .uponReceiving('a request for getting all employees') .withRequest({ method: 'GET', path: '/api/employees', headers: { Accept: 'application/json' }, }) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json' }, body: GET_EMPLOYEES_EXPECTED_BODY, }); return provider.executeTest((mockserver) => { console.log("mockserver.url: " + mockserver.url); console.log("mockserver.port: " + mockserver.port); const employeeService = new EmployeeService(mockserver.url, mockserver.port); const response = employeeService.getEmployees(); console.log("response: " + response); expect(response.headers['Content-Type']).toBe("application/json"); expect(response.data).toEqual(GET_EMPLOYEES_EXPECTED_BODY); expect(response.status).toEqual(200); }); });```

syamphaneendrak
2023-04-18 13:57
```class EmployeeService { constructor(baseUrl, port) { this.baseUrl = baseUrl; this.port = port; } getEmployees = async () => { const response = await axios.get(`${this.baseUrl}:${this.port}/api/employees`).then((res) => { return res }) .catch((error) => { console.log("Exception while fetching the employees"); return error.res }) // console.log("response header: " + response.headers['content-type']); return response };```

syamphaneendrak
2023-04-18 13:58
Pactsetup.js ```global.port = 8081 global.provider = new PactV3({ port: global.port, log: path.resolve(process.cwd(), "__tests__/contract/logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "__tests__/contract/pacts"), spec: 2, logLevel: 'INFO', pactfileWriteMode: "overwrite", consumer: "Frontend", provider: "EmployeeService", })```

jan.krolikowski
2023-04-18 13:58
you lack `await` before calling `getEmployees`

syamphaneendrak
2023-04-18 13:58
ok, let me try that @jan.krolikowski Thanks for your support :slightly_smiling_face:

syamphaneendrak
2023-04-18 14:01
@jan.krolikowski Even If i use Async wait, facing the same issue. ```return provider.executeTest(async(mockserver) => { const employeeService = new EmployeeService(mockserver.url, mockserver.port); const response = await employeeService.getEmployees(); expect(await response.headers['Content-Type']).toBe("application/json"); expect(await response.data).toEqual(GET_EMPLOYEES_EXPECTED_BODY); expect(await response.status).toEqual(200); });```

jan.krolikowski
2023-04-18 14:07
could you `console.log` the response in the test? Maybe the request isn?t fired at all.

syamphaneendrak
2023-04-18 14:08
I tried doing that @jan.krolikowski It was strange that it didn't print any value

syamphaneendrak
2023-04-18 14:09
I might be missing something, but not able to find it.

jan.krolikowski
2023-04-18 14:14
you added `await` to the response in the `except` methods? That?s not how it should work :slightly_smiling_face: it should be plain javascript object here, so no need for `await` here

syamphaneendrak
2023-04-18 14:16
``` const employeeService = new EmployeeService(mockserver.url, mockserver.port); const response = await employeeService.getEmployees(); expect(response.headers['Content-Type']).toBe("application/json"); expect(response.data).toEqual(GET_EMPLOYEES_EXPECTED_BODY); expect(response.status).toEqual(200);```

syamphaneendrak
2023-04-18 14:16
Removed, but still its the same response @jan.krolikowski

jan.krolikowski
2023-04-18 14:18
and you still get the same message? ```TypeError: Cannot read properties of undefined (reading 'Content-Type')```

syamphaneendrak
2023-04-18 14:19
Yes @jan.krolikowski ```expect(response.headers['Content-Type']).toBe("application/json"); ^ TypeError: Cannot read properties of undefined (reading 'headers')```

jan.krolikowski
2023-04-18 14:19
so the response is undefined here

jan.krolikowski
2023-04-18 14:19
let?s go back to your service

syamphaneendrak
2023-04-18 14:20
ok..

syamphaneendrak
2023-04-18 14:20
```//import axios from "axios"; import axios from "axios"; //const baseURL = "http://localhost:8080"; class EmployeeService { constructor(baseUrl, port) { this.baseUrl = baseUrl; this.port = port; } getEmployees = async () => { const response = await axios.get(`${this.baseUrl}:${this.port}/api/employees`).then((res) => { return res }) .catch((error) => { console.log("Exception while fetching the employees"); return error.res }) // console.log("response header: " + response.headers['content-type']); return response }; } export default EmployeeService;```

syamphaneendrak
2023-04-18 14:20
This is my complete file

jan.krolikowski
2023-04-18 14:20
if you remove `then` and `catch` parts from the call: ```getEmployees = async () => { const response = await axios.get(`${this.baseUrl}:${this.port}/api/employees`) return response };```

jan.krolikowski
2023-04-18 14:20
what?s the return value of the `getEmployees` method?

syamphaneendrak
2023-04-18 14:21
Let me check

syamphaneendrak
2023-04-18 14:24
I replaced the getEmployee method with the below one. ```getEmployees = async () => { return axios.request({ baseURL: this.url, headers: { Accept: 'application/json' }, method: 'GET', url: '/api/employees', }); };```

syamphaneendrak
2023-04-18 14:25
Now when I run, getting the below error. ```Test suite failed to run Your test suite must contain at least one test. at onResult (node_modules/@jest/core/build/TestScheduler.js:173:18) console.log ? Test suite failed to run Returning a Promise from "describe" is not supported. Tests must be defined synchronously. Returning a value from "describe" will fail the test in a future version of Jest. 42 | // afterEach(() => provider.verify()) 43 | > 44 | describe("GET All Employees", async () => { | ^ 45 | 46 | provider 47 | .given('I have a list of empoyees')```

jan.krolikowski
2023-04-18 14:26
that?s better, and it?s true, you cannot. You have to add a `test` method here, within `describe`. Or rename `describe` to `test`, that should work as well.

syamphaneendrak
2023-04-18 14:30
I replaced the describe with test and ran again, the response is, ```Test suite failed to run TypeError: provider.finalize is not a function 5 | afterEach(() => provider.verify()); // Ensure the mock provider verifies expected interactions for each test 6 | > 7 | afterAll(() => provider.finalize()) | ^ at Object.<anonymous> (__tests__/helpers/pactTestWrapper.js:7:25)```


syamphaneendrak
2023-04-18 14:38
I have commented the below piece of code, ```// beforeAll(() => provider.setup()) // afterEach(() => provider.verify()); // afterAll(() => provider.finalize())```

syamphaneendrak
2023-04-18 14:38
Then I am getting the below error, ``` Employee Clients Service Tests cannot be nested.```

syamphaneendrak
2023-04-18 14:39
I replaced the main test block with describe and ran again,

syamphaneendrak
2023-04-18 14:40
``` Employee Clients Service ? GET All Employees AxiosError: Network Error at XMLHttpRequest.handleError (node_modules/axios/lib/adapters/xhr.js:154:14) at XMLHttpRequest.<anonymous> (node_modules/jsdom/lib/jsdom/living/helpers/create-event-accessor.js:33:32) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:316:27) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:267:3) at XMLHttpRequestEventTargetImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:214:9) at fireAnEvent (node_modules/jsdom/lib/jsdom/living/helpers/events.js:17:36) at requestErrorSteps (node_modules/jsdom/lib/jsdom/living/xhr-utils.js:121:3) at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr-utils.js:51:3) at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:675:20) at Request.onRequestError (node_modules/request/request.js:877:8) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 10.534s Ran all test suites matching /__tests__\\contract\\consumer/i. console.error Error: Error: connect ECONNREFUSED ::1:80```

jan.krolikowski
2023-04-18 14:42
ok, it seems like it?s not something related with the Pact itself

jan.krolikowski
2023-04-18 14:42
gotta go for now, please refer to the examples in pact-js Github

syamphaneendrak
2023-04-18 14:43
Thank you @jan.krolikowski for your support

paul.caplan
2023-04-18 14:52
has joined #pact-js

yousafn
2023-04-18 16:31
Can you create a repro in a github repo to share?

yousafn
2023-04-18 16:31
Nice one for the support Jan :raised_hands:

tjones
2023-04-18 21:32
Taco for @jan.krolikowski :taco: !

tjones
2023-04-18 21:34
I?m not sure what?s going on here, but you may want to check your test structure

squarism
2023-04-18 22:44
has joined #pact-js

tjones
2023-04-18 23:04
I don?t think this is a Pact problem. Probably there are at least three things happening: 1) As Jan pointed out, you need to await the appropriate parts of the test. Anything that returns a promise must be `await`ed, and you must either make your `test`/ `it` function `async` or return a promise from the test function. 2) You can?t currently make that change, as the order of `test`/`it` and `describe` blocks is not correct. Without seeing your full code, it?s hard to advise, but in general: you can have multiple describes (even nested), but you must only have one `test` or `it`, and it must not have `describe` inside it. Check the documentation for your test runner (Jest or Mocha, probably?) for more information. 3) Your code is not calling the mock correctly, and you?re getting an error response back, which was originally returning `undefined` because of the `catch` block returning `error.res`, which doesn?t exist on an `AxiosError: Network Error`. This is why Jan suggested removing the `catch` - long term, you?ll want to improve the error handler in your code. Check the https://axios-http.com/docs/handling_errors docs for an example. As to why it is getting a network error, I would try printing out `${this.baseUrl}:${this.port}/api/employees` in your EmployeeService to check that it is reasonable - although I suspect it will start working once your `await`s are in the right place.

yousafn
2023-04-18 23:22
so i heard about koffi this week https://koffi.dev/platforms#supported-platforms pre built binaries for node sound mighty mighty appealing considering the platform support and the amount of grief requiring a full developer tool chain for node-gyp support. I?ve built some aarch64 binaries for windows here https://github.com/YOU54F/pact-reference/releases/tag/libpact_ffi-v0.4.3 managed to get it building with node-gyp after using an unofficial built of v18.15.0 node, in order to get windows arm node bindings ( they aren?t packaged with the official build yet ) but when calling it through pact-js it complains that pact.node isn?t a valid application so more digging required. not going to lie, it?s awfully fun to do this, as a job

yousafn
2023-04-18 23:42
thanks buddy, that was a good read.

yousafn
2023-04-18 23:46
so come eol of node 14 lts in a couple of weeks, we switch off node 14 ci, set the engines flag and do a major version bump, and build a nice compat matrix matching node release lts versions and show tests running against them is my tl;dr from that

tjones
2023-04-18 23:47
> aarch64 binaries for windows :exploding_head:


tjones
2023-04-18 23:48
That?s what I used to do when I maintained it

tjones
2023-04-18 23:48
except for the compat matrix. I just put it in the changelog.

tjones
2023-04-18 23:51
I think doing that kind of release means that you _must_ have good changelogs - as in, each changed item is understandable to a user with no context of the internals, no empty release note releases, clear migration guidelines for breaking changes, etc.

tjones
2023-04-18 23:52
One really nice feature of https://github.com/googleapis/release-please is that you can change the release notes for a PR after it has been merged, so you don?t have to be so draconian about commit messages in first-time contributor PRs. However, one downside is that it requires squash merges if you want to totally override the commit messages on the branch.

tjones
2023-04-18 23:54
Also, I don?t run CI on node?s bleeding edge releases (the odd version numbers). This is because I found they produced too many broken builds.

matt.fellows
2023-04-19 02:11
this looks great, especially if it?s actually going to be maintained (unlike the previous ffi lib). That being said, Tim noticed some serious problems with the previous abstractions in FFI and the problems/segfaults/memory issues that were likely to ensue. Hopefully they are addressed in this lib

matt.fellows
2023-04-19 02:14
See also https://github.com/pact-foundation/pact-js/issues/899#issuecomment-1462945915. I believe doing what we need to remove the build chain during install, is just to build a few additional targets and embed them in the package. It will add a bit of size to the distro, but I think it will be manageable

cars2991
2023-04-19 02:42
has joined #pact-js

tjones
2023-04-19 04:46
> especially if it?s actually going to be maintained I dunno. It?s behind on current Node releases.

tjones
2023-04-19 04:47
For example, it supports none of the ?current? releases, and only supports ?active?, ?maintenance? and ?end-of-life?

tjones
2023-04-19 04:47
My feeling is - FFI is not the way to go, unless you want to become a Node maintainer

vaidas.sieber
2023-04-19 06:42
has joined #pact-js

jonathandelaros
2023-04-19 07:40
has joined #pact-js

priyaranjanmudliar
2023-04-19 09:05
has joined #pact-js

ajaydiwakar.ka
2023-04-19 10:11
has joined #pact-js

meghaagr
2023-04-19 10:13
has joined #pact-js

hcummins
2023-04-19 12:58
has joined #pact-js

michael.dasilva
2023-04-19 13:13
has joined #pact-js

syamphaneendrak
2023-04-19 13:52
I noticed that baseUrl is having already the port number and I am appending port number again. After removing the portnumber its worked. Thank you all for your support :slightly_smiling_face:

jan.krolikowski
2023-04-19 13:53
wow, it was right in front of our eyes all the time! :wink: nice job figuring it out.

ivana.lazic
2023-04-19 14:04
has joined #pact-js

tjones
2023-04-19 14:23
@yousafn - I reckon you?d like JSii?s approach to this problem:

yousafn
2023-04-19 14:56
Yeah the pact ruby standalone with my changes in won't execute under node 19 on windows for me, for nodeymcreasons. I personally LOVE that messaging though, will 110% take a look

tjones
2023-04-19 14:57
> nodeymcreasons :joy:

vakong13
2023-04-19 16:15
has joined #pact-js

ravinder.kadiyan
2023-04-20 09:56
has joined #pact-js

alfredo.castro
2023-04-20 13:27
has joined #pact-js

yousafn
2023-04-20 15:48
FFI is v cool, but when things go wrong, they can go seriously wrong and leave the user proper head scratching, plus the complexities of what might be issues in the core, or in the ffi translation layer or in the main code or the users code. Ffi and node, currently just feels gnarly. Bun and Deno seem to have a nicer approach that doesn?t require building any bindings as properly custom code which from experimentation very few languages need. JNI is similar in java. although the panama project looked very cool at being able to use it without having to write wrapper code

yousafn
2023-04-20 15:51
i had a bit of a go with node pre gyp for pre building the node bindings and publishing them to github where they can be picked up with an install hook where it will try and get the bindings from the release location otherwise try and build from source ( as current ) i personally would prefer to have slimmer npm packages and download required libs at run time, the current weight of the pact-core is 215mb ( it includes the standalone aswell ) if we carried pact.node bindings for each node api version and had to store the shared libs, we are hurting a fair few digital trees. i know generally corporates have issues with proxies and install scripts, but i would be the question why are they using npm at all, why aren?t they vetting all code and creating internal mirrors.

yousafn
2023-04-20 15:52
re koffi - i looked at the source and some some tests i think but couldn?t see anywhere that was running them. was hoping it would be an omission and that the docs aren?t up to date

lluis.casals
2023-04-20 17:07
has joined #pact-js

dprawatya
2023-04-21 01:11
has joined #pact-js

mbutt
2023-04-21 01:11
has joined #pact-js

matt.fellows
2023-04-21 02:50
All good points Saf

matt.fellows
2023-04-21 02:50
> i know generally corporates have issues with proxies and install scripts, but i would be the question why are they using npm at all, why aren?t they vetting all code and creating internal mirrors. It?s hard to build a mirror though, when your code?s `postinstall` script needs to pull artifacts down dynamically from Github

matt.fellows
2023-04-21 02:51
It was a really big pain point for some of PactFlow?s enterprise banking customers, who understandably, don?t like the idea of an arbitrary script running after `npm i` happens where any file from the internet can make their way onto a dev machine :wink:

tjones
2023-04-21 03:11
I can see why that would make someone uncomfortable

marcia.meira
2023-04-21 12:43
has joined #pact-js

raubreysmith
2023-04-21 12:46
has joined #pact-js

tam.norris
2023-04-21 13:56
Hi. I am following the tutorial on https://killercoda.com/pactflow/scenario/pactflow-getting-started-js. And was wondering is there a way to get the test to just check that the client returns a response that matches the expected response in terms of the keys and types rather than an exact match on the values? Wouldn't this be more appropriate for a contract test than matching on exact values?


tam.norris
2023-04-21 14:33
Hi Jan. Thanks for the response. In the 'like' is used in the MockProvider but its in the expect statement in the assert stage which is doing a deep.equal which seems to only pass if the response is exactly the same i.e structure, types and values.

tam.norris
2023-04-21 14:33
const expectedProduct = { id: 10, type: "pizza", name: "Pepperoni" }; await mockProvider.addInteraction({ state: "a product with ID 10 exists", uponReceiving: "a request to get a product", withRequest: { method: "GET", path: "/products/10", }, willRespondWith: { status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: like(expectedProduct), }, }); // (5) Act const api = new ProductApiClient(mockProvider.mockService.baseUrl); const product = await api.getProduct(10); // (6) Assert that we got the expected response expect(product).to.deep.equal(new Product(10, "Margharita", "pizza")); }); });

tam.norris
2023-04-21 14:59
Sorry I think I might have misunderstood how the consumer pact works. When I run the provider pact specs it passes successfully even if values are different.

tam.norris
2023-04-21 14:59
which is want we want to see.

ksenia.vasileva
2023-04-21 15:02
has joined #pact-js

yousafn
2023-04-21 15:14
correct, by using matchers, you make the verification less brittle and reliant on the example data. Pact is specification by example, so we want something nice to render on the the screen if you view the pact, but you usually want to check the shape of the data, and not particular unique values themselves (bar within either a discrete type, or whatever bounds you place on it in your consumer test) The matchers in the consumer side generate example code, which you can use in your consumer tests to assert that your api client under test unmarshalls the correct response based on the example data you've provided (where you probably care about the value you passed in)

yousafn
2023-04-21 15:16
Pact is essentially a unit testing framework using _specification by example_. It just so happens that to be able to run those tests on the API consumer and provider side, it needs to generate an intermediate format to be able to communicate that structure - this is the specification, matchers and generators are encoded into this specification :slightly_smiling_face:

tam.norris
2023-04-21 15:45
ok, thanks for the explanation Yousef.

jack.amico
2023-04-21 15:48
has joined #pact-js

cheng.ngai
2023-04-22 00:55
has joined #pact-js

tam.norris
2023-04-22 13:54
Hi Yousef. Just one more question, Is the only reason you would create the Product class and assert against this because this particular client app uses this class. If this was a contract test between 2 apis could you just as easily do something like ..

tam.norris
2023-04-22 13:54
expect(product).to.deep.equal(expectedProduct); where expectedProduct is ... const expectedProduct = { id: 10, type: "pizza", name: "Margharita"};

aditya.kashyap
2023-04-24 05:13
has joined #pact-js

iustina.gavrila
2023-04-24 09:15
has joined #pact-js

vandana.aveva
2023-04-24 18:24
has joined #pact-js

lucas
2023-04-25 00:01
has joined #pact-js

szydlakus
2023-04-25 11:19
has joined #pact-js

sarah.hutchins
2023-04-25 12:48
has joined #pact-js

kristoffer
2023-04-25 13:31
has joined #pact-js

jack.drake
2023-04-25 15:40
has joined #pact-js

mathivanan.kailasam
2023-04-25 16:15
has joined #pact-js

hornc
2023-04-25 18:00
has joined #pact-js

hulia.suliman
2023-04-25 18:07
has joined #pact-js

markus.nakhlah
2023-04-26 13:44
has joined #pact-js

james414
2023-04-26 16:15
Hi folks! We're attempting to use PactJS to verify the contract between one of our services, and our OIDC auth service - specifically, the `/token` endpoint. As per the OIDC spec, we've implemented the `/token` endpoint to accept a request with `Content-Type` of `application/x-www-form-urlencoded`. The intention was for us to use `fromProviderState` to match the body and allow a valid authentication grant to be generated and injected by the provider tests. However, it seems Pact doesn't currently support matchers on unstructured body content (https://github.com/pact-foundation/pact-js/issues/767). Second attempt - we looked at ignoring the body in the contract spec, and then using `reqFilter` in the `Verifier` to generated and inject the authN grant into the body. But we then ran into an outstanding bug which means unstructured content doesn't get injected correctly into the request body (https://github.com/pact-foundation/pact-js/issues/884). Is there another approach we're missing here? And is there any priority being given to address either of these issues? Many thanks!

tjones
2023-04-26 18:10
I don?t believe Pact supports this yet, and I don?t know what the priorities are. But, why are you testing an OIDC endpoint? Did you hand roll your token negotiation?

james414
2023-04-26 18:13
Thanks Tim. I was mostly checking that I hadn't missed something - if it's not supported, then that's just how it is. We have some customisation of the claims which are yielded in our access token, as well as other configuration changes. We're by no means using Pact as our primary means of testing these, but as a general rule, we aim to use Pact to verify any contract relationships between different components in our architecture.

jean-francois.renaud
2023-04-26 21:09
has joined #pact-js

jakazzy
2023-04-27 06:16
has joined #pact-js

paul
2023-04-27 08:13
I really need to work out why my slack notifications are busted, sorry for the tardy reply here guys. Yes, I'm on the 11.x line. I think my above example is followable, but if you'd like something more concrete let me know and I can try to carve out a little time to put it together.

tjones
2023-04-27 08:35
Have you updated to the latest?

tjones
2023-04-27 08:37
Also, your example above doesn?t have your definition of `StateHandlers`

tjones
2023-04-27 08:38
If you?re using the internally exported `StateHandlers`, then I don?t know why you?d expect `StateHandlers & MessageStateHandlers` to compile. What are you trying to achieve?

tjones
2023-04-27 08:40
The two pact types `StateHandlers` and `MessageStateHandlers` are not compatible

tjones
2023-04-27 08:42
> StateHandlers and MessageStateHandlers their union via VerifierOptions means a StateFuncWithSetup can?t satisfy the MessageStateHandler type. Yes, that?s right. This is the problem that separating the types corrected. In your example, you?re putting them back together?

tjones
2023-04-27 08:42
I don?t know why they are different types to be honest. There?s probably a bigger issue (and maybe a bug) for a maintainer to look at.

matt.fellows
2023-04-27 12:35
Yeah, that?s the use case I?ve seen for JWT validation. Other data comes along in the claims, and that is important to certain functionality.

matt.fellows
2023-04-27 12:35
But as Tim said, we don?t currently support that.

matt.fellows
2023-04-27 12:37
The bugs have been added to a backlog for review, we haven?t published timelines for it yet, so if you wanted to have a look into it you could definitely have a crack at fixing it. #884 is probably relatively simple. #767 would need to be implemented in a Plugin for Pact, or added to the https://github.com/pact-foundation/pact-reference/tree/master/rust

edwin.raju
2023-04-28 11:13
@edwin.raju has left the channel

srinivas.nali
2023-04-28 14:27
has joined #pact-js

dmitriy.tarasevich
2023-04-28 16:00
has joined #pact-js

jigish.mehta
2023-04-28 16:00
has joined #pact-js

juan.felix
2023-04-28 16:01
has joined #pact-js

himesj
2023-04-28 17:25
has joined #pact-js

m.gruehn
2023-04-28 18:26
Hello party people. :upside_down_face: Big fan, thank you for everything you do. I wanted to gather some feedback on a problem I've ran into a while ago. I'm using pact-js and I'm trying to use the method `withRequestMultipartFileUpload` to write a consumer test for one of our endpoints. The https://github.com/pact-foundation/pact-js/blob/master/src/v3/pact.ts#L139 is defined as ``` public withRequestMultipartFileUpload( req: V3Request, contentType: string, file: string, mimePartName: string ): PactV3 { [...] }``` , and I was wondering where the `mimePartName` value is meant to be collected from during the test-execution. I gather that the the `contentType` field is taken from the `content-type` request header, and that the binary `file` is taken from the form data body. Where is the `mimePartName` represented? The test-implementation for this part looks something like ``` .withRequestMultipartFileUpload( { method: 'POST', path: endpoint }, 'multipart/form-data', `${__dirname}/${testFileName}`, 'image/png' // <--- I know that's the mime-type, since the back-end will tell me so )``` During the test-execution, I get the debug-output: ```2023-04-28T17:22:00.413534Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing 'multipart/form-data; boundary=R9kK5VpobMo1Lz7p' to 'multipart/form-data; boundary=--------------------------379308910942565113614489' ==> true cascaded=false matcher=Regex("multipart/form-data;(\\s*charset=[^;]*;)?\\s*boundary=.*") 2023-04-28T17:22:00.413554Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: [BodyMismatch { path: "$", expected: Some(b"image/png"), actual: None, mismatch: "Expected a MIME part 'image/png' but was missing" }]``` The request body of the interaction (as it is implemented by my front-end application) with the actual API-endpoint in the browser looks like shown in the attachments, and there is no mention of the mime-type in the headers as well. Should the `mimePartName` parameter of the function be made optional perhaps, as it seems to be in no way mandatory? I could ask my frond-end team to add a header or another value to the form-data, but why should they send an information that has the be gathered/verified by the back-end anyway? Also, just FYI: I've tried to use the method `withRequestBinaryFile` instead, since it does not require the `mimePartName` parameter to be provided, but the test-execution with that one fails due the boundary not being known beforehand, as it is calculated each time anew: ```2023-04-28T17:11:50.880036Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Request did not match: Request did not match - HTTP Request ( method: POST, path: /assets, query: None, headers: Some({"Content-Type": ["multipart/form-data; boundary=----515823676253717799984874"]}), body: Present(68987 bytes) ) 0) Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'multipart/form-data; boundary=----xxxx' but was 'multipart/form-data; boundary=--------------------------279702090645891265456368' 1) expected 'multipart/form-data;boundary=----xxxx' body but was 'multipart/form-data;boundary=--------------------------279702090645891265456368'``` Thank you for any response on this, highly appreciated! If you would like me to, I could open an issue with the pact-js GitHub repository on this topic. Hope ya'll have a lovely weekend, Martin

syamphaneendrak
2023-04-29 08:31
Hello all, I am setting up PACTV3 JS with Jest for one of my project. I am facing some strange behaviour with it. Can someone please help me. I defined couple of interactions and wrote tests in one js file. When I run all 2 tests together, the second tests is failing but both are passing individually when I ran. The exception I am seeing during the fail was, ``` console.error Error: Error: read ECONNRESET at Object.dispatchError (.....\node_modules\jsdom\lib\jsdom\living\xhr-utils.js:54:19) at Request.<anonymous> (....\node_modules\jsdom\lib\jsdom\living\xmlhttprequest.js:675:20) at Request.emit (node:events:539:35) at Request.onRequestError (........\node_modules\request\request.js:877:8) at ClientRequest.emit (node:events:527:28) at Socket.socketErrorListener (node:_http_client:454:9) at Socket.emit (node:events:527:28) at emitErrorNT (node:internal/streams/destroy:151:8) at emitErrorCloseNT (node:internal/streams/destroy:116:3) at processTicksAndRejections (node:internal/process/task_queues:82:21) undefined at VirtualConsole.<anonymous> (node_modules/jsdom/lib/jsdom/virtual-console.js:29:45) at Object.dispatchError (node_modules/jsdom/lib/jsdom/living/xhr-utils.js:57:53) at Request.<anonymous> (node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:675:20) at Request.onRequestError (node_modules/request/request.js:877:8)```

syamphaneendrak
2023-04-29 08:31
The code is something like, ```it("returns the requested employee", async () => { provider .given("I have an empoyee") .uponReceiving("a request for getting the employee by name") .withRequest({ method: "GET", path: "/api/employees/name/Charles", headers: { Accept: "application/json" }, }) .willRespondWith({ status: 200, headers: { "content-type": "application/json" }, body: GET_EMPLOYEE_BY_NAME_EXPECTED_BODY, }); return provider.executeTest(async (mockserver) => { const employeeService = new EmployeeService(mockserver.url); const response = await employeeService.getEmployeeByName("John"); expect(await response.headers["content-type"]).toEqual( "application/json" ); expect(await response.data).toEqual(GET_EMPLOYEE_BY_NAME_EXPECTED_BODY); expect(await response.status).toEqual(200); }); });```

tjones
2023-04-29 10:39
I only see one test in your code. I would check that you?re awaiting the things that need to be awaited appropriately

tjones
2023-04-29 10:41
Oh, ECONNRESET. There are some breaking changes to the connection pool in some recent version of node. You?ll need to make sure you?re not reusing connections between tests, or that your client is correctly handling a connection reset

syamphaneendrak
2023-04-29 10:42
@tjones Please find the complete file below. ```import { MatchersV3 } from "@pact-foundation/pact"; import EmployeeService from "../../../src/apis/EmployeeService.js"; describe("Employee Clients Service", () => { const GET_EMPLOYEES_EXPECTED_BODY = [ { id: 1, name: "Amy", surname: "Jakline", role: "Software Engineer", }, { id: 2, name: "Jake", surname: "Folker", role: "Test Analyst", }, { id: 3, name: "Charles", surname: "Hucker", role: "Scrum Master", }, { id: 4, name: "Terry", surname: "Roland", role: "Developer", }, { id: 5, name: "Rosa", surname: "Marie", role: "Technical Solution Architect", }, ]; //afterEach(() => provider.verify()); const GET_EMPLOYEE_BY_NAME_EXPECTED_BODY = [ { id: 3, name: "Charles", surname: "Hucker", role: "Scrum Master" }, ]; describe("GET All Employees", () => { it("returns all employees", async () => { provider .given("I have a list of empoyees") .uponReceiving("a request for getting all employees") .withRequest({ method: "GET", path: "/api/employees", headers: { Accept: "application/json" }, }) .willRespondWith({ status: 200, headers: { "content-type": "application/json" }, body: GET_EMPLOYEES_EXPECTED_BODY, }); return provider.executeTest(async (mockserver) => { const employeeService = new EmployeeService(mockserver.url); const response = await employeeService.getEmployees(); console.log("response1: " + response); expect(await response.headers["content-type"]).toEqual( "application/json" ); expect(await response.data).toEqual(GET_EMPLOYEES_EXPECTED_BODY); expect(await response.status).toEqual(200); }); }); }); describe("GET Employee By Name", () => { it("returns the requested employee", async () => { provider .given("I have an empoyee") .uponReceiving("a request for getting the employee by name") .withRequest({ method: "GET", path: "/api/employees/name/Charles", headers: { Accept: "application/json" }, }) .willRespondWith({ status: 200, headers: { "content-type": "application/json" }, body: GET_EMPLOYEE_BY_NAME_EXPECTED_BODY, }); return provider.executeTest(async (mockserver) => { const employeeService = new EmployeeService(mockserver.url); const response = await employeeService.getEmployeeByName("Charles"); console.log("response2: " + response); expect(await response.headers["content-type"]).toEqual( "application/json" ); expect(await response.data).toEqual(GET_EMPLOYEE_BY_NAME_EXPECTED_BODY); expect(await response.status).toEqual(200); }); }); }); });```

tjones
2023-04-29 10:43
Yeah, your test is fine. It?s the connection pool thing, not a pact issue (but you?re more likely to see it with pact, because it starts and stops the server in between each test)

tjones
2023-04-29 10:44
It is actually detecting a mistake with the way your client uses the connection pool

syamphaneendrak
2023-04-29 10:44
ok

syamphaneendrak
2023-04-29 10:45
```import * as path from 'path'; import { PactV3 } from "@pact-foundation/pact"; global.port = 8081 global.provider = new PactV3({ port: global.port, log: path.resolve(process.cwd(), "__tests__/contract/logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "__tests__/contract/pacts"), spec: 2, logLevel: 'INFO', pactfileWriteMode: "overwrite", consumer: "Frontend", provider: "EmployeeService", })```

tjones
2023-04-29 10:45
Also you don?t need to declare your test callback (inside the `it`) as async, but it won?t matter if you do

syamphaneendrak
2023-04-29 10:45
This is how I am setting up

tjones
2023-04-29 10:46
I?m on mobile so I can?t link you, but I wrote a bit about this issue for someone else the other day

tjones
2023-04-29 10:46
I think it was in an issue on the pact-js repo

tjones
2023-04-29 10:46
But you can also find the solution by reading the release notes for node

tjones
2023-04-29 10:47
They changed the http connection pool default behaviour

syamphaneendrak
2023-04-29 10:47
Thank you @tjones

tjones
2023-04-29 10:49
I think it might be an improvement to have pact add a header saying the connection should be closed. But also, if it did that then I think this issue would be masked

itsforbabu
2023-04-29 14:25
has joined #pact-js

tea.trader168
2023-04-30 02:04
has joined #pact-js

matt.fellows
2023-05-01 08:24
> I think it might be an improvement to have pact add a header saying the connection should be closed. But also, if it did that then I think this issue would be masked that?s a good point. Interesting. My gut feel is that it probably still makes sense for us to add that setting, as it feels more ?infrastructure-y? than contract-testing.

matt.fellows
2023-05-01 08:25
Hi Martin! thank you both for the kind words and detailed post. I?ll take a look at this tomorrow :+1:

lori.maurais
2023-05-01 15:27
has joined #pact-js

tam.norris
2023-05-01 18:08
Hi. I have cloned the repo a https://github.com/pact-foundation/pact-js/tree/master/examples and am looking at the typescript example. I can run this fine, however I tried to copy the typescript example folder to a different location on my laptop so that I could use this as a template without the code for other examples. I deleted the node_modules folder and ran npm i again, but when I run the tests I get the error ...TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts". Does anyone know why this is? Is it something to do with the fact that parent package.json or tsconfig.json are not it folder I copied across? Thanks.

tjones
2023-05-01 22:15
yeah, I think you?re right. By default it makes sense for the contract tests to just work on the data. It would be cool to have a ?flaky? mode, with injected failures / problems for people using the mock server to back part of a black box test or something.

tjones
2023-05-01 22:55
Did you also delete package lock?

tjones
2023-05-01 22:57
Ah! This is a mocha problem. When run in-situ, it will be picking up this config file- https://github.com/pact-foundation/pact-js/blob/master/.mocharc.json<https://github.com/pact-foundation/pact-js/blob/master/.mocharc.json| > Which has the typescript settings in it

tjones
2023-05-01 23:05
You?ll need to copy that file in to your directory

matt.fellows
2023-05-02 00:52
> It would be cool to have a ?flaky? mode, with injected failures / problems for people using the mock server to back part of a black box test or something. I?m reminded of this post by Tal when at PageUp: https://medium.com/@rotbart/driving-api-client-resiliency-how-to-enforce-postels-law-by-violating-postel-s-law-4fd6ef9da205

asoni
2023-05-02 01:12
I am not able to npm install node pact package. Getting below error. Did any one encountered and get it resolved? ``` npm i @pact-foundation/pact```

asoni
2023-05-02 01:13
?> pactnode % npm i @greet_bot/pact npm ERR! code 1 npm ERR! path /Downloads/pactnode/node_modules/@pact-foundation/pact-core npm ERR! command failed npm ERR! command sh -c node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@9.3.1 npm ERR! gyp info using node@19.4.0 | darwin | arm64 npm ERR! gyp info find Python using Python version 3.10.11 found at ?/Library/Frameworks/Python.framework/Versions/3.10/bin/python3? npm ERR! gyp http GET https://nodejs.org/download/release/v19.4.0/node-v19.4.0-headers.tar.gz npm ERR! gyp http 200 https://nodejs.org/download/release/v19.4.0/node-v19.4.0-headers.tar.gz npm ERR! gyp http GET https://nodejs.org/download/release/v19.4.0/SHASUMS256.txt npm ERR! gyp http 200 https://nodejs.org/download/release/v19.4.0/SHASUMS256.txt npm ERR! gyp info spawn /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args ?/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py?, npm ERR! gyp info spawn args ?binding.gyp?, npm ERR! gyp info spawn args ?-f?, npm ERR! gyp info spawn args ?make?, npm ERR! gyp info spawn args ?-I?, npm ERR! gyp info spawn args ?/Users//Downloads/pactnode/node_modules/@pact-foundation/pact-core/build/config.gypi?, npm ERR! gyp info spawn args ?-I?, npm ERR! gyp info spawn args ?/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/addon.gypi?, npm ERR! gyp info spawn args ?-I?, npm ERR! gyp info spawn args ?/Users//Library/Caches/node-gyp/19.4.0/include/node/common.gypi?, npm ERR! gyp info spawn args ?-Dlibrary=shared_library?, npm ERR! gyp info spawn args ?-Dvisibility=default?, npm ERR! gyp info spawn args ?-Dnode_root_dir=/Users//Library/Caches/node-gyp/19.4.0?, npm ERR! gyp info spawn args ?-Dnode_gyp_dir=/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp?, npm ERR! gyp info spawn args ?-Dnode_lib_file=/Users//Library/Caches/node-gyp/19.4.0/<(target_arch)/node.lib?, npm ERR! gyp info spawn args ?-Dmodule_root_dir=/Users//Downloads/pactnode/node_modules/@pact-foundation/pact-core?, npm ERR! gyp info spawn args ?-Dnode_engine=v8?, npm ERR! gyp info spawn args ?--depth=.?, npm ERR! gyp info spawn args ?--no-parallel?, npm ERR! gyp info spawn args ?--generator-output?, npm ERR! gyp info spawn args ?build?, npm ERR! gyp info spawn args ?-Goutput_dir=.? npm ERR! gyp info spawn args ] npm ERR! No receipt for ?com.apple.pkg.CLTools_Executables? found at ?/?. npm ERR! npm ERR! No receipt for ?com.apple.pkg.DeveloperToolsCLILeo? found at ?/?. npm ERR! npm ERR! No receipt for ?com.apple.pkg.DeveloperToolsCLI? found at ?/?. npm ERR! npm ERR! gyp info spawn make npm ERR! gyp info spawn args [ ?BUILDTYPE=Release?, ?-C?, ?build? ] npm ERR! xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun npm ERR! gyp ERR! build error npm ERR! gyp ERR! stack Error: `make` failed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.onExit (/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28) npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:293:12) npm ERR! gyp ERR! System Darwin 22.4.0 npm ERR! gyp ERR! command ?/opt/homebrew/Cellar/node/19.4.0/bin/node? ?/opt/homebrew/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js? ?rebuild? npm ERR! gyp ERR! cwd /Users//Downloads/pactnode/node_modules/@pact-foundation/pact-core npm ERR! gyp ERR! node -v v19.4.0 npm ERR! gyp ERR! node-gyp -v v9.3.1 npm ERR! gyp ERR! not ok

tjones
2023-05-02 03:41
You may need the xcode CLI tools. Run `xcode-select --install`

matt.fellows
2023-05-02 04:50
I?m surprised you could do anything else technical without those!

matt.fellows
2023-05-02 04:50
But I suppose we should probably put this in the technical pre-requisites. Good shout Tim

tien.xuan.vo
2023-05-02 05:02
Hi, Should `fromProviderState` be flexible about matcher's type? Currently if I want to use `regex` matcher with `ProviderState` generator, I have to define a custom method like this: ```export function regexFromProviderState( expression: string, regex: string, exampleValue: string ) { return { 'pact:matcher:type': 'regex', 'pact:generator:type': 'ProviderState', expression, value: exampleValue, regex }; }``` I think it will be the same with other matchers.

tjones
2023-05-02 05:12
I?m not sure what you?re trying to do here?

tien.xuan.vo
2023-05-02 05:48
currently matcher `type` is hard coded https://github.com/pact-foundation/pact-js/blob/master/src/v3/matchers.ts. if I use it like this: ```pact.addInteraction({ states: [{ description: 'A user' }], uponReceiving: 'get one user', withRequest: { method: 'GET', path: fromProviderState('${iri}', '/api/users/14f6626f-c51e-4311-ac52-182c8f2a7634') }, willRespondWith: { status: 200, body: { id: '14f6626f-c51e-4311-ac52-182c8f2a7634' }, }, });``` mock server will match with *any* GET request, not with only request with regex that I want `'^\/api\/users\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$'`

tjones
2023-05-02 05:50
This is a development question, I guess?

tjones
2023-05-02 05:50
``` 'pact:matcher:type': 'regex', 'pact:generator:type': 'ProviderState',``` Is this valid?

tjones
2023-05-02 05:50
I don?t actually know.

tien.xuan.vo
2023-05-02 05:51
yes it's valid. I tried it in my personal project

tjones
2023-05-02 05:51
Doesn?t the mock server match `'/api/users/14s....'` etc?

tjones
2023-05-02 05:51
not any string

tjones
2023-05-02 05:52
I thought it was either the string you provide, or the example from the provider state

tien.xuan.vo
2023-05-02 05:52
I tried on my project, it match any `string` . For example `GET /any` it still match

tjones
2023-05-02 05:52
That sounds like a bug to me

tjones
2023-05-02 05:53
The lack of composability in the matchers is one of the things that make me kick off the ContractCase project - where the matchers are fully composable

tjones
2023-05-02 05:54
If you can indeed add a generator like in your example, then I think yes, it?s worth exposing that in the DSL somehow

tien.xuan.vo
2023-05-02 05:54
Let me create a demo project for this bug and then report it


tjones
2023-05-02 06:18
Great example

tien.xuan.vo
2023-05-02 06:43
Here is the ticket https://github.com/pact-foundation/pact-js/issues/1088 I created it as if I am a user, not contributor, so it's easier to read (I think)

tjones
2023-05-02 06:44
Thanks!

damola.thompson
2023-05-02 07:26
has joined #pact-js

damola.thompson
2023-05-02 07:34
Hello :wave: , I have a question regarding how queries are represented in generated contracts. On my interaction I have set up my query as a string but on the contract, my query appears as an array `"method": "GET",` `"path": "/v1/assignments",` `"query": {` `"audienceId": [` `"63f57d805d8ecbf46f5b5278"` `]` `}` Is this normal or can my query appear without being encased in an array?

m.gruehn
2023-05-02 08:57
Thank you!

tjones
2023-05-02 09:30
You can ignore the contents in the contract, it?s essentially opaque

tjones
2023-05-02 09:30
> Is this normal or can my query appear without being encased in an array? Your query is not encased in an array

tjones
2023-05-02 09:31
In the contract file, it?s formatted that way

damola.thompson
2023-05-02 09:34
Thank you @tjones

ivan.v.kurlovich
2023-05-02 13:01
has joined #pact-js

ckulkarni
2023-05-02 14:22
has joined #pact-js

aurel.pintea
2023-05-02 14:55
has joined #pact-js

ariveros142
2023-05-02 20:03
has joined #pact-js

matt.fellows
2023-05-02 22:57
It?s because query parameters can have multiple values, and there is no ?standard? way to represent arrays. The pact file chooses to store it in a data structure that is already an array, presumably because it?s easier to parse

cody.jenkins
2023-05-03 04:48
has joined #pact-js

ashish.tilara
2023-05-03 06:08
has joined #pact-js

alfred.brose00
2023-05-03 08:17
has joined #pact-js

dibya.dhar
2023-05-03 09:04
has joined #pact-js

ronnie.kilsbo
2023-05-03 09:28
has joined #pact-js

caitriona.gallagher
2023-05-03 15:18
has joined #pact-js

majhwar.mragni
2023-05-03 17:03
has joined #pact-js

noor.hashem
2023-05-03 18:13
Hello :wave:, i'm looking to use the matchers feature here: https://github.com/pact-foundation/pact-js/blob/master/src/dsl/matchers.spec.ts I am using the npm package `"pact_foundation_greet/pact": "^9.18.1"` and have a response in the body that can be either a string or null, is anyone aware how can I assert more than one type like a string and/or null using matchers?

tam.norris
2023-05-03 19:41
Thanks. This resolved it (after I changed 'src' to 'test'.

tam.norris
2023-05-03 20:16
What do you mean 'run in situ'?

tam.norris
2023-05-03 20:26
it seems to run tests based on the path specified in the mocharc.json file even if the specific path is specified in the package.json scripts.

michael.fenstermaker
2023-05-03 20:56
has joined #pact-js

man.tse
2023-05-03 20:58
has joined #pact-js

matt.fellows
2023-05-03 21:38
See howtooptional


tristan
2023-05-04 03:27
has joined #pact-js

asoni
2023-05-04 04:03
Hello @tjones I installed xcode and ran npm install again but still got same error. ``` npm install npm ERR! code EBADPLATFORM npm ERR! notsup Unsupported platform for @pact-foundation/pact-node@6.21.5: wanted {"os":"darwin,linux,win32","arch":"x64,ia32"} (current: {"os":"darwin","arch":"arm64"}) npm ERR! notsup Valid OS: darwin,linux,win32 npm ERR! notsup Valid Arch: x64,ia32 npm ERR! notsup Actual OS: darwin npm ERR! notsup Actual Arch: arm64 npm ERR! A complete log of this run can be found in: npm ERR! /Users/asoni/.npm/_logs/2023-05-04T04_02_02_707Z-debug-0.log pactnode % xcode-select --install xcode-select: error: command line tools are already installed, use "Software Update" in System Settings to install updates```

asoni
2023-05-04 04:08
I was following this thread https://github.com/pact-foundation/pact-js-core/issues/264 but it seems i will need to alter my OS to install Rosseta. But this is my office laptop and i do not to alter OS configuration here. ```softwareupdate --install-rosetta --agree-to-license```

tjones
2023-05-04 04:34
Ah! Try the latest line of pact-js

tjones
2023-05-04 04:34
It looks like you are on 9.x

tjones
2023-05-04 04:35
Oh wait, you?re installing pact-node directly

tjones
2023-05-04 04:35
I would install just @pact-foundation/pact

tjones
2023-05-04 04:35
Unless there is some reason that you need pact-node? There shouldn?t be for most use cases

asoni
2023-05-04 04:37
I was installing from package.json. ```I re-tried installing : npm install @pact-foundation/pact``` but same error ? ```npm install @pact-foundation/pact npm ERR! code EBADPLATFORM npm ERR! notsup Unsupported platform for @pact-foundation/pact-node@6.21.5: wanted {"os":"darwin,linux,win32","arch":"x64,ia32"} (current: {"os":"darwin","arch":"arm64"})```

tjones
2023-05-04 04:37
Yes, it looks like you?re on 9.x

asoni
2023-05-04 04:38
Apple M1 Max, 13.3.1 (22E261)

tjones
2023-05-04 04:38
You will need to try 10 or 11 (I recommend the latest)

tjones
2023-05-04 04:38
Pact-node 6.21.5 is very old

asoni
2023-05-04 04:45
Ok installation is now complete. Using below version. ``` "@pact-foundation/pact": "^11.0.2", "@pact-foundation/pact-node": "^10.17.7",```

tjones
2023-05-04 05:13
You do not need to install pact-node

tjones
2023-05-04 05:13
But other than that, that?s all fine

tjones
2023-05-04 05:15
Sorry, by ?run in situ? I meant running the example directly without the rest of pact-js around it. It wasn?t a good way to explain what I meant. Yes, mocha has some unintuitive preference rules

tjones
2023-05-04 05:16
*precedence

tjones
2023-05-04 05:16
I think Jest is more popular these days. Pact doesn?t care which test runner you use

tjones
2023-05-04 05:18
Is there some example somewhere that says to install pact-node? If so, it should be updated

michal.kopriva
2023-05-04 11:03
has joined #pact-js

michal.kopriva
2023-05-04 11:11
Hello all, I am new to Pact world. I am trying to run Pact JS in my company, but as it turns out, Python is for some reason needed for pact js installation. For some company security reasons I am not able to use python. Is there a way, how to install it without python?

tam.norris
2023-05-04 14:13
Ok, thanks Timothy. Think Im just using mocha as that came with example I am learning from and don'r know how to add jest and remove mocha without breaking the whole thing.

tjones
2023-05-04 15:00
It shouldn?t matter which one you use

tjones
2023-05-04 15:01
If you already know Jest, I can put together an example for you over the weekend, but if you don?t know either I would just stick with Mocha

james.jenks
2023-05-04 19:09
has joined #pact-js

abdurrahman.muratt
2023-05-04 20:50
has joined #pact-js

matt.fellows
2023-05-05 09:43
I don't think so, unless you get somebody to compile the native dependency and manual install it into the right location after nom install. See also https://github.com/pact-foundation/pact-js/issues/899

matt.fellows
2023-05-05 09:44
Python is a dependency of node gyp, a common part of the node JS build chain to build native dependencies

michal.kopriva
2023-05-05 10:36
thx, i will look on it

tam.norris
2023-05-05 13:49
Thanks for the offer. I have used jest with other api test frameworks before so should probably give it a go myself. Its not the using of it that will cause me issues its resolving all the conflicts with current framework I am using.

svetoldo444ka
2023-05-05 15:35
has joined #pact-js

svetoldo444ka
2023-05-05 15:49
hello Everyone! Need your help with pact-js. I've tried to install it and I got an error for any version more than 9 - Failed at the pact-core@13.13.8 node version - 14.20.0 npm 6.14.17 angular 15.2.2 Maybe you can help me? Thanks

svetoldo444ka
2023-05-05 19:13
the answer is simple - the latest stable node version :slightly_smiling_face:

matt.fellows
2023-05-05 23:38
It should work on 14, 16 and 18. What's the actual error you're seeing?

svetoldo444ka
2023-05-06 08:16
After I've updated the node version from 14 to 18 the pact installed without any errors

matt.fellows
2023-05-08 00:38
strange. We test on the above versions, so perhaps something is corrupt/misconfigured or something else is going on

matt.fellows
2023-05-08 00:38
If you could share the errors, that might help us find the problem

arjun.gowda
2023-05-08 17:07
has joined #pact-js

m.gruehn
2023-05-09 11:16
Hi @matt.fellows. Did you have a chance to look into this behavior by chance? My front-end devs are waiting on an update from my side. Thanks!

valencianaad
2023-05-09 15:04
has joined #pact-js

tam.norris
2023-05-09 16:17
Hi. I am getting the error 'Error: Error in native callback'. However I believe my code already has suggestions that Ivan made above. Does anyone know why this error might be occuring?

marlon.jimenez
2023-05-09 17:53
has joined #pact-js

erollins
2023-05-09 18:49
has joined #pact-js

marcos.aruj
2023-05-09 23:39
has joined #pact-js

matt.fellows
2023-05-10 05:25
It's usually a logic error on a test, can you please share your code?

meritxell.rodriguez
2023-05-10 06:33
has joined #pact-js

tam.norris
2023-05-10 07:29
Hi Matt.

tam.norris
2023-05-10 07:30
```import { PactV3 } from "@pact-foundation/pact"; import { ProductApiClient } from "../../clients/product/getProducts_client1"; import { MatchersV3 } from "@pact-foundation/pact"; import { Product2 } from "../../models/product2"; const { eachLike, like } = MatchersV3; const Pact = PactV3; // const mockProvider = new Pact({ // consumer: 'pactflow-example-consumer', // provider: process.env.PACT_PROVIDER // ? process.env.PACT_PROVIDER // : 'pactflow-example-provider' // }); const mockProvider = new Pact({ consumer: "products-consumer2", provider: "products-provider", //cors: true, // needed for katacoda environment }); describe("API Pact test", () => { it("ID 10 exists", async () => { // Arrange const expectedProduct = { id: 10, type: "pizza", name: "Margharita" }; // Uncomment to see this fail // const expectedProduct = { id: '10', type: 'CREDIT_CARD', name: '28 Degrees', price: 30.0, newField: 22} mockProvider .given("a product with ID 10 exists") .uponReceiving("a request to get a product") .withRequest({ method: "GET", path: "/products/10", }) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: like(expectedProduct), }); return mockProvider.executeTest(async (mockserver) => { // Act const api = new ProductApiClient(mockserver.url); const product = await api.getProduct(10); // Assert - did we get the expected response expect(product).toStrictEqual(new Product2(10, "Margharita", "pizza")); return; }); }); it("product does not exist", async () => { // set up Pact interactions mockProvider .given("a product with ID 11 does not exist") .uponReceiving("a request to get a product") .withRequest({ method: "GET", path: "/products/11", headers: { Authorization: like("Bearer 2019-01-14T11:34:18.045Z"), }, }) .willRespondWith({ status: 404, }); return mockProvider.executeTest(async (mockserver) => { const api = new ProductApiClient(mockserver.url); // make request to Pact mock server await expect(api.getProduct(11)).rejects.toThrow( "Request failed with status code 404" ); return; }); }); });```

tam.norris
2023-05-10 07:34
I got it from https://github.com/pactflow/example-consumer/tree/master. However I am using typescript rather than javascript. I also needed to change the test statements to 'it' as was getting 'test is not defined'. Finally I added this particular pact.spec.ts file to an existing repo where I have other pact.spec files that are working fine, although in those I am using chai assertions. I wanted to switch to jest as had been told that this is the more popular library. Not sure if any of that is relevant to this error i.e. chai could be conflicting with jest.

tjones
2023-05-10 07:43
Please format with triple backticks

tjones
2023-05-10 07:55
**triple** backticks :wink:


tjones
2023-05-10 07:56
Anyway, what is the exact error (including stack trace) that you?re getting?

tam.norris
2023-05-10 07:58
1) ID 10 exists 2 passing (103ms) 1 failing 1) API Pact test ID 10 exists: Error: Error in native callback at mockServerMismatches (/Users/tam.norris/Documents/Projects/My-Projects/Contract-Testing/typescript/node_modules/@pact-foundation/pact-core/src/consumer/internals.ts:10:9) at Object.mockServerMismatches (/Users/tam.norris/Documents/Projects/My-Projects/Contract-Testing/typescript/node_modules/@pact-foundation/pact-core/src/consumer/index.ts:123:27) at PactV3.<anonymous> (/Users/tam.norris/Documents/Projects/My-Projects/Contract-Testing/typescript/node_modules/@pact-foundation/src/v3/pact.ts:207:39) at step (/Users/tam.norris/Documents/Projects/My-Projects/Contract-Testing/typescript/node_modules/@pact-foundation/pact/src/v3/pact.js:33:23) at Object.throw (/Users/tam.norris/Documents/Projects/My-Projects/Contract-Testing/typescript/node_modules/@pact-foundation/pact/src/v3/pact.js:14:53) at rejected (/Users/tam.norris/Documents/Projects/My-Projects/Contract-Testing/typescript/node_modules/@pact-foundation/pact/src/v3/pact.js:6:65) at processTicksAndRejections (node:internal/process/task_queues:96:5

tjones
2023-05-10 08:02
Does this happen on the latest version of pact-js?

tjones
2023-05-10 08:02
(11.0.2)


tjones
2023-05-10 08:11
This is a bug

tjones
2023-05-10 08:11
``` .uponReceiving("a request to get a product")``` ^ This needs to be unique if the request is different

tjones
2023-05-10 08:11
You can fix this by changing the name

tjones
2023-05-10 08:12
The bug is that pact is exploding instead of complaining

tjones
2023-05-10 08:12
But it?s not valid to send two different requests with the same name

tjones
2023-05-10 08:13
Also, it looks like whatever version of pact-js you have has a corrupt sourcemap - there shouldn?t be a mix of JS and TS files in the stack trace, only TS

tjones
2023-05-10 08:13
(that?s not your problem, I?m mentioning it so a maintainer can add it to the backlog)

tam.norris
2023-05-10 08:14
ok, when you say install latest version of pact-js is this part of the "@greet_bot/pact": "^10.4.1",?

tam.norris
2023-05-10 08:14
My package.json doesn't have a specific pact-js library.

tjones
2023-05-10 08:14
change that to: ``` "@pact-foundation/pact": "^11.0.2",```

tjones
2023-05-10 08:15
You can find out what you currently have with `npm ls @pact-foundation/pact`

tjones
2023-05-10 08:16
My psychic powers tell me you have 10.1.4, because that?s what?s in the package-lock on that example repo you linked

tjones
2023-05-10 08:16
And pact-core 13.9.1

tam.norris
2023-05-10 08:19
Its 10.4.1

tjones
2023-05-10 08:22
Yes. Does this still happen if you: 1) Change package.json to 11.0.3 2) run `npm install` 3) Change the `uponReceiving` lines so that each test has a different value

tam.norris
2023-05-10 08:24
Thanks Timothy. I'll give that a go soon.

tam.norris
2023-05-10 08:25
I get this ...

tam.norris
2023-05-10 08:25
BG-MAC049:typescript tam.norris$ npm i npm ERR! code ETARGET npm ERR! notarget No matching version found for @greet_bot/pact@11.0.3. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist. npm ERR! A complete log of this run can be found in: npm ERR! /Users/tam.norris/.npm/_logs/2023-05-10T08_25_31_195Z-debug-0.log

tjones
2023-05-10 08:27
Sorry, I meant 11.0.2

tjones
2023-05-10 08:27
As above

tam.norris
2023-05-10 08:35
ok, thanks. Im no longer getting this error, but getting a new one. Although I think this is related to my apiClient. I'll try and resolve this on my own. Thanks again.

tjones
2023-05-10 08:36
You?re welcome!

yana.kliuch
2023-05-10 08:58
has joined #pact-js

tam.norris
2023-05-10 10:01
Hi Timothy. Sorry now I am getting 'ReferenceError: expect is not defined'. With my other consumer pacts that are using chai I declare a expect constant like 'const expect = chai.expect;'. Do I need to do something similar with jest?

yousafn
2023-05-10 10:59
jest comes with its own assertion engine https://jestjs.io/docs/expect Whereas with mocha is a test runner and you use chai as the assertion engine

tam.norris
2023-05-10 12:34
Thanks Yousaf. I followed info at https://jestjs.io/docs/getting-started#using-typescript. Had to make a few other changes. Running scripts with '"test:Jestconsumer": "jest --runInBand --testRegex 'test/consumer_pact_specs/productJest/product.consumer3.pact.spec.ts'",'. Have new issues now but atleast the contract pact is running. Thanks again.

tjones
2023-05-10 12:49
Sorry, I was a way from the computer. You can tell typescript that jest is defined in your tsconfig. You may also need @types/jest, although I don?t remember

tam.norris
2023-05-10 12:52
Hi Tim. Yeah I was required to install @types/jest, Thanks.

tam.norris
2023-05-10 12:54
I didn't change tsconfig but added a babel.config.js file and populated with ..

tam.norris
2023-05-10 12:54
`module.exports = {` `presets: [` `['@babel/preset-env', {targets: {node: 'current'}}],` `'@babel/preset-typescript',` `],` `};`

tam.norris
2023-05-10 12:55
Added import {describe, expect, test} from '@jest/globals'; to my pact.spec.ts file.

james.brown
2023-05-10 14:01
has joined #pact-js

mark.bursnall
2023-05-10 14:01
has joined #pact-js

alexandru.simion
2023-05-10 14:01
has joined #pact-js

giulio.giovannini
2023-05-10 14:01
has joined #pact-js

razvan.grigorescu
2023-05-10 14:04
has joined #pact-js

henry.rutman
2023-05-10 18:28
has joined #pact-js

simondemartini
2023-05-10 19:53
has joined #pact-js

prajapati.pravesh
2023-05-11 02:06
@here I am using above workshop to test the pact broker. https://github.com/pact-foundation/pact-workshop-js/tree/step11#step-11---using-a-pact-broker I generated the contract as mentioned in step5. Now I wanted to skip directly on step11 and upload that contract to pact broker. for this i switched to step5 and did docker-compose up then added ``` "pact:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx @pact-foundation/absolute-version)\" --auto-detect-version-properties --broker-base-url=http://localhost:8000 --broker-username pact_workshop --broker-password pact_workshop"``` to package.json in consumer and again executed the test but when i tried to publish by using command ```npm run pact:publish --prefix consumer``` but getting below error ```npm WARN deprecated @pact-foundation/absolute-version@0.0.4: Package @pact-foundation/absolute-version has been renamed absolute-version. Please install absolute-version instead {"errors":{"pacticipantVersionNumber":["pacticipantVersionNumber cannot contain multiple lines"]}}``` any solution to overcome this? ``` ```

tjones
2023-05-11 03:10
```Package @pact-foundation/absolute-version has been renamed absolute-version. Please install absolute-version instead``` As per this :point_up: instruction in your error message, try: ``` "pact:publish": "pact-broker publish ./pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=http://localhost:8000 --broker-username pact_workshop --broker-password pact_workshop"```

stefan.kemp
2023-05-11 07:42
has joined #pact-js

yousafn
2023-05-11 08:30
please don?t use the @ here tag, you?ll notice it?s disabled as we don?t 3k members phones to all beep at the same time. this is a community forum and people will answer if and when they can

supersmile2009
2023-05-11 12:06
has joined #pact-js

lknaresh2
2023-05-11 18:20
has joined #pact-js

siddharth12345
2023-05-12 09:47
has joined #pact-js

siddharth.shetty
2023-05-12 09:51
has joined #pact-js

lukemstorey
2023-05-12 13:52
has joined #pact-js

yousafn
2023-05-12 16:01
Thank you! welcome and good luck in your Pact journey

rana
2023-05-13 20:56
has joined #pact-js

anatoliy.ganzyuk
2023-05-14 20:15
has joined #pact-js

minhajsid
2023-05-15 10:18
has joined #pact-js

artur.ashyrov984
2023-05-15 16:01
has joined #pact-js

jerson.zuniga
2023-05-15 20:25
has joined #pact-js

sekumar
2023-05-15 21:05
has joined #pact-js

jzunigacoayla
2023-05-15 21:41
has joined #pact-js

matthieu.saleta
2023-05-16 09:31
has joined #pact-js

carls.stfleur
2023-05-16 12:20
has joined #pact-js

dale
2023-05-16 16:01
has joined #pact-js

curb1968
2023-05-17 03:41
has joined #pact-js

robert.turner
2023-05-17 12:26
has joined #pact-js

jsanthakumar
2023-05-18 09:47
has joined #pact-js

rmodrego
2023-05-18 09:47
has joined #pact-js

clm.whyte
2023-05-18 09:48
has joined #pact-js

fdonald
2023-05-18 09:52
has joined #pact-js

mgarcia
2023-05-18 09:53
has joined #pact-js

lsantarelli
2023-05-18 10:26
has joined #pact-js

bdocherty
2023-05-18 11:56
has joined #pact-js

srikanth_vemuri
2023-05-18 12:08
has joined #pact-js

perera.x.roshni
2023-05-18 12:16
has joined #pact-js

mohitkrishna.s.s12
2023-05-18 13:23
has joined #pact-js

mohitkrishna.s.s12
2023-05-18 13:37
Hello team,

mohitkrishna.s.s12
2023-05-18 13:39
iam getting below error when i tired to install pact using npm package (npm install --save-dev @pact-foundation/pact) and i have node-gyp and pyhton and visual studio desktop development with c++

mohitkrishna.s.s12
2023-05-18 13:39
npm ERR! code 1 npm ERR! path C:\Users\mohit\Desktop\pact-poc\example-consumer\node_modules\@pact-foundation\pact-core npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using node-gyp@8.2.0 npm ERR! gyp info using node@16.13.0 | win32 | x64 npm ERR! gyp info find Python using Python version 3.11.3 found at "C:\Users\mohit\AppData\Local\Programs\Python\Python311\python.exe" npm ERR! gyp ERR! find VS npm ERR! gyp ERR! find VS msvs_version was set from command line or npm config npm ERR! gyp ERR! find VS - looking for Visual Studio version 2017 npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt npm ERR! gyp ERR! find VS unknown version "undefined" found at "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" npm ERR! gyp ERR! find VS unknown version "undefined" found at "C:\Program Files\Microsoft Visual Studio\2022\Community" npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use npm ERR! gyp ERR! find VS looking for Visual Studio 2015 npm ERR! gyp ERR! find VS - not found npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 npm ERR! gyp ERR! find VS npm ERR! gyp ERR! find VS valid versions for msvs_version: npm ERR! gyp ERR! find VS npm ERR! gyp ERR! find VS ************************************************************** npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload. npm ERR! gyp ERR! find VS For more information consult the documentation at: npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows npm ERR! gyp ERR! find VS ************************************************************** npm ERR! gyp ERR! find VS npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use npm ERR! gyp ERR! stack at VisualStudioFinder.fail (C:\Users\mohit\AppData\Roaming\nvm\v16.13.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47) npm ERR! gyp ERR! stack at C:\Users\mohit\AppData\Roaming\nvm\v16.13.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16 npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Users\mohit\AppData\Roaming\nvm\v16.13.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14) npm ERR! gyp ERR! stack at C:\Users\mohit\AppData\Roaming\nvm\v16.13.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14 npm ERR! gyp ERR! stack at C:\Users\mohit\AppData\Roaming\nvm\v16.13.0\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16 npm ERR! gyp ERR! stack at C:\Users\mohit\AppData\Roaming\nvm\v16.13.0\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7 npm ERR! gyp ERR! stack at C:\Users\mohit\AppData\Roaming\nvm\v16.13.0\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16 npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:404:5) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:390:28) npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1064:16) npm ERR! gyp ERR! System Windows_NT 10.0.22621 npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\mohit\\AppData\\Roaming\\nvm\\v16.13.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd C:\Users\mohit\Desktop\pact-poc\example-consumer\node_modules\@pact-foundation\pact-core npm ERR! gyp ERR! node -v v16.13.0 npm ERR! gyp ERR! node-gyp -v v8.2.0 npm ERR! gyp ERR! not ok npm ERR! A complete log of this run can be found in:

dwayne.sykes
2023-05-18 16:23
has joined #pact-js

tam.norris
2023-05-18 16:58
Hi. I am new to pactflow and contract testing. I have been looking at the example provided at https://killercoda.com/pactflow/scenario/pactflow-getting-started-js But I was wondering how I can extend this to include tests for a product that does not exist i.e. to check that we get a 404 and valid error message. Would I need to modify the client to include a catch block and return an error response e.g. something like ... `async getProduct(id: number) {` `return axios` `.get(`${this.url}/products/${id}`)` `.then((r: any) => new Product(r.data.id, r.data.name, r.data.type))` `.catch((e: any) => new ErrorResponse(e.data.errorCode, e.data.errorMessage))` `}`

yousafn
2023-05-18 20:12
axios throws on non 2xx errors so you need to change your test code to expect it to return with a rejected promise and check the result, assuming you want your code to return the error to whatever code in your app called the api collaborator. if not you can handle the error case in your api client, and do whatever businessey behaviour you want, then use Pact to assert that your api collaborator behaves as you expect it to, when you've got your provider in a state when it will return an error

yousafn
2023-05-18 20:13
there will lots of resources on the internet about error handling in axios :+1:

tam.norris
2023-05-18 20:58
I'm still pretty confused. So this is my test in my consumer pact spec. `it("product does not exist", async () => {` `// set up Pact interactions` `const expectedError = { errorCode: '1223', errorMessage: 'Product not found' };` `mockProvider` `.given("a product with ID 11 does not exist")` `.uponReceiving("a request to get a product that doesn't exist")` `.withRequest({` `method: "GET",` `path: "/products/11"` `})` `.willRespondWith({` `status: 404,` `body: like(expectedError)` `});` `return mockProvider.executeTest(async (mockserver) => {` `const api = new ProductApiClient(mockserver.url);` `const errorResponse = await api.getProduct(11);` `expect(errorResponse).toEqual(new ErrorResponse('1223', 'Product not found'));` `return;` `});` `});` But this results in TypeError: Cannot read properties of undefined (reading 'errorCode')

yousafn
2023-05-18 23:05
I don't know if this helps, https://github.com/pactflow/pact-msw-adapter/pull/94/files#diff-b46ef3cd00c413a1774590ff2e72f13c6e7433bdc5867af7952ce64ef49dccae I came across a different in the error handling in node 20 today, or well on node 20, I got 2 econn refused, only trying localhost the other trying the loopback address

matt.fellows
2023-05-18 23:07
I think the issue is that the `e.data` does not exist on the error object. Axios (from googling) returns it as `e.response` https://github.com/axios/axios/issues/376#issuecomment-238034016

matt.fellows
2023-05-18 23:07
So it?s probably just `new ErrorResponse(e.response.errorCode, e.response.errorMessage)` type thing.

matt.fellows
2023-05-18 23:07
but suffice to say yes, you can definitely test 4xx :stuck_out_tongue:

kancharla.g
2023-05-19 03:31
has joined #pact-js

tam.norris
2023-05-19 13:33
ok, thanks I've managed to make some progress on this. I found this article 'https://docs.pact.io/implementation_guides/javascript/docs/troubleshooting' which was useful. I changed my consumer spec to be ... `it("product does not exist", async () => {` `// set up Pact interactions` `const expectedError = { errorCode: 'ERR_BAD_REQUEST', errorMessage: 'Request failed with status code 404' };` `mockProvider` `.given("a product with ID 11 does not exist")` `.uponReceiving("a request to get a product that doesn't exist")` `.withRequest({` `method: "GET",` `path: "/products/11"` `})` `.willRespondWith({` `status: 404,` `body: like(expectedError)` `});` `return mockProvider.executeTest(async (mockserver) => {` `const api = new ProductApiClient(mockserver.url);` `await expect(api.getProduct2(11)).rejects.toMatch('Request failed with status code 404');` `return;` `});` `});`

tam.norris
2023-05-19 13:37
and my getProduct client function to be .. `async getProduct2(id: number) {` `try {` `return await axios` `.get(`${this.url}/products/${id}`)` `.then((r: any) => new Product(r.data.id, r.data.name, r.data.type));` `} catch (error) {` `if (error.errors && error.errors.length > 0) {` `return Promise.reject(new Error(error.errors));` `} else {` `const errorResponse = new ErrorResponse(error.response.data.errorCode, error.response.data.errorMessage )` `return Promise.reject(error.response.data.errorMessage)` `}` `}` `}` Above will only work for a single error and just returning the error message. Would like to now see if I can extend it to return the whole error response and validate against that.

tam.norris
2023-05-19 14:53
I would like to be able to match on the whole error response but when I change my client to ... `catch (error) {` `if (error.errors && error.errors.length > 0) {` `return Promise.reject(new Error(error.errors));` `} else {` `const errorResponse = new ErrorResponse(` `error.response.data.errorCode,` `error.response.data.errorMessage` `);` `error.response.data.errorMessage));` `return Promise.reject(errorResponse);` `}` `}` but then in my consumer spec test I have.... `await expect(api.getProduct2(11)).rejects.toMatch(new ErrorResponse('ERR_BAD_REQUEST', 'Request failed with status code 404'));` This gives me error .... Argument of type 'ErrorResponse' is not assignable to parameter of type 'string | RegExp'.

joseantonionmfilho
2023-05-19 17:46
has joined #pact-js

anenada
2023-05-20 08:06
has joined #pact-js

tam.norris
2023-05-20 12:52
Found the solutions for this. Used toEqual instead of toMatch so ... `await expect(api.getProduct2(11)).rejects.toEqual(new ErrorResponse('ERR_BAD_REQUEST', 'Request failed with status code 404'));`

rabrosimov
2023-05-20 20:11
has joined #pact-js

arm.arturpetrosyan
2023-05-22 10:37
has joined #pact-js

adra_verma
2023-05-22 12:11
has joined #pact-js

p.keshav.chainani
2023-05-22 12:13
has joined #pact-js

divya.s.parappanavar
2023-05-22 12:13
has joined #pact-js

tam.norris
2023-05-22 14:12
Hi. I am getting the error 'Cannot log after tests are done. Did you forget to wait for something async in your test?' for the following provider test Cannot log after tests are done. Did you forget to wait for something async in your test? `import { Verifier } from "@pact-foundation/pact";` `import { server } from "../providers/product.provider";` `import { describe, beforeAll, beforeEach, test } from "@jest/globals";` `describe("Pact Verification", () => {` `// (1) Starting the Provider API` `beforeAll( () => server.listen(8081));` `afterAll( () => {` `if (server) {` `server.close();` `}` `});` `it("validates the expectations of ProductService", async () => {` `// (2) Telling Pact to use the contracts stored in PactFlow and where the Product API will be running` `const opts: any = {` `logLevel: "INFO",` `providerBaseUrl: "http://localhost:8081",` `providerVersion: "1.0.0-someprovidersha",` `provider: "products-provider",` `providerBranch: "main",` `consumerVersionSelectors: [{ branch: "main" }],` `pactBrokerUrl: process.env.PACT_BROKER_BASE_URL,` `// pactUrls: [` `// `${process.env.PWD}/pacts/katacoda-consumer-katacoda-provider.json`,` `// ],` `publishVerificationResult: true,` `enablePending: true,` `};` `// (3) Running the Provider verification task` `return new Verifier(opts).verifyProvider().then((output: any) => {` `console.log("Pact Verification Complete!");` `});` `});` `});` With the option --detectOpenHandles added in my package.json jest command I get ... TCPSERVERWRAP 9 | 10 | //beforeAllasync((done: any) => server.listen(8081, done)); > 11 | beforeAll( () => server.listen(8081)); | ^ 12 | 13 | afterAll( () => { 14 | if (server) { at Function.listen (node_modules/express/lib/application.js:635:24) at Object.listen (test/provider_pact_specs/product.provider.pact.spec.ts:11:27) ? TCPSERVERWRAP 37 | 38 | // (3) Running the Provider verification task > 39 | return new Verifier(opts).verifyProvider().then((output: any) => { | ^ 40 | console.log("Pact Verification Complete!"); 41 | }); 42 | }); But Im not really sure how to fix these. From stackoverflow I found that I can add the --forceExit option to jest cl command, but is there a better way of writing this code so that I don't need this? Thanks.

n.duran
2023-05-22 14:38
has joined #pact-js

tam.norris
2023-05-22 15:25
Hi, I have the following in my pact consumer test.. `return mockProvider.executeTest(async (mockserver) => {` `// Act` `const metersResponse = await callMeters(mockserver.url,'sgegegeg','2100040885876');` `console.log('Type of meters resposne ' + typeof(metersResponse))` `console.log('metersResponse is ' + JSON.stringify(metersResponse));` `// Assert - did we get the expected response` `expect(metersResponse.meters.postcode).toEqual("SW11"); //expect(product).toStrictEqual(JSON.stringify(expectedProduct));` `return;` `});` This is saying that received is undefined. However when I print the response in the console log above I do get an actual response i.e. ... ```[ { "errors":[ ], "meters":[ { "address":{ "address_line_1":null, "address_line_2":"SELECT", "address_line_3":"TW23", "address_line_4":null, "address_line_5":"ST DAVIDS ONE", "address_line_6":null, "address_line_7":"ST DAVIDS CENTRE", "address_line_8":"CARDIFF", "address_line_9":"SOUTH GLAMORGAN", "postcode":"CF10" }``` It doesn't work if I have metersResponse,meters[0].postcode either. Can anyone tell me what I am doing wrong? Also is the whole response being put in square brackets just the result of the stringify function?

n.duran
2023-05-22 20:28
did you try to install it globally?

tam.norris
2023-05-22 21:04
Hi. For above. This is the client that I am using ... `interface MetersResponse {` `errors: any[]` `meters: any[]` `}` `const callEcoes = async (url: string, authToken: string, meters: string): Promise<MetersResponse> => {` `const response = await fetch(`${url}/api/v1/meters`, {` `method: 'POST',` `headers: {` `Authorization: authToken,` `'Content-Type': 'application/json'` `},` `body: JSON.stringify({` `meters: meters` `})` `})` `return (await response.json() as MetersResponse)` `}` `export { callEcoes, MetersResponse }` This is my mock provider code within consumer spec .. `return mockProvider.executeTest(async (mockserver) => {` `// Act` `const metersResponse: MetersResponse = await callMeters(mockserver.url,'sgegegeg','2100040885876');` `console.log('Type of meters response ' + typeof(metersResponse.meters[0]))` `console.log('metersResponse is ' + metersResponse.meters[0]);` `// Assert - did we get the expected response` `expect(metersResponse.meters[0].meter).toEqual("2100040885876"); //expect(product).toStrictEqual(JSON.stringify(expectedProduct));` `return;` When this runs I get the error on the console log of TypeError: Cannot read properties of undefined (reading '0'). If I just remove the .meters[0] then the whole response gets printed to the console but its inside square brackets. Can someone tell me why this response is coming back inside square brackets as this seems to be why I can't validate my assertion on the response. Thanks.

matt.fellows
2023-05-22 23:17
When you say ?square brackets?, do you mean array?

matt.fellows
2023-05-22 23:17
We?d need to see the test definition, remember Pact is just going to send back the body you asked it to

matt.fellows
2023-05-22 23:18
also, you can improve the formatting using triple backticks ``` (or using the ?code block? formatting item)

tjones
2023-05-23 00:06
~You are not using the lifecycle hooks correctly. Check the examples.~

tjones
2023-05-23 00:07
```afterAll( () => { if (server) { server.close(); } });``` ~^ Where did you get this from?~

tjones
2023-05-23 00:07
Oh, wait, apologies - I thought this was a consumer test

tjones
2023-05-23 00:08
I think your server is staying alive after the end of the tests

tjones
2023-05-23 00:08
``` server.close();``` ^ Is this async?

tjones
2023-05-23 00:10
Also, this isn't your problem, but you can remove the `async` from your `it` function, because you're returning a promise.

mohitkrishna.s.s12
2023-05-23 06:23
yes i installed node-gyp globally

tam.norris
2023-05-23 07:10
Thanks Matt. Here is my entire consumer pact spec (although I cut down the expected response for brevity. And yes its returned inside an array. ```import { PactV3 } from "@pact-foundation/pact"; import { MatchersV3 } from "@pact-foundation/pact"; import { callMeters, MetersResponse } from '../../../lambda/helpers/call-meters'; import axios, {AxiosResponse} from 'axios'; import { MetersResonse } from "../models/MetersResponse"; const { like, eachLike } = MatchersV3; const Pact = PactV3; const mockProvider = new Pact({ consumer: "cs-consumer", provider: "db-provider", }); describe("API Pact test", () => { it("meter exists", async () => { const expectedMetersResponse = { "errors": [], "meters": [ { "meter": "2100040885876", "topline": { "llf": "N13", "mtc": "801", "profile": "03" ... } } const EXPECTED_BODY = MatchersV3.eachLike(expectedMetersResponse); type metersRequestBody_T = { meters: string; } const reqBodyExample: metersRequestBody_T = { meters: "2100040885876" } mockProvider .given("a meter with meter core 2100040885876 exists") .uponReceiving("a request to get meter details with a valid meter") .withRequest({ method: "POST", path: "/api/v1/meters", headers: { 'Content-Type': 'application/json' }, body: like(reqBodyExample), }) .willRespondWith({ status: 200, headers: { "Content-Type": "application/json; charset=utf-8", }, body: like(EXPECTED_BODY), }); return mockProvider.executeTest(async (mockserver) => { // Act const metersResponse = await callMeters(mockserver.url,'sgegegeg','2100040885876'); console.log('metersResponse is ' + metersResponse.meters[0]); // Assert - did we get the expected response expect(metersResponse.meters[0].meter).toEqual("2100040885876"); return; }); }) });``` ``````

matt.fellows
2023-05-23 07:32
Thanks! > ```const EXPECTED_BODY = MatchersV3.eachLike(expectedMetersResponse);``` This says ?I expect an *array* that has items *each* of which has the shape `expectedMetersResponse`?

matt.fellows
2023-05-23 07:33
That?s why it?s an array

matt.fellows
2023-05-23 07:34
If you just want to match on the type, and cascade that, just use `like`

tam.norris
2023-05-23 07:38
Great! Thanks a lot. Matching correctly now and tests passing.

garry.wilson
2023-05-23 12:28
has joined #pact-js

verevad
2023-05-23 13:04
has joined #pact-js

jon.arambarri
2023-05-24 07:34
has joined #pact-js

yonatany
2023-05-24 08:14
has joined #pact-js

scoplin
2023-05-24 20:02
has joined #pact-js

aemanuelson
2023-05-25 23:41
has joined #pact-js

sreenivas.chaitanya
2023-05-26 08:29
has joined #pact-js

tigrandza
2023-05-26 08:46
has joined #pact-js

sreenivas.chaitanya
2023-05-26 09:53
Hi All, iam a new user to pact , iam using pact with message queues , iam trying to follow the dog example on the github

sreenivas.chaitanya
2023-05-26 09:53
```export type LogIds = { session_id: string, client_id: string, persistent_session_id: string, client_session_id: string, request_id: string, }; export function auditApiHandler(logIds: LogIds): void { if (!logIds.client_id || !logIds.client_session_id || !logIds.persistent_session_id || !logIds.request_id || !logIds.session_id ) { throw new Error('Missing fields in the Audit Message '); } return; } verify(synchronousBodyHandler(auditApiHandler)); - error TS2345: Argument of type '(logIds: LogIds) => void' is not assignable to parameter of type '(body: AnyJson | Buffer) => void'. Types of parameters 'logIds' and 'body' are incompatible. Type 'AnyJson | Buffer' is not assignable to type 'LogIds'. Type 'null' is not assignable to type 'LogIds'. 39 .verify(synchronousBodyHandler(auditApiHandler));``` in my spec class iam getting error on synchronousbody handler

tle
2023-05-26 09:56
has joined #pact-js

yousafn
2023-05-26 12:52
:wave: can you show your full test code please Have you been able to get the example running out of interest (the dog example, not your own)

adam699
2023-05-26 13:35
has joined #pact-js

sreenivas.chaitanya
2023-05-26 14:39
I managed to solve this error by myself thanks

yousafn
2023-05-26 14:44
Care to share your solution for others? and no problem

matt.fellows
2023-05-29 00:36
The latest version of Pact JS should have that type error fixed

mariusz.kapczynski
2023-05-29 12:10
has joined #pact-js

kazimierz.zarychta
2023-05-29 12:10
has joined #pact-js

morin.td
2023-05-30 11:44
Hello Pact familly, I used Pact in the past, but I wanted to improve my configuration. Unfortunately, I don't know how to do the following, or if that's even possible: I have two test suites, one for unit tests (that don't use pacts), and another specifically for pacts. Is that a better practice to include my Pact tests directly into my unit tests suite (I'm wondering about watch mode too)? Also, I'm doing this because all my pact tests for a single provider-consumer pair are in the same file. This is because if I have multiple files, they override the generated Pact file, and I end up with only the expected message of the test I ran last. I'm using a `MessageConsumerPact` : ``` pact = new MessageConsumerPact({ consumer: '<consumer-name>', dir: path.resolve(process.cwd(), 'pacts'), pactfileWriteMode: 'merge', provider: '<provider-name>', logLevel: 'info', });``` Would appreciate some help :pray:

matt.fellows
2023-05-30 11:50
With the latest version of Pact, you should be able to (more easily) split tests across files

matt.fellows
2023-05-30 11:51
Assuming you?re on the 9.x.x line, you could use this tip to split tests across files: https://github.com/pact-foundation/pact-js/tree/9.x.x#splitting-tests-across-multiple-files

matt.fellows
2023-05-30 11:52
The key trick is properly clearing out the pact files before the entire suite of tests run. But even locally it?s not that important, if you only publish pacts from CI

matt.fellows
2023-05-30 11:52
> I have two test suites, one for unit tests (that don?t use pacts), and another specifically for pacts. I tend to keep them separate. One of the benefits is that you can use code coverage tools to get some idea of what code paths are tested with Pact

morin.td
2023-05-30 12:02
Thanks a lot of the answers @matt.fellows :pray: If I keep the test suites separate I don't mind having Pact tests in the same file. Does that mean you have some overlap between your unit and pact test suites? Or some cases are not covered by unit tests but tested by Pact tests?

matt.fellows
2023-05-30 12:04
> Does that mean you have some overlap between your unit and pact test suites? Or some cases are not covered by unit tests but tested by Pact tests? Yes that can happen. I wouldn?t be too concerned about it, but I think the visibility you get by separating things out helps. I?d expect unit tests to overlap with Pact tests pretty significantly, as Pact tests (generalization) tend to be slighly higher up the testing stack than unit tests, albeit you want that ?unit test? mentality.

pierre.zeidan
2023-05-30 13:10
has joined #pact-js

morin.td
2023-05-30 14:43
Understood, thanks a lot :pray:

shkothari
2023-05-30 14:55
has joined #pact-js

bwang
2023-05-30 16:55
has joined #pact-js

dev.talha.akbar
2023-05-31 09:45
has joined #pact-js

dev.talha.akbar
2023-05-31 09:58
I am using Pact for the first time and I would like to write a test which does not specify a certain HTTP status code for the provider to respond with. As in as long as any 4xx error response is there, the test should pass. Is it possible?

dev.talha.akbar
2023-05-31 10:00
```.willRespondWith({ status: '4xx', headers: { 'Content-Type': 'application/json' }, body: EXPECTED_BODY, })```

tjones
2023-05-31 10:59
Not with Pact, as far as I know. The usual pattern is to just put one in the contract that you know it can generate.

tjones
2023-05-31 11:00
ContractCase does support this, but the documentation isn?t complete yet, and it only supports JavaScript / Typescript at the moment: https://case.contract-testing.io/

sreenivas.chaitanya
2023-05-31 11:04
is there a way to change the pact broker port ?

dev.talha.akbar
2023-05-31 12:38
Thanks @tjones! I wanted to keep it generic because as a consumer I didn?t care what the status code was but for now I used 406 which our backend actually returns. Honestly I didn?t want to look at the backend implementation to write my pact but it?s okay :smile:

tjones
2023-05-31 13:49
yeah, that?s a good pragmatic approach

msiles
2023-05-31 13:50
has joined #pact-js

tjones
2023-05-31 13:51
general errors are an interesting case, because they?re kind of out of the contract - like, if your client isn?t relying on them, they don?t need to be in the contract. But, you also want them in the contract, so you can say ?well, if you produce ANY errors, I want them in this format?


tjones
2023-05-31 14:17
for pact-js, just put it in the url

tjones
2023-05-31 14:17
or are you asking about something else?

eli.thorkelson
2023-05-31 18:14
has joined #pact-js

lori.maurais
2023-05-31 20:20
Hi, I am having problems just installing the pact dependency into our project - I am running ? npm i -S @pact-foundation/pact? and am getting errors on node-gyp rebuild. I have already verified that ignore scripts is false, and have installed node-gyp globally per installation notes https://github.com/pact-foundation/pact-js#installation: . I will attach output in a thread. Any help is appreciated - Thanks!

lori.maurais
2023-05-31 20:21
from the terminal: ```npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @pact-foundation/pact-core@13.13.8 install: `node-gyp rebuild` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @pact-foundation/pact-core@13.13.8 install script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /Users/m_884005/.npm/_logs/2023-05-31T20_16_32_076Z-debug.log```

lori.maurais
2023-05-31 20:22
from the log: ```3025 verbose stack Error: @pact-foundation/pact-core@13.13.8 install: `node-gyp rebuild` 3025 verbose stack Exit status 1 3025 verbose stack at EventEmitter.<anonymous> (/Users/m_884005/.nvm/versions/node/v12.14.1/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 3025 verbose stack at EventEmitter.emit (events.js:223:5) 3025 verbose stack at ChildProcess.<anonymous> (/Users/m_884005/.nvm/versions/node/v12.14.1/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 3025 verbose stack at ChildProcess.emit (events.js:223:5) 3025 verbose stack at maybeClose (internal/child_process.js:1021:16) 3025 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) 3026 verbose pkgid @pact-foundation/pact-core@13.13.8 3027 verbose cwd /Users/m_884005/Documents/Lineage/repos2/linos-backend/nestjs-monorepo 3028 verbose Darwin 22.3.0 3029 verbose argv "/Users/m_884005/.nvm/versions/node/v12.14.1/bin/node" "/Users/m_884005/.nvm/versions/node/v12.14.1/bin/npm" "i" "-S" "@pact-foundation/pact" 3030 verbose node v12.14.1 3031 verbose npm v6.13.4 3032 error code ELIFECYCLE 3033 error errno 1 3034 error @pact-foundation/pact-core@13.13.8 install: `node-gyp rebuild` 3034 error Exit status 1 3035 error Failed at the @pact-foundation/pact-core@13.13.8 install script. 3035 error This is probably not a problem with npm. There is likely additional logging output above. 3036 verbose exit [ 1, true ]```

lori.maurais
2023-05-31 20:27
node version: 12.14.1, npm version: 6.13.4

msiles
2023-05-31 20:43
Hi All, what is the right way to do this; for example if we have in my API these calls: getAccounts postAccounts getList postLists getCustomers postCustomers doSomethingWithCustomers do we need separate contracts for each module? (Accounts, Lists, Customers, Orders, etc) or all of them should be in one contract

tjones
2023-05-31 23:35
They should all be in one contract file. However, you can put them in separate tests if you like

tjones
2023-05-31 23:36
Make sure you delete the contract file before each run

tjones
2023-05-31 23:37
What OS and arch combination do you have?

matt.fellows
2023-06-01 00:53
That?s a very old version of Node - we don?t technically support that version, albeit it might work. Is there a reason you can?t use a later version?

tjones
2023-06-01 00:53
oh right, yeah. I reckon that's the problem


lori.maurais
2023-06-01 12:25
Agree - they are in the process of upgrading node for the project. What is the minimum version of node version that pact-foundation/pact will work with?

lori.maurais
2023-06-01 12:26
(I did get the npm install to work with node 14.17.0/npm 6.14.13, and I can run my test from the command line successfully, but the nest build breaks on the pact node modules.)

tjones
2023-06-01 13:01
I?m not sure. Have a look in the changelog. Dropping support for node 12 will be documented.

tjones
2023-06-01 13:02
Oh, the changelog has all the beta releases in it for some reason. That?s not a very nice read. Hold on

tjones
2023-06-01 13:04
And it wasn?t documented either

tjones
2023-06-01 13:04
~It was 11.0.1. The drop of node 12 should have been a breaking change.~

tjones
2023-06-01 13:08
Er, apologies, that?s not right either

tjones
2023-06-01 13:10
9.17.3

tjones
2023-06-01 13:11
It should have been a breaking change, but Pact couldn?t release major versions at that time for ?reasons.

tjones
2023-06-01 13:11
Sorry about that

tjones
2023-06-01 13:11
I suspect any 9.x line will work for you

tjones
2023-06-01 13:11
it should have made it in to the changelog, perhaps we can retroactively fix that

lori.maurais
2023-06-01 13:11
I?m confused now? 9 <12. (I was talking about node versions). I?ve got the latest pact (11.02), and I?m trying to figure out the min version of node I need for it. Thanks

lori.maurais
2023-06-01 13:13
can you send a link to the doc you?re looking at? thanks!

tjones
2023-06-01 13:29
It?s the pact-js changelog (in the repo https://github.com/pact-foundation/pact-js/blob/master/CHANGELOG.md), but it?s corrupted by the beta releases so it?s hard to read. Also, the information about dropping node 12 isn?t in it.

tjones
2023-06-01 13:29
Apologies, I thought you were asking for the minimum Pact version

tjones
2023-06-01 13:30
the minimum node version for 11.0.2 is 14.

tjones
2023-06-01 13:30
That should be in the changelog too (or at least implied from ?dropping support for node 12?)

tjones
2023-06-01 13:30
but it isn?t


tjones
2023-06-01 13:31
I would recommend the latest 14.x

lori.maurais
2023-06-01 13:32
Thanks, Timothy!

tjones
2023-06-01 13:33
If you want a specific one, it was last tested in CI on `14.21.3`. You can see that in the logs for the successful runs here: https://github.com/pact-foundation/pact-js/actions/runs/4549309315/jobs/8021248485

lori.maurais
2023-06-01 13:34
Thanks, this is really helpful. (I?m a newbie with this.)

tjones
2023-06-01 13:35
Sorry for the confusion! The changelog is really nice when it?s not corrupt. If I get a moment later in the month I?ll try to figure out what happened and how it should look

yousafn
2023-06-01 13:52
I?d recommend moving to node 18 personally node 14 is eol https://endoflife.date/nodejs and there is 3 weeks left for 16.x

yousafn
2023-06-01 13:53
We hope to resolve the installation issues for users and remove the requirement for a node gyp build chain in the very near future, there is an open PR at the moment

yousafn
2023-06-01 13:54
Thanks for all the support and help as usual Tim!

harwin1494
2023-06-01 15:07
Hi team, I have a use-case wherein 1 out of 3 microservices is going to act as a consumer and a provider both. What are the best practices in writing the contract tests for such a use-case?

matt.fellows
2023-06-02 00:16
It shouldn?t really change things. The best practice for consumers are the same, and the best practices for providers are also the same. It?s just that some of your apps will be both. Is there something you?re worried about?

sreenivas.chaitanya
2023-06-02 09:52
this is the error I get if I use a central broker

sreenivas.chaitanya
2023-06-02 09:52
ERROR: Error making request - Errno::ECONNREFUSED Failed to open TCP connection to http://meufavcpy3.execute-api.eu-west-2.amazonaws.com:80 (Connection refused - connect(2) for "http://meufavcpy3.execute-api.eu-west-2.amazonaws.com" port 80) /Users/sguttarlapalli/IPV/di-ipv-spot/node-functions/messages/node_modules/@pact-foundation/pact-core/standalone/darwin-1.91.0/pact/lib/vendor/ruby/2.4.0/gems/pact_broker-client-1.65.0/lib/pact_broker/client/hal/http_client.rb:79:in `block in perform_request', attempt 1 of 5

tjones
2023-06-02 09:53
Is your broker actually there and listening on that port?

sreenivas.chaitanya
2023-06-02 09:53
yes

tjones
2023-06-02 09:53
What happens if you go to it in a browser?

sreenivas.chaitanya
2023-06-02 09:53
I can log in ok in a browser

sreenivas.chaitanya
2023-06-02 09:54
but when I run publish from the folder I get this error

tjones
2023-06-02 09:55
Well, I get connection refused when I click that link

sreenivas.chaitanya
2023-06-02 09:55
that may be because its secure to our local env

sreenivas.chaitanya
2023-06-02 09:56
are u accesing from outside uk?

tjones
2023-06-02 09:56
What happens if you click that link?

tjones
2023-06-02 09:56
Have you misspelt it?

tjones
2023-06-02 09:56
Does your browser have a proxy?

sreenivas.chaitanya
2023-06-02 09:56
it asks for username and password

tjones
2023-06-02 09:56
I suspect there is something different between your browser and the command line

tjones
2023-06-02 09:57
try doing a curl of that url

sreenivas.chaitanya
2023-06-02 09:57
outside of the country it may not work as its our secure aws environment , due to our restrictions

tjones
2023-06-02 09:58
Or have a look in your AWS logs

sreenivas.chaitanya
2023-06-02 09:58
seems the broker is down , let me get it up


sreenivas.chaitanya
2023-06-02 10:01
this seems to be working

tjones
2023-06-02 10:02
So, if it?s working in your browser but not on the command line, my question would be - what is different between the command line and the browser?

sreenivas.chaitanya
2023-06-02 10:02
I presume pact only allows 9292 for broker

sreenivas.chaitanya
2023-06-02 10:02
is there a way we can tell it to look at a new port

tjones
2023-06-02 10:04
Why do you think it only allows 9292?

sreenivas.chaitanya
2023-06-02 10:05
on pacs docs it says u need permissions to run on a port below 1024

tjones
2023-06-02 10:05
yes, that?s an operating system thing


sreenivas.chaitanya
2023-06-02 10:10
here it says default

sreenivas.chaitanya
2023-06-02 10:10
how do I Amend it to look at 80?

tjones
2023-06-02 10:10
If you?re able to access the broker at that url, then you?re already running it on port 80

sreenivas.chaitanya
2023-06-02 10:11
it works in browser only

tjones
2023-06-02 10:11
As I said above, if you can access it in the browser but not on the command line, then something is different between the two. I can?t help you any more than that, I?m sorry

sreenivas.chaitanya
2023-06-02 10:11
ok thanks

harwin1494
2023-06-02 13:22
I am just thinking if it is advised to write an end-to-end test for all the three microservices in one file, since the middle-one is acting as a consumer and a provider both? Or the should the interactions be handled separately?

msiles
2023-06-02 15:14
Hi all, question about running the consumer tests, is there a way to run only 1 test, or do we need to run the full suite every time we are adding something new? Most of my experience is related to Cypress / Selenium? so I?m wondering if there is a such thing in contract tests

jegadeesan.ponnusamy8
2023-06-02 16:19
has joined #pact-js

tjones
2023-06-02 23:29
Consumer tests are driven by your unit testing framework, so yes. You can just use whatever mechanism that has for restricting tests

msiles
2023-06-03 03:13
Hi all, another question regarding fixture files? I saw this example here, section ?Improve test readability?? where can I find more examples with fixture files? I?m using a big json in my consumer test, so I think the fixture could solve my issue https://docs.gitlab.com/ee/development/testing_guide/contract/consumer_tests.html

matt.fellows
2023-06-03 03:28
Fixture files just means (dumbed down) "put data outside of the tests themselves" In JS this is super easy. I don't know if we have any examples but I think you'll find this is quite a generic question and not unique to Pact

msiles
2023-06-03 03:29
Thanks Matt,

tjones
2023-06-03 06:43
Is that? the gitlab documentation?

tjones
2023-06-03 06:45
That?s pretty cool that they have jest-pact in there! If I?d known other people would be writing documentation for it, I would have chosen a better name than PactFn

siyuanshen1993
2023-06-03 10:36
has joined #pact-js

siyuanshen1993
2023-06-03 10:39
Hi! I?m new with pact js, recently I try to create a contract test for my project, on my consumer side I already succeed to create a consumer test with pact file, but on my provider side I need to use event-driven structure to create provider test and I?m not sure it can used to match the pact file. Can someone help me please?

siyuanshen1993
2023-06-03 10:50
BTW, does the MessageProviderPact still support pactBrokerUsername and pactBrokerPassword? My pact file already upload into it but I cannot download it ?.

matt.fellows
2023-06-03 23:39
Can you please share your code or a bit more detail? Are you using any of the examples to work from?

matt.fellows
2023-06-03 23:55
I can access that URL here in Australia, from my laptop (both CLI and browser) That tells me (and as Tim has stated) there is something about your network or environment that's different. It could be proxy settings (you either need them or you need to exclude them) or routing is different. You need to discuss that with your network/ops team

matt.fellows
2023-06-03 23:56
This page may have some tips if it is proxy related: https://docs.pact.io/implementation_guides/ssl

matt.fellows
2023-06-03 23:58
Separate. Always separate :wink:

tjones
2023-06-04 00:57
Oh, I remember why! It?s because jest calls their test callback `TestFn`

siyuanshen1993
2023-06-04 03:04
```import { LogLevel, Verifier } from '@pact-foundation/pact'; import * as getParent from './get-parent'; import sinon from 'sinon'; let sandbox: any; const LOG_LEVEL = process.env.LOG_LEVEL || 'DEBUG'; const mockId = { queryStringParameters: { organisationId: '12345abcde', }, }; describe('send organisation parent provider test', () => { before(() => { sandbox = sinon.createSandbox(); }); afterEach(() => { sandbox.restore(); }); it('send organisation parent id', () => { return new Verifier({ provider: 'getOrganisationParentProvider', logLevel: LOG_LEVEL as LogLevel, providerBaseUrl: 'http://localhost:8081', stateHandlers: { 'has the organisation id 12345abcde': () => { const stubResponse = { Items: [ { id: '12345abcde', name: 'Test Organisation', parentId: 'TestParentId', }, ], }; // Stub the send function of DynamoDBDocumentClient const stub = sandbox.stub(getParent, 'send'); stub.returns({ promise: () => Promise.resolve(stubResponse) }); return Promise.resolve({ description: `state set get the organisation parent id`, }); }, }, providerVersion: 'organisation-parent-id-1.0', pactBrokerUsername: 'tap-pact-broker', pactBrokerPassword: 'JGNqcsd3x2JESU1LHFSw', pactBrokerUrl: 'https://pact-broker/', consumerVersionSelectors: [ { matchingBranch: true, }, ], publishVerificationResult: true, enablePending: true, }) .verifyProvider() .then((output) => { console.log('Pact Verification Complete!'); console.log(output); }); });```

siyuanshen1993
2023-06-04 03:05
I try to use the example from pact github, and to be honest they are also confused me. the process in the doc is quite different?.

siyuanshen1993
2023-06-04 03:06
```const p = new MessageProviderPact({ messageProviders: { 'a organisation parent id': providerWithMetadata( () => getParent(mockId), { 'content-type': 'application/json', } ), }, stateHandlers: { 'has the organisation id 12345abcde': () => { const stubResponse = { Items: [ { id: '12345abcde', name: 'Test Organisation', parentId: 'TestParentId', }, ], }; // Stub the send function of DynamoDBDocumentClient const stub = sandbox.stub(DynamoDBDocumentClient.prototype, 'send'); stub.returns({ promise: () => Promise.resolve(stubResponse) }); return Promise.resolve(`state set get the organisation parent id`); }, }, logLevel: LOG_LEVEL as LogLevel, provider: 'getOrganisationParentProvider', providerVersion: 'organisation-parent-id-1.0', pactBrokerUsername: 'tap-pact-broker', pactBrokerPassword: 'JGNqcsd3x2JESU1LHFSw', pactBrokerUrl: 'https://pact-broker/', consumerVersionSelectors: [ { matchingBranch: true, }, ], }); describe('send organisation parent id', () => { it('sends valid organisation parent id', () => { return p.verify(); }); });```

siyuanshen1993
2023-06-04 03:08
This is another code which is beasd on the example of event-driven. Currently both code complain that the pact file cannot be downloaded from pact broker

siyuanshen1993
2023-06-04 04:20
```14:18:04.651] INFO (36059): pact@11.0.2: Verifying provider [14:18:04.665] INFO (36059): pact-core@13.13.8: Verifying Pacts. [14:18:04.666] INFO (36059): pact-core@13.13.8: Verifying Pact Files [14:18:04.667] DEBUG (36059): pact-core@13.13.8: Initalising native core at log level 'DEBUG' 2023-06-04T04:18:04.672803Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_new_for_application FFI function invoked 2023-06-04T04:18:04.676468Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_info FFI function invoked [14:18:04.677] DEBUG (36059): pact-core@13.13.8: the optional ffi function 'pactffiVerifierSetFilterInfo' was not executed as it had non-fatal validation errors: None of PACT_DESCRIPTION, PACT_PROVIDER_STATE or PACT_PROVIDER_NO_STATE were set in the environment 2023-06-04T04:18:04.677706Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_state FFI function invoked 2023-06-04T04:18:04.677868Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_verification_options FFI function invoked 2023-06-04T04:18:04.678127Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_publish_options FFI function invoked [14:18:04.678] DEBUG (36059): pact-core@13.13.8: the optional ffi function 'pactffiVerifierSetConsumerFilters' was not executed as it had non-fatal validation errors: Either no consumerFilters option provided, or the array was empty [14:18:04.678] DEBUG (36059): pact-core@13.13.8: the optional ffi function 'pactffiVerifierSetFailIfNoPactsFound' was not executed as it had non-fatal validation errors: No failIfNoPactsFound option provided [14:18:04.678] DEBUG (36059): pact-core@13.13.8: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: No customProviderHeaders option provided [14:18:04.678] DEBUG (36059): pact-core@13.13.8: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: No pactUrls option provided 2023-06-04T04:18:04.679144Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_broker_source_with_selectors FFI function invoked [14:18:04.680] DEBUG (36059): pact-core@13.13.8: the optional ffi function 'pactffiVerifierAddProviderTransport' was not executed as it had non-fatal validation errors: No additional provider transports provided```

siyuanshen1993
2023-06-04 04:21
In the beginning, I also received these debug information, but I?m not sure it is relevant with my issue.

matt.fellows
2023-06-05 00:31
Nothing of issue there that I can see. DEBUG level statements are for helping diagnose issues, but shouldn?t be an error themselves (that?s what `ERROR` is for)

matt.fellows
2023-06-05 00:31
thanks for sharing though

pawar.s
2023-06-05 05:15
has joined #pact-js

siyuanshen1993
2023-06-05 12:38
Hi! may I ask how to solve the error with ECONNREFUSED with providerBaseUrl ? I used axios-mock-adapter but it still failed

matt.fellows
2023-06-05 13:31
What are you mocking? The provider? If so, you don't mock the provider in the provider test - we need to test the provider!

matt.fellows
2023-06-05 13:32
I'd suggest doing one of the tutorials or workshops below (howtolearn) to understand how it all works

2023-06-05 13:32
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

siyuanshen1993
2023-06-05 13:56
I just followed the example in github, and the pact verifier will complain if I do not provide the providerBaseUrl.

siyuanshen1993
2023-06-05 13:56
``` 1) receive get organisation parent id request return organisation parent id: Error: 'providerBaseUrl' is mandatory if no 'messageProviders' or 'transports' given at new ConfigurationError (node_modules/@pact-foundation/pact/src/errors/configurationError.js:21:42) at new Verifier (node_modules/@pact-foundation/src/dsl/verifier/verifier.ts:71:13) at /Users/shensiyuan/Desktop/organisations/backend/src/get-parent/get-parent-contract.test.ts:77:18 at Generator.next (<anonymous>) at /Users/shensiyuan/Desktop/organisations/backend/src/get-parent/get-parent-contract.test.ts:8:71 at new Promise (<anonymous>) at __awaiter (src/get-parent/get-parent-contract.test.ts:4:12) at Context.<anonymous> (src/get-parent/get-parent-contract.test.ts:76:50) at processImmediate (node:internal/timers:466:21)```

siyuanshen1993
2023-06-05 14:00
My lambda provider is triggered by api gateway, so I?m trying to create a mock server to call my lambda function

siyuanshen1993
2023-06-05 14:22
Maybe I need to search about providerBaseUrl in verifier again, because this one is really confuse me hahaha.

tjones
2023-06-05 14:22
Are you verifying an http endpoint?

tjones
2023-06-05 14:23
if yes, and that endpoint is connected by API gateway, then you need to stand it up somehow. With API Gateway I think you can use localstack. Or, possibly you could deploy to a dev environment

tjones
2023-06-05 14:24
you will need to be able to stand up your service to the point that you can send http requests to it

tjones
2023-06-05 14:24
and once you have done that, you give the URL of the service to `providerBaseUrl`

siyuanshen1993
2023-06-05 14:26
So may I ask the purpose of `providerBaseUrl` ?

tjones
2023-06-05 14:28
That?s how you tell pact where your service is running

tjones
2023-06-05 14:28
so it can run the verification

tjones
2023-06-05 14:29
As Matt said, the tutorials will walk you through all these concepts

siyuanshen1993
2023-06-05 14:29
Got it! thanks!

yousafn
2023-06-05 15:43
That is cool, I've been playing a bit with a GitLab setup in my homelab. Didn't know they were using it either

rohitkrishnan
2023-06-05 20:37
has joined #pact-js

payal.chainani
2023-06-06 06:32
has joined #pact-js

divya.parappanavar
2023-06-06 07:23
has joined #pact-js

mrudula.patil
2023-06-06 08:19
has joined #pact-js

asjad.baig.ind
2023-06-06 11:12
has joined #pact-js

rajat.chouhan
2023-06-06 12:16
has joined #pact-js

yonatany
2023-06-06 12:42
hi ,im a new user to pact ,i am using Pact with message queues - already able to write down the consumer (that generates the contract) but I was not able to verify it here by the contract consumer (the producer of the event) - did i misunderstood something? (Expecting the contract to be verified)

tjones
2023-06-06 12:46
I think you need to set `publishVerificationResult` to `true`. It?s false by default

tjones
2023-06-06 12:47
``` const p = new MessageProviderPact({ publishVerificationResult: true, ....etc });```

yonatany
2023-06-06 12:52
Thanks :slightly_smiling_face:

aaron.m.williams24
2023-06-06 16:40
I also get this problem on an azure pipeline. The step before npm i does a global install of node-gyp. cc @matt.fellows

msiles
2023-06-06 21:13
Hi, does anyone know why one of my colleagues is getting the following error? this is a sample repo but he?s getting that error, he tried another repo, and the same thing. Same code is working fine on my local. Cannot find addinteraction

matt.fellows
2023-06-06 23:14
Does the log file show anything?

matt.fellows
2023-06-07 00:11
It's worth googling that error. I remember getting the error in the past, but it's an issue with node gyp/native deps on Windows. It's possible even with node gyp installed you need a C++ tool chain, which looks to be the error you're seeing

tjones
2023-06-07 00:17
This is an old version of pact - if you can upgrade it might be fixed (and it definitely will have a better error message)

tjones
2023-06-07 00:17
usually this happens if setup hasn?t been called first

matt.fellows
2023-06-07 00:20
Unfortunately this is just one of those NodeJS things.

matt.fellows
2023-06-07 00:21
This all being said, @yousafn has done some awesome work and hopefully soon it will be a https://github.com/pact-foundation/pact-js-core/pull/446 for us

msiles
2023-06-07 02:16
the weird thing is that the same code is working on my local, but the other guy just download the code, ran the npm install and he is getting that error :thinking_face:

matt.fellows
2023-06-07 02:23
the two things that come to mind 1. Are you running windows or Mac? 2. Possibly, they are running into the windows long path issue (google it + Pact to see relevant issues). Move the project closer to `c:\` and it might fix it 3. There is some error that?s not surfacing (e.g. the port is taken). You can check that by running `lsof -i:<port>` (replace the `<port>` with the relevant port the test is using). Similarly, a Ruby process could be hanging around (`ps -ef | grep ruby` should show that). I realise these are linux commands?so, probably need to check As Tim said, newer versions of Pact JS won?t have this problem, so really you should update

matt.fellows
2023-06-07 02:23
I?ll reach out to Rafaela to see if she is willing to update to the latest

msiles
2023-06-07 02:25
I?m running mac, he?s running windows? we tried the short path and it didn?t work? I?ll tell him to try the newer version,

msiles
2023-06-07 02:26
and thanks again for the answers, really appreciate it

tjones
2023-06-07 02:57
You're using pact-js 9.x, which requires the `setup` method to complete before running tests. My guess is that you're not waiting for the promise to complete.

tjones
2023-06-07 02:57
If you can share your test file, we can take a look and probably point out the error

david.stothers
2023-06-07 07:25
has joined #pact-js

rafaela.azevedosouza
2023-06-07 08:52
has joined #pact-js

newmolti
2023-06-07 10:14
has joined #pact-js

danut.turta
2023-06-07 11:35
has joined #pact-js

dev664
2023-06-07 11:53
has joined #pact-js

david.blanco
2023-06-07 18:08
has joined #pact-js

jonathan.fisher
2023-06-07 19:30
has joined #pact-js

dev.pactslack
2023-06-07 20:17
has joined #pact-js

msiles
2023-06-07 20:47
thanks Tim, he upgrade to the latest pact and now he?s getting this error (Windows machine)

msiles
2023-06-07 20:47
that could be a port thing, right?

tjones
2023-06-07 21:00
Follow the instructions in that error message

msiles
2023-06-07 21:04
yeah, he?s doing that? I just wondering why the same code is working on my side but it?s failing on windows

tjones
2023-06-07 21:11
There should be answers in the logs, and if there isn?t, it might be in how it is being used. If you can share your test file we can help more

dan.nichols52
2023-06-08 04:30
has joined #pact-js

s.lohmeier
2023-06-08 08:08
has joined #pact-js

aaron.m.williams24
2023-06-08 08:59
Ah I see, thanks. I?ll keep an eye on that PR.

yousafn
2023-06-08 11:48
technically you can try it out today, as per my last comment in that PR, I have published forks consuming the changes in the PR to npm under my personal scope. Looking at a quick google, regarding node-gyp on azure pipelines suggest you need to use a specific task https://stackoverflow.com/questions/70332595/azure-devops-build-pipeline-npm-install-failing-on-node-gyp https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/node-tool-v0?view=azure-pipelines can you share a copy of the pipeline file omitting anything sensitive/company specific or provide a simple repro with just a pact-js example repo?

aaron.m.williams24
2023-06-08 12:39
```It's just doing the below and failing on npm install parameters: - name: 'node_version' type: string default: '14.18.1' - name: 'function_app_name' type: string default: 'SampleFunctionApp' - name: 'code_coverge_threshold' type: string default: '60' steps: - task: NodeTool@0 inputs: versionSpec: ${{ parameters.node_version }} # Install dev dependencies - script: npm install -g gyp workingDirectory: $(System.DefaultWorkingDirectory) displayName: 'npm install gyp' # Install dev dependencies - script: npm install -g node-gyp workingDirectory: $(System.DefaultWorkingDirectory) displayName: 'npm install node-gyp' # Install dev dependencies - script: npm install workingDirectory: $(System.DefaultWorkingDirectory) displayName: 'npm install'```

radek.stolarczyk
2023-06-08 13:32
has joined #pact-js

yousafn
2023-06-08 15:16
14 is EOL, please try at minimum 16

yousafn
2023-06-08 15:17
(if not already on a later one :slightly_smiling_face: )


zeeshankhan0330
2023-06-08 16:36
has joined #pact-js

msiles
2023-06-09 02:18
Hi all, probably this is a dumb question hehe, I was checking the examples here https://github.com/pact-foundation/pact-js/blob/master/examples/e2e/test/consumer.spec.js and I noticed the line below in the consumer.spec.js, so my question is: if the consumer test are running a log folder should be created with some log info in the root folder? ``` log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),```

tjones
2023-06-09 03:57
I think that?s left over from the 9.x interface - looks like the example needs to be updated

tjones
2023-06-09 03:58
10.x and above don?t log to a file

msiles
2023-06-09 04:00
so, for 10.x and above we need to check the output in the terminal, right?

tjones
2023-06-09 04:03
The log is the debug log

tjones
2023-06-09 04:03
for 10.x it is only to standard out

tjones
2023-06-09 04:03
you never need to check the log unless something is not working

msiles
2023-06-09 04:54
Another question, I?m wondering if there is a way to get in the output of the executed tests in a list, If I?m not wrong I was getting a kind of list with a previous pact version. How can I know which tests were executed?

marek
2023-06-09 07:57
has joined #pact-js

aaron.m.williams24
2023-06-09 09:44
Yeah, we?re currently going through ?upgrading? node and packages etc on all projects. I?ll check again after :)? thanks

yousafn
2023-06-09 09:50
Good luck buddy! One of my last places was pretty heavily node focused, I can imagine bumping all projects, and most of the dependencies moving onto esm have meant that hasn?t been a simply straightforward task. I?ll see if I can get some time in today to setup azure for testing

michael.lawrence
2023-06-09 09:57
has joined #pact-js

harwin1494
2023-06-09 11:10
Hi Team, after updating the pact version to this `"@pact-foundation/pact": "11.0.2"`, `npm install` is failing in my local system. Should I update the node version in my system? Currently it is 16.18.0.

msiles
2023-06-09 14:34
I?m using v16.16.0 and ?@pact-foundation/pact?: ?^11.0.2",

msiles
2023-06-09 17:53
I think this is related to the testframework

matt.fellows
2023-06-10 12:06
What's the error?

mssachin
2023-06-12 08:06
has joined #pact-js

mssachin
2023-06-12 08:08
:wave: Hello, team! Had a query regarding PACT test can anyone please help

yousafn
2023-06-12 08:19
hey buddy, we are not a general purpose help desk but feel free to ask your question as it will aid community members in being able to help you

yousafn
2023-06-12 08:20
should i update node? probably not, i doubt that is your issue. please note we have no idea about what your local system consists of, nor the error message you are receiving therefore it is almost impossible to help you.

yousafn
2023-06-12 08:20
please provide more information

harwin1494
2023-06-12 08:21
I am sharing the error message in 2 minutes

harwin1494
2023-06-12 08:23
`npm ci` `npm WARN deprecated mkdirp@0.3.0: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promis` `es in 1.x.)` `npm WARN deprecated puppeteer@9.1.1: < 19.4.0 is no longer supported` `npm WARN cleanup Failed to remove some directories [` `npm WARN cleanup [` `npm WARN cleanup 'C:\\testProject\\node_modules\\puppeteer',` `npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'C:\mfe-home\node_modules\puppeteer'] {` `npm WARN cleanup errno: -4082,` `npm WARN cleanup code: 'EBUSY',` `npm WARN cleanup syscall: 'rmdir',` `npm WARN cleanup path: 'C:\\testProject\\node_modules\\puppeteer'` `npm WARN cleanup }` `npm WARN cleanup ],` `npm WARN cleanup [` `npm WARN cleanup 'C:\\testProject\\node_modules',` `npm WARN cleanup [Error: EBUSY: resource busy or locked, rmdir 'C:\testProject\node_modules\puppeteer'] {` `npm WARN cleanup errno: -4082,` `npm WARN cleanup code: 'EBUSY',` `npm WARN cleanup syscall: 'rmdir',` `npm WARN cleanup path: 'C:\\testProject\\node_modules\\puppeteer'` `npm WARN cleanup }` `npm WARN cleanup ]` `npm WARN cleanup ]` `npm ERR! code 1` `npm ERR! path C:\testProject\node_modules\@pact-foundation\pact-core` `npm ERR! command failed` `npm ERR! command C:\Windows\system32\cmd.exe /d /s /c node-gyp rebuild` `npm ERR! gyp info it worked if it ends with ok` `npm ERR! gyp info using node-gyp@9.1.0` `npm ERR! gyp info using node@16.18.0 | win32 | x64` `npm ERR! gyp info find Python using Python version 3.10.1 found at "C:\Python310\python.exe"` `npm ERR! gyp ERR! find VS` `npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config` `npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt` `npm ERR! gyp ERR! find VS checking VS2022 (17.6.33723.286) found at:` `npm ERR! gyp ERR! find VS "D:\Visual Studio"` `npm ERR! gyp ERR! find VS - found "Visual Studio C++ core features"` `npm ERR! gyp ERR! find VS - missing any VC++ toolset` `npm ERR! gyp ERR! find VS could not find a version of Visual Studio 2017 or newer to use` `npm ERR! gyp ERR! find VS looking for Visual Studio 2015` `npm ERR! gyp ERR! find VS - not found` `npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8` `npm ERR! gyp ERR! find VS` `npm ERR! gyp ERR! find VS **************************************************************` `npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio` `npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.` `npm ERR! gyp ERR! find VS For more information consult the documentation at:` `npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows` `npm ERR! gyp ERR! find VS **************************************************************` `npm ERR! gyp ERR! find VS` `npm ERR! gyp ERR! configure error` `npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use` `npm ERR! gyp ERR! stack at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47)` `npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16` `npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:364:14` `)` `npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14` `npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:385:16` `npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7` `npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16` `npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:410:5)` `npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28)` `npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1100:16)` `npm ERR! gyp ERR! System Windows_NT 10.0.19045` `npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"` `npm ERR! gyp ERR! cwd C:\testProject\node_modules\@pact-foundation\pact-core` `npm ERR! gyp ERR! node -v v16.18.0` `npm ERR! gyp ERR! node-gyp -v v9.1.0` `npm ERR! gyp ERR! not ok`

harwin1494
2023-06-12 08:24
@yousafn please let me know if the above error is sufficient.

yousafn
2023-06-12 08:25
have you clicked on the link re node gyp and followed the windows instructions

harwin1494
2023-06-12 08:25
not yet

yousafn
2023-06-12 08:26
well why would you expect it to work

harwin1494
2023-06-12 08:27
Makes sense! I'l try this and update if it works.

yousafn
2023-06-12 08:28
:) it is noted in the troubleshooting guide https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#installation-failing-missing-python-c-or-build-tools unfortunately we can?t catch this earlier and detect a different message to present to the user but i?m hoping to get a pr reviewed to include all the dependencies in the package so you won?t need a full tool chain to install pact js :)

harwin1494
2023-06-12 08:30
yes, that would be helpful as well.

mssachin
2023-06-12 09:05
Sir basically its quite a complicated query. I have a GET request which responds back with a UUID and a string. When I create a consumer test I create with an ID say e5173b29-d597-434e-872b-71db298bbe8f. Now when I run my provider side of tests it expects the same UUID for the test to pass. I am creating a new stack and I do not have the UUID in the DB yet. How do I circumvent this situation

yousafn
2023-06-12 09:44
use provider states and matchers, matchers so you expect a key that looks like a uuid not the actual fixed uuid

yousafn
2023-06-12 09:44
the provider state can be read in the provider test to setup the required data

yousafn
2023-06-12 09:45
in which it would return a uuid, which could be validated to ensure if matches a valid uuid. i assume the actual specific id isn?t of importance

mssachin
2023-06-12 09:50
the UUID goes in the path of the url something like base_url/e5173b29-d597-434e-872b-71db298bbe8f

mssachin
2023-06-12 09:51
sorry @yousafn I have spent 3 days already trying to get around this



yousafn
2023-06-12 10:10
it matches your use case > The `fromProviderState` matching function allows values to be generated based on values returned from the provider state callbacks. This should be used for the cases were database entries have auto-generated values and these values need to be used in the URLs or query parameters.

matt.fellows
2023-06-12 12:20
What Yousaf said. Most people don?t need `fromProviderState`, provider states themselves should work for 99% of people

matt.fellows
2023-06-12 12:20
Do you have control over your provider? i.e. do you have access to the code or are you testing against a fixed environment?

andy.frith
2023-06-12 12:31
has joined #pact-js

mssachin
2023-06-12 12:49
Yes I have control

mssachin
2023-06-12 12:50
I am still struggling when I look at the logs it says

mssachin
2023-06-12 12:50
[13:45:45.092] DEBUG (20768): pact@11.0.2: Proxying GET: /anyguuuid

mssachin
2023-06-12 12:50
That what is in the pact.json

mssachin
2023-06-12 12:51
and no matter what I do when I run the state handler it runs based on /anyguuuid value

mssachin
2023-06-12 12:52
```{ "status": 200, "headers": { "Content-Type": "application/json" }, "body": { "details": "some string", "id": "4f2fa219-c805-4781-937c-bf3296e93cc4" } }``` *{*"method": "GET", "path": "http://ec2-44-208-250-63.compute-1.amazonaws.com/anyguuuid", "headers": *{*"Content-Type": "application/json" *}* *}*

mssachin
2023-06-12 12:52
This is my pact

mssachin
2023-06-12 12:54
I do not want it to use the /anyguuuid in the path

mssachin
2023-06-12 12:54
I want to substitute at runtime for a newly created id

mssachin
2023-06-12 14:23
Any word for me @yousafn @matt.fellows

yousafn
2023-06-12 14:24
read the docs

yousafn
2023-06-12 14:24
and don?t tag me

yousafn
2023-06-12 14:25
You need to uses matchers not an explicit value in your path

mssachin
2023-06-12 14:25
I am using mathers

mssachin
2023-06-12 14:25
const dynamicPath = term({ matcher: '.*', generate: '/anyguuuid' });

mssachin
2023-06-12 14:26
path: dynamicPath,

yousafn
2023-06-12 14:26
well if that if your pact above you have shown you don?t have matchers encoded in your contract

mssachin
2023-06-12 14:26
Yes its not

yousafn
2023-06-12 14:26
If you want help, please provide a reproducible example

yousafn
2023-06-12 14:27
and note that this is completely on volunteer time

mssachin
2023-06-12 14:27
I know

mssachin
2023-06-12 14:27
But I spent ages on this so got a bit desparate

yousafn
2023-06-12 14:27
I get that my friend, I?d love to be able to help you, do you think you could make a simple example in a public repo?

mssachin
2023-06-12 14:28
{ "consumer": { "name": "syncconnectors-bullhorn-get" }, "interactions": [ { "description": "A Request for obtaining credentials", "providerState": "I get credentials", "request": { "headers": { "Content-Type": "application/json" }, "matchingRules": { "$.path": { "match": "regex", "regex": ".*" } }, "method": "GET", "path": "/anyguuuid" }, "response": { "body": { "details": "some string", "id": "4f2fa219-c805-4781-937c-bf3296e93cc4" }, "headers": { "Content-Type": "application/json" }, "matchingRules": { "$.body.details": { "match": "regex", "regex": ".*" }, "$.body.id": { "match": "regex", "regex": ".*" } }, "status": 200 } } ], "metadata": { "pact-js": { "version": "11.0.2" }, "pactRust": { "ffi": "0.4.0", "models": "1.0.4" }, "pactSpecification": { "version": "2.0.0" } }, "provider": { "name": "secret-store-get" } }

mssachin
2023-06-12 14:28
This is my json

yousafn
2023-06-12 14:29
ok ty, so you are using the latest pact, but the v2 interface on the consumer side.

yousafn
2023-06-12 14:29
which matchers are you using v2 or v3?


yousafn
2023-06-12 14:31
okay I?ll try and make a simple reproducible from here and update the package.json to match the latest version https://github.com/YOU54F/pact-matchers/blob/main/pact-js-v3-v10/matchers.v2.pact.test.js


yousafn
2023-06-12 15:07
can you share your provider side test

msiles
2023-06-12 18:58
Hi Team, probably this is too obvious, but what should I review if I?m getting a 500 on my provider test instead of 200 status?. currently the consumer tests are passing for my get and post requests, but I?m getting a failure on the POST - Provider Side ```1.1) has a matching body expected 'application/json;charset=utf-8' body but was 'text/html;charset=utf-8' 1.2) has status code 200 expected 200 but was 500 1.3) includes header 'Content-Type' with value 'application/json; charset=utf-8' Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'text/html; charset=utf-8'```

ajay_886
2023-06-12 22:38
has joined #pact-js

tjones
2023-06-12 23:10
A 500 in your provider test means that your provider is returning 500. Have a look in your service logs or run the test under a debugger

msiles
2023-06-13 04:23
checking?

steven.wang06
2023-06-13 05:06
has joined #pact-js

msiles
2023-06-13 05:14
thanks, basically it was my fault ```<pre>TypeError: reasonRepository.insert is not a function<br>...```

tjones
2023-06-13 05:21
That?s a good result! It?s my belief that 500 should exclusively mean ?programmer error?

navanesyan
2023-06-13 07:05
has joined #pact-js

matt.fellows
2023-06-13 11:18
we need logs and/or a reproducible example

matt.fellows
2023-06-13 11:18
Screenshots are usually not very helpful - text logs are

yousafn
2023-06-13 11:48
Just to circle back on this, we were able to resolve this for Sachin. Consumer side https://github.com/YOU54F/pact-matchers/blob/main/pact-js-v3-v10/path.v2.pact.test.js Provider side https://github.com/YOU54F/pact-matchers/blob/main/pact-js-v3-v10/path.provider.pact.test.js Utilising a combination of consumer side matchers and provider state, provider side state handlers, and request filters. There may be a more elegant solution but for now that has got across the roadblock encountered

msiles
2023-06-13 21:04
Hi all, what could be the reason for the following error ```2023-06-13T20:59:16.333720Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (165 bytes) 2023-06-13T20:59:16.333735Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed 2023-06-13T20:59:16.333768Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292) 2023-06-13T20:59:16.334098Z ERROR ThreadId(02) pact_verifier: Failed to load pact - Could not load pacts from the pact broker 'http://localhost:9292' 2023-06-13T20:59:16.334130Z WARN ThreadId(02) pact_matching::metrics: Please note: We are tracking events anonymously to gather important usage statistics like Pact version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.``` basically 1. I downloaded a branch from my coworker, 2. I ran the consumer tests, 3. I published the contract into the broker (local docker, no previous version of the contract), 4. run the provider test and it was throwing the error about couldn?t not load pacts

ran.tao
2023-06-13 21:46
has joined #pact-js

matt.fellows
2023-06-13 21:48
Please share the debug logs, the code you use to select pacts (i.e. verification code) or both

msiles
2023-06-13 21:58
``` > e2e@1.0.0 test:provider > mocha test/provider.spec.js People App Service listening on http://localhost:8081 Pact Verification 2023-06-13T20:59:15.734805Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_new_for_application FFI function invoked 2023-06-13T20:59:15.735309Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_info FFI function invoked 2023-06-13T20:59:15.735513Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_state FFI function invoked 2023-06-13T20:59:15.735639Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_verification_options FFI function invoked 2023-06-13T20:59:15.735716Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_publish_options FFI function invoked 2023-06-13T20:59:15.736158Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_broker_source_with_selectors FFI function invoked 2023-06-13T20:59:15.739750Z DEBUG ThreadId(02) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_execute FFI function invoked 2023-06-13T20:59:15.739824Z DEBUG ThreadId(02) pact_ffi::verifier::handle: Pact source to verify = PactBrokerWithDynamicConfiguration(http://localhost:9292, provider_name='e2e Provider Example', enable_pending=true, include_wip_since=None, provider_tags=["master"], provider_branch=Some("master"), consumer_version_selectors='[ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: Some(true) }], auth=None') 2023-06-13T20:59:15.743652Z DEBUG ThreadId(02) 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-06-13T20:59:15.743713Z DEBUG ThreadId(02) 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 [14:59:15.735] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierSetFilterInfo' was not executed as it had non-fatal validation errors: None of PACT_DESCRIPTION, PACT_PROVIDER_STATE or PACT_PROVIDER_NO_STATE were set in the environment [14:59:15.725] INFO (90906): pact@11.0.2: Verifying provider [14:59:15.735] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierSetConsumerFilters' was not executed as it had non-fatal validation errors: Either no consumerFilters option provided, or the array was empty [14:59:15.735] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierSetFailIfNoPactsFound' was not executed as it had non-fatal validation errors: No failIfNoPactsFound option provided [14:59:15.735] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: No customProviderHeaders option provided [14:59:15.736] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: No pactUrls option provided [14:59:15.736] DEBUG (90906): pact-core@13.13.5: the optional ffi function 'pactffiVerifierAddProviderTransport' was not executed as it had non-fatal validation errors: No additional provider transports provided [14:59:15.732] INFO (90906): pact-core@13.13.5: Verifying Pacts. [14:59:15.733] INFO (90906): pact-core@13.13.5: Verifying Pact Files [14:59:15.733] DEBUG (90906): pact-core@13.13.5: Initalising native core at log level 'DEBUG' 2023-06-13T20:59:16.281088Z INFO ThreadId(02) pact_verifier::pact_broker: Fetching path '/' from pact broker 2023-06-13T20:59:16.281462Z DEBUG tokio-runtime-worker hyper::client::connect::dns: resolving host="localhost" 2023-06-13T20:59:16.282985Z DEBUG ThreadId(02) hyper::client::connect::http: connecting to [::1]:9292 2023-06-13T20:59:16.283349Z DEBUG ThreadId(02) hyper::client::connect::http: connected to [::1]:9292 2023-06-13T20:59:16.283928Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 155 bytes 2023-06-13T20:59:16.293714Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers 2023-06-13T20:59:16.293743Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (4300 bytes) 2023-06-13T20:59:16.293784Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed 2023-06-13T20:59:16.293815Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292) 2023-06-13T20:59:16.294215Z DEBUG ThreadId(02) pact_verifier::pact_broker: Link URL is templated 2023-06-13T20:59:16.294306Z DEBUG ThreadId(02) pact_verifier::pact_broker: templated URL = http://localhost:9292/pacts/provider/{provider}/for-verification 2023-06-13T20:59:16.295418Z DEBUG ThreadId(02) pact_verifier::pact_broker: final URL = http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification 2023-06-13T20:59:16.295499Z INFO ThreadId(02) pact_verifier::pact_broker: Fetching path '/pacts/provider/e2e%20Provider%20Example/for-verification' from pact broker 2023-06-13T20:59:16.295528Z DEBUG ThreadId(02) hyper::client::pool: reuse idle connection for ("http", localhost:9292) 2023-06-13T20:59:16.295610Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 211 bytes 2023-06-13T20:59:16.318444Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers 2023-06-13T20:59:16.318464Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (2554 bytes) 2023-06-13T20:59:16.318482Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed 2023-06-13T20:59:16.318508Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292) 2023-06-13T20:59:16.318690Z DEBUG ThreadId(02) pact_verifier::pact_broker: templated URL = http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification 2023-06-13T20:59:16.319412Z DEBUG ThreadId(02) pact_verifier::pact_broker: final URL = http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification 2023-06-13T20:59:16.319474Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification using POST: {"providerVersionTags":["master"],"includePendingStatus":true,"consumerVersionSelectors":[{"matchingBranch":true}],"providerVersionBranch":"master"} 2023-06-13T20:59:16.319515Z DEBUG ThreadId(02) hyper::client::pool: reuse idle connection for ("http", localhost:9292) 2023-06-13T20:59:16.319607Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 421 bytes 2023-06-13T20:59:16.333702Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers 2023-06-13T20:59:16.333720Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is content-length (165 bytes) 2023-06-13T20:59:16.333735Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body completed 2023-06-13T20:59:16.333768Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("http", localhost:9292) 2023-06-13T20:59:16.334098Z ERROR ThreadId(02) pact_verifier: Failed to load pact - Could not load pacts from the pact broker 'http://localhost:9292' 2023-06-13T20:59:16.334130Z WARN ThreadId(02) pact_matching::metrics: ```

msiles
2023-06-13 21:58
```Please note: We are tracking events anonymously to gather important usage statistics like Pact version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'. 2023-06-13T20:59:16.337991Z DEBUG ThreadId(02) pact_matching::metrics: Sending event to GA - {"tid": "UA-117778936-1", "cid": "21f374b6ee8766d5fa78d27c9b22ecfb", "av": "13.13.5", "an": "pact-core", "aip": "true", "t": "event", "cd6": "pact_ffi", "cd7": "1.0.4", "aid": "pact-core", "v": "1", "ds": "client", "cd2": "unknown", "ec": "ProviderTest", "cd3": "macos-x86_64", "el": "Pacts verified", "ea": "Completed", "ev": "0"} 2023-06-13T20:59:16.714840Z DEBUG tokio-runtime-worker hyper::client::connect::dns: resolving host="http://www.google-analytics.com" 2023-06-13T20:59:16.806869Z DEBUG ThreadId(02) hyper::client::connect::http: connecting to 216.239.36.178:443 2023-06-13T20:59:16.874056Z DEBUG ThreadId(02) hyper::client::connect::http: connected to 216.239.36.178:443 2023-06-13T20:59:16.957343Z DEBUG ThreadId(02) h2::client: binding client connection 2023-06-13T20:59:16.957394Z DEBUG ThreadId(02) h2::client: client connection bound 2023-06-13T20:59:16.957428Z DEBUG ThreadId(02) h2::codec::framed_write: send frame=Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 } 2023-06-13T20:59:16.957677Z DEBUG ThreadId(02) hyper::client::pool: pooling idle connection for ("https", http://www.google-analytics.com) 2023-06-13T20:59:16.957687Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=WindowUpdate { stream_id: StreamId(0), size_increment: 5177345 } 2023-06-13T20:59:16.958342Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) } 2023-06-13T20:59:16.958401Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) } 2023-06-13T20:59:17.034767Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Settings { flags: (0x0), max_concurrent_streams: 100, initial_window_size: 1048576, max_header_list_size: 65536 } 2023-06-13T20:59:17.034815Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Settings { flags: (0x1: ACK) } 2023-06-13T20:59:17.034832Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=WindowUpdate { stream_id: StreamId(0), size_increment: 983041 } 2023-06-13T20:59:17.095060Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Settings { flags: (0x1: ACK) } 2023-06-13T20:59:17.095096Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::settings: received settings ACK; applying Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 } 2023-06-13T20:59:17.118661Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) } 2023-06-13T20:59:17.118723Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(1) } 2023-06-13T20:59:17.118746Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) } 2023-06-13T20:59:17.118759Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_read: received frame=Ping { ack: false, payload: [0, 0, 0, 0, 0, 0, 0, 0] } 2023-06-13T20:59:17.118768Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=Ping { ack: true, payload: [0, 0, 0, 0, 0, 0, 0, 0] } Failures: 1) Failed to load pact - Could not load pacts from the pact broker 'http://localhost:9292' There were 1 pact failures 2023-06-13T20:59:17.119083Z DEBUG ThreadId(02) pact_plugin_driver::plugin_manager: Shutting down all plugins 2023-06-13T20:59:17.119132Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::codec::framed_write: send frame=GoAway { error_code: NO_ERROR, last_stream_id: StreamId(0) } 2023-06-13T20:59:17.119161Z DEBUG tokio-runtime-worker Connection{peer=Client}: h2::proto::connection: Connection::poll; connection error error=GoAway(b"", NO_ERROR, Library) 2023-06-13T20:59:17.120102Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_shutdown FFI function invoked 1) validates the expectations of Matching Service 0 passing (1s) 1 failing 1) Pact Verification validates the expectations of Matching Service: Error: Verfication failed```


tjones
2023-06-13 22:02
That example doesn?t use a local broker, so presumably you?ve changed it somewhat

tjones
2023-06-13 22:02
Is your broker running?

msiles
2023-06-13 22:04
yes, it?s running

msiles
2023-06-13 22:04
I published the contract and then I ran the provider tests

matt.fellows
2023-06-13 23:13
My guess is the consumer contract is not tagged, and is not matching the selectors

matt.fellows
2023-06-13 23:14
```http://localhost:9292/pacts/provider/e2e%20Provider%20Example/for-verification using POST: {"providerVersionTags":["master"],"includePendingStatus":true,"consumerVersionSelectors":[{"matchingBranch":true}],"providerVersionBranch":"master"}``` That says ?find pacts in the broker that have a matching branch (`master`)?

matt.fellows
2023-06-13 23:14
Is the consumer contract tagged with the `master` branch?

msiles
2023-06-14 03:05
sorry, I was away?

msiles
2023-06-14 03:11
is the branch name affecting this?

tjones
2023-06-14 03:58
Yes. The example you are looking at is selecting the branch as master

msiles
2023-06-14 04:04
so, line 58 should be something like ```process.env.GIT_BRANCH || 'master',```

tjones
2023-06-14 04:08
No, that line is about what to tag the provider with

tjones
2023-06-14 04:09
Line 59 is the one you need to update, to get the branch from git or whatever you use

msiles
2023-06-14 04:10
I just put the branch name hardcoded and it worked? I?m wondering why it was working before in another branch

tjones
2023-06-14 04:10
I would guess that `GIT_BRANCH` is not set by your CI, so you're getting the default of `'master'`

tjones
2023-06-14 04:10
really that example should be updated to not hard code that bit.

msiles
2023-06-14 04:12
anyway, you guys helped me to point out the issue :+1:

tjones
2023-06-14 04:12
but it's hard to produce a universal example, because what if they're not using git

prakhar.roy371
2023-06-14 05:21
has joined #pact-js

john.joel.thetla
2023-06-14 10:16
has joined #pact-js

msiles
2023-06-14 14:25
Hi again, is this a valid solution? or is there a better way to do get the branch name? ```import { exec } from 'child_process'; const getBranch = () => new Promise((resolve, reject) => { return exec('git rev-parse --abbrev-ref HEAD', (err, stdout, stderr) => { if (err) reject(`getBranch Error: ${err}`); else if (typeof stdout === 'string') resolve(stdout.trim()); }); }); export { getBranch }``` ```// --- --- Another File / Module --- --- import { getBranch } from './moduleLocation.mjs' const someAsyncFunction = async () => { console.log(await getBranch()); } someAsyncFunction();```

tjones
2023-06-14 14:28
Usually you would get it from an environment variable that is set automatically by your CI

msiles
2023-06-14 14:30
that?s what I thought, but how can I run the provider tests locally... or am I misunderstanding the workflow?

msiles
2023-06-14 14:31
or should I replace the branch name manually every time I wanna run the tests locally?

tjones
2023-06-14 14:35
I don?t personally use the matching branch thing, I?m not sure how it?s supposed to work in that case

tjones
2023-06-14 14:36
I think matching branch is for when you want the consumer and the provider?s feature branches to be named the same. I?m not sure why it?s in that example

msiles
2023-06-14 14:36
ok, so if that?s the case I think I can get rid of it

msiles
2023-06-14 15:29
I?m gonna use the ```pactUrls: [...]``` that solves my issue

drew.bowman
2023-06-14 18:05
has joined #pact-js

devwenzel
2023-06-15 08:26
has joined #pact-js

ronen.yurik
2023-06-15 13:34
has joined #pact-js

matthew.finbury
2023-06-15 13:39
has joined #pact-js

anthony.sharp
2023-06-15 13:43
has joined #pact-js

mariane.leite
2023-06-15 15:25
has joined #pact-js

tony.nguyen
2023-06-15 18:31
Hi team, we trying to run verifier for our provider. However we want to break each interaction/state of the provider into separate test files. Currently, it looks like each test is overwriting the previous one, cause only the last test to verify one interaction.

matt.fellows
2023-06-15 21:52
Yes, at the moment that?s the cases. You could split the state handlers across multiple tests, but not the individual interactions. What?s the aim Tony?

matt.fellows
2023-06-15 21:53
So Moises doing that is not ideal - you do really want to pull dynamically from the broker

matt.fellows
2023-06-15 21:54
See the ci/cd workshop :point_down: (howtolearn) for a lab on how to achieve a solid pipeline setup

2023-06-15 21:54
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

matt.fellows
2023-06-15 21:55
the get branch thing above should be fine.

matt.fellows
2023-06-15 21:55
It?s a reminder - we should aim to pull that automatically from the verifier. I?ll raise a feature request

msiles
2023-06-15 22:01
thanks @Matt (http://pactflow.io / pact-js / pact-go), so does that mean that it?s ok if we create a ?getBranch? function as a workaround to get it locally? currently we are starting with the contract test, we don?t have the ci/cd implemented yet, we are running the tests locally (docker locally). The goal is to implement the ci/cd later

msiles
2023-06-15 22:02
I heading out, but I?ll check later when I go back


msiles
2023-06-16 03:50
so, it?s possible to have multiple contracts, for instance, if my app has 3 modules (accounts, reports, contacts) can I have 1 contract per module? and multiple consumer/provider files? or in real life, it doesn?t work like that

matt.fellows
2023-06-16 07:51
A contract is between a single consumer and a single provider. If the provider has 3 modules in it, that would usually be detail within the contract. You could model it that a provider is 3 applications, but it complicates your CI/CD pipeline and I wouldn?t advise it

matt.fellows
2023-06-16 07:51
what are you trying to achieve by splitting it?

wvkehoe
2023-06-16 10:27
has joined #pact-js

msiles
2023-06-16 15:40
you are right, what I was thinking is that having a huge file with many tests can be hard to read or maintain. I?m still learning about contract tests, so that?s what I was asking about best practices

rost.khanyukov
2023-06-16 22:59
has joined #pact-js

mich.krzyzanowski
2023-06-17 15:22
has joined #pact-js

f.barril
2023-06-18 16:58
has joined #pact-js

f.barril
2023-06-18 16:59
Hi team, I am trying to use pact in node.js but I am getting the following error `Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /home/node/app/node_modules/@pact-foundation/pact-core/build/Release/libpact_ffi.so)` any idea what might be ? I've googled it but I didn't find useful information , I can provide more info if you need

matt.fellows
2023-06-18 23:39
That is a required library for Pact to run. It should be bundled into the package

matt.fellows
2023-06-18 23:39
are you having any install warnings/errors?

matt.fellows
2023-06-18 23:40
Can you see if there is a `libpact_ffi.so` file anywhere in your `node_modules`?

matt.fellows
2023-06-18 23:40
What os/arch are you actually running?

delboy1978uk
2023-06-20 07:46
has joined #pact-js

hammid.funsho
2023-06-20 22:18
has joined #pact-js

benjamine.nidhin
2023-06-21 12:15
has joined #pact-js

msiles
2023-06-21 21:41
Hi All, in the body section, does that mean that my json is 11106 length? ```Pact verification failed! Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was not expected: Method: POST Path: /api/1/users Headers: accept-encoding: gzip, deflate connection: close content-length: 11106 content-type: application/json; charset=utf-8 host: 127.0.0.1:49724 Body: [{"account":{"accoun... (11106 length) 1) The following request was expected but not received: Method: POST Path: /api/1/users Headers: Content-Type: application/json; charset=utf-8 2) "after each" hook for "creates a new user"```

matt.fellows
2023-06-21 21:50
Yep

kuksa.vladyslav
2023-06-22 12:47
has joined #pact-js

suryasaharan
2023-06-22 15:41
has joined #pact-js

msiles
2023-06-22 20:14
Hi guys, I?m getting the following error running the provider tests, does that means that there is a failure even if it?s green? ``` a request for all employeess Given Has some employees returns a response which has status code 200 (OK) includes headers "Content-Type" with value "application/json; charset=utf-8" (OK) has a matching body (OK)```

msiles
2023-06-22 20:15
``` a request for one employee Given Has some employees Request Failed - One or more of the setup state change handlers has failed```

gabriel
2023-06-22 21:22
has joined #pact-js

msiles
2023-06-22 21:32
similar question, what could be the reason for getting these failures? and the same code is currently working on other computer? We are using the same branch but currently is throwing these errors on my end. What should I review first? ``` a request for all projects Given Has some projects Request Failed - One or more of the setup state change handlers has failed a request for projects by employee Given Has some projects Request Failed - One or more of the setup state change handlers has failed a request to create a new reason Given is authenticated Request Failed - One or more of the setup state change handlers has failed```

matt.fellows
2023-06-22 21:45
> ```One or more of the setup state change handlers has failed``` that is a hint

matt.fellows
2023-06-22 21:45
Give `<state>`

matt.fellows
2023-06-22 21:45
make sure the state handlers for those states are registered and working

matt.fellows
2023-06-22 21:45
How you you running the verification? Do you have `pending` enabled? http://docs.pact.io/pending

matt.fellows
2023-06-22 21:46
are there any additional logs?

msiles
2023-06-22 21:47
but the same code is working in his local? he?s running windows, I?m running mac, but we are using the same branch with the latest :face_with_diagonal_mouth:

msiles
2023-06-22 21:48
it?s enabled enablePending: true,

matt.fellows
2023-06-22 21:50
that?s why it can ?fail? but not fail your build

matt.fellows
2023-06-22 21:50
see the link above for more

matt.fellows
2023-06-22 21:51
They might need to do some debugging. For one, start with increasing verbosity of log levels

msiles
2023-06-22 21:53
regarding logs, the only way to check the output is from the terminal, right?

msiles
2023-06-22 22:00
I?m asking because depending on the log level a lot of information will be printed in the terminal, including the big responses we are using? and the terminal is kind of cutting the information from the top

matt.fellows
2023-06-22 22:40
> and the terminal is kind of cutting the information from the top wha? What terminal are you usinsg? You should be able to make it not do that (usually scroll/buffer)

tjones
2023-06-22 22:44
Also, that doesn?t look like a failure

tjones
2023-06-22 22:46
In that case I would pipe it to a file. I thought pact would tell you which state handler failed even on non-debug mode though. Is there an error elsewhere in the log?

tjones
2023-06-22 22:46
a state handler failing means there?s an error in your test setup code - in the handler for setting up state

matt.fellows
2023-06-23 00:15
> In that case I would pipe it to a file. I thought pact would tell you which state handler failed even on non-debug mode though. Is there an error elsewhere in the log? yes it should be in the log output. This part is printed by the core (albeit I think the core should print out which state failed - i?ll raise a request)

matt.fellows
2023-06-23 00:15
yep

matt.fellows
2023-06-23 00:16
We really need a little more info in these reports Moises. Without context, we are guessing. See howtorepro for the ideal case, but at the very least, is it a consumer/provider test, code snippets to show what you?re doing, log outputs would all go a long way to help


msiles
2023-06-23 14:00
I?m using the zsh terminal from visual studio, I?ll take a look again.

msiles
2023-06-23 21:11
for instance, am I doing something wrong here. Warning from the output ```2023-06-23T20:20:17.460373Z INFO ThreadId(12) pact_verifier: Running teardown provider state change handler 'Has some links' for 'a request for all links' [14:20:17.455] WARN (89283): pact@11.0.2: no state handler found for state: "Has some links"```

msiles
2023-06-23 21:12
``` describe('when a call to list all links from something', () => { describe('and the user is authenticated', () => { describe('and there are links in the database', () => { before(() => provider.addInteraction({ state: 'Has some links', uponReceiving: 'a request for all links',```

matt.fellows
2023-06-26 02:17
I just checked the source code, and it should be printing errors for the states that have failed. I suspect something is awry with your logging to terminal

bgrgincic
2023-06-26 11:00
has joined #pact-js

msiles
2023-06-26 13:41
I just downloaded the code again on another computer that I got, and I'm not getting the errors there... that's odd. Probably something got corrupted

sreenivas.chaitanya
2023-06-26 15:23
does pact allow us to update the default broker port?

matt.fellows
2023-06-26 22:24
Chaitanya, please try googling it or better - searching on http://docs.pact.io Once you have found your answer, please try it out. If what you are trying hasn?t worked, please come back and explain what you are trying to do, what you?ve tried, and what?s not working. See howtoask

2023-06-26 22:24
Please see this page for some tips on how to ask for help to get the best response from the community https://docs.pact.io/help/how_to_ask_for_help

sreenivas.chaitanya
2023-06-27 08:22
iam trying to publish my sample pacts to my central broker and it is throwing error inside the pact library , I have googled it but could not find a relevant example. it errors on port as connection refused .

svilen.popov
2023-06-27 09:44
has joined #pact-js

matt.fellows
2023-06-27 11:24
Please see the other thread where you have the problem. You think the problem is the port, but if you provide the logs as requested we might be able to understand the real root cause. Changing the port is as simple as updating the URI you are publishing to, but that may not be the real issue (I suspect it?s something else)

matt.fellows
2023-06-27 11:24
seeing the logs will give us visibility into your issue


matt.fellows
2023-06-27 11:26
For context: I?m currently reasonably confident that the issue is a configuration problem with your pact broker, and the verbose logs will confirm that theory.

sreenivas.chaitanya
2023-06-27 11:38
```"test:publish": "pact-broker publish ./pacts --consumer-app-version=1.0.1 --auto-detect-version-properties --broker-base-url=https://ysi5tc076m.execute-api.eu-west-2.amazonaws.com:80 --broker-username user --broker-password pass --verbose"```

sreenivas.chaitanya
2023-06-27 11:39
I have tried this and the output I get is same as above

sreenivas.chaitanya
2023-06-27 12:03
do u mean the way the broker is setup ? I can log into the broker url normally

sreenivas.chaitanya
2023-06-27 12:04
do u think being in aws its restricted on access?? due to firewalls?

sreenivas.chaitanya
2023-06-27 12:41
this is my pact broker screen

matt982
2023-06-27 16:02
has joined #pact-js

matt982
2023-06-27 16:07
Afternoon all. I?m looking at using Pact to verify message event communication via https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage. Can?t seem to find anything on the web that covers this. The scenario: ? a parent web app embeds an iframe ? and needs to send data to that iframe ? so it uses `postMessage` to do so ? and the child iframe also sends data back to the parent frame via `postMessage` So I want to be able to verify the shape of the data that is sent via `postMessage`. Ideas on where to start? I?ve had a look at a lot of the videos and articles, and from what I can see, a Pact Provider needs to be one of the existing providers listed here: https://docs.pact.io/implementation_guides/workshops#providers But I might be missing something :nerd_face:

matt.fellows
2023-06-27 22:14
that confirms the problem for me

matt.fellows
2023-06-27 22:15
note in the ?Response body? section, the links are all `http`, but in the ?Explorer? section (and presumably the address bar) it?s a secure `https` link? That?s why it?s publishing to port `80` and failing.


tjones
2023-06-28 00:25
This is a cool use case. It?s not really obvious from the pact message documentation, but a message pact is really just a function call

tjones
2023-06-28 00:26
You would have your provider verification mock `postMessage`. You would have your consumer test implement something that calls `postMessage` with the data you?re expecting.


tjones
2023-06-28 01:45
Probably what you'd do is actually test your listener - and not involve the iframe at all

tjones
2023-06-28 01:46
most of the Pact message examples do this - eg, an example for SQS doesn't have a real SQS queue at any point. This is different to how Pact does HTTP testing

matt982
2023-06-28 07:54
@tjones Brilliant, thanks for that! I was wondering if something that might be the case. I realised that my scenario was analogous to a queue, like the Kafka example, but couldn?t quite work out how to string it together. I?ll have another dig around, and if we end up going for it, will post back here.

tjones
2023-06-28 08:21
It's definitely an appropriate use case. You might have to jump through more hoops if you want to actually send a message across a real iframe as part of the test, but it's possible.

matt982
2023-06-28 08:39
I?ll try and keep it as simple as possible :nerd_face:

matt.fellows
2023-06-28 12:28
we really could do with better docs / examples on what ?message pact? can do. It?s not obvious it?s very general and can be used in a lot of weird and wonderful ways

matt.fellows
2023-06-28 12:28
If you get ^^ to work and you?re up for it, perhaps a PR to https://docs.pact.io/recipes would be helpful?

matt982
2023-06-28 13:36
@matt.fellows thanks for the message :flag-au: Yes, will try to do so if we go with Pact. Do you have anything else to add to what @tjones said?

eltonlinconl07
2023-06-28 17:30
has joined #pact-js

carlosmmelo
2023-06-29 07:00
has joined #pact-js

matt982
2023-06-29 08:33
A good UK morning to everyone :slightly_smiling_face: I?ve just raised a tiny PR here: https://github.com/pact-foundation/pact-js/pull/1097 The https://github.com/pact-foundation/pact-js/blob/master/CONTRIBUTING.md#contributing mention a #pact-js-development channel, but I can?t see one.

matt982
2023-06-29 08:47
Oh, I can see the channel now :tada:

prerit.jain849
2023-06-29 09:40
has joined #pact-js

sssona09
2023-06-29 11:12
has joined #pact-js

tjones
2023-06-29 11:13
:taco: for @matt982!!

antonio.blandon
2023-06-29 20:40
has joined #pact-js

arjun
2023-07-02 04:23
has joined #pact-js

adwait.damle
2023-07-03 06:39
has joined #pact-js

stan.amsellem
2023-07-03 14:00
has joined #pact-js

stan.amsellem
2023-07-03 14:07
Hey there, I am in the process of designing an intensive software engineering bootcamp aimed at developers with +3 years of experience, that I?ll be launching by the end of the year. The program leverages the benefits of open source projects as a learning platform. Essentially, participants will be divided into small groups of four, and they will delve into advanced concepts such as software architecture, TDD, observability, documentation, and so on. *These concepts will be practically applied through their work on diverse open source projects.* With that in mind, I'm reaching out to various communities to gauge the interest in having a team of four software engineers (and their tech lead mentor) contribute 2/3rd-time to the pact codebase for a period of one month. I believe this could provide a unique learning opportunity for the participants (whom we refer to as 'runners'), while potentially offering value to your project. For this arrangement to be most beneficial, it would be ideal to establish a liaison within someone in your community who could guide our runners. This point person could assist them in selecting suitable issues to tackle and ensure they are well-versed in the project's philosophy. Would this proposal be of interest to you?

yousafn
2023-07-03 17:21
Hey, Sounds interesting, loving the ethos. Would this course be free or chargeable? Pact is maintained by volunteers, so whilst it would be advantageous to increase our contributor base, I would worry about the expectation placed on a volunteer(s) to provide time. We have a community forum (here) where we have some regular visitors and the majority which are more transient. We are hosting a celebration of Pact in October, which will have some hackathon challenges, and roadmap items to pick up on and we are working this year on improving our maintainer and contributor documentation, which may allow for this work to be picked up more autonomously. Ie. the projects philosophy should be open and freely available and legible to anyone to read, understand and contribute value, without necessarily getting one on one time with a maintainer. That is with my maintainer and community conscientious hat on, you might find that some community members might jump at the chance as it highly aligns with their own personal goals.

cobookman
2023-07-03 21:14
has joined #pact-js

matt.fellows
2023-07-04 01:12
Love this idea! :heart:

anshu.behera.02
2023-07-04 07:01
has joined #pact-js

adam.strawson
2023-07-04 13:24
has joined #pact-js

mathewsa
2023-07-04 15:20
has joined #pact-js

olopezs
2023-07-04 16:03
has joined #pact-js

tonis.ojandu
2023-07-05 06:51
@tonis.ojandu has left the channel

nithesh
2023-07-05 08:14
has joined #pact-js

andre.tartarelli
2023-07-05 11:26
has joined #pact-js

laura.huysamen
2023-07-05 12:38
has joined #pact-js

goatleyj11
2023-07-05 12:43
has joined #pact-js

lily.oconnell
2023-07-05 15:32
has joined #pact-js

mohanraj.r
2023-07-05 19:53
has joined #pact-js

lcruz
2023-07-06 00:34
:wave: Hey folks. Had a quick question and I'm not sure if there's a know GH issue around it or this has been asked previously in slack. We've been running into an issue with spinning up the mock provider at runtime when using node 18: ``` connect ECONNREFUSED ::1:8080``` Making a switch back to 16 works. Curious if there's been a solution to this or path forward? We're looking to start running things in CI and wondering if we'd have to pull down a specific node docker container when running pact tests.

matt.fellows
2023-07-06 00:53
It?s to do with networking changes in Node 18+

matt.fellows
2023-07-06 00:53
If you manually set the host to `127.0.0.1` that will probably address it (i.e. an ipv4 address)

matt.fellows
2023-07-06 00:54
I can?t remember the specifics, but it?s something like by default `localhost` maps to `::1` on on ipv6 networks

lcruz
2023-07-06 01:15
Ah copy that. Thanks Matt. Let me try manually setting the host.

ianlutz
2023-07-06 01:34
has joined #pact-js

tjones
2023-07-06 03:01
There's also a change to the way that connection pooling works. The details are in the node release notes, and also on an issue in github I think

rohit.m.patil27
2023-07-06 03:51
has joined #pact-js

matt.fellows
2023-07-06 05:02
Thanks, I meant to send that link but clearly I got side tracked

timo.schwarzer
2023-07-06 06:18
has joined #pact-js

kuntol.banerjee
2023-07-06 06:54
has joined #pact-js

adebakre
2023-07-06 11:28
has joined #pact-js

lcruz
2023-07-06 15:52
FWIW - I did come across the relevant Pact GH issues: ? https://github.com/pact-foundation/pact-js/discussions/1083 ? https://github.com/pact-foundation/pact-js/issues/1066 I changed refs to `localhost` to `127.0.0.1` but to no avail: ```const provider = new Pact({ consumer: consumerName, provider: providerName, host: '127.0.0.1', port: 8080, log: path.resolve(process.cwd(), 'logs', 'pact.log'), dir: pactDir, });``` I'm also on `arm64` if that helps

lcruz
2023-07-06 15:55
Ah. Nevermind. I forgot to change `localhost` at the actual callsite when making a call with axios.

lcruz
2023-07-06 15:56
working now -- apologize for the additional noise!

rajkumarbapuvrs
2023-07-06 17:35
has joined #pact-js

jorge.carneiro
2023-07-07 09:43
has joined #pact-js

carlleferink
2023-07-07 12:01
has joined #pact-js

anju.ashk
2023-07-10 07:39
has joined #pact-js

rmahadeorathod
2023-07-10 09:48
has joined #pact-js

ekaterina.essina
2023-07-10 09:59
has joined #pact-js

arca.artem
2023-07-10 10:00
has joined #pact-js

connor.stevens
2023-07-10 11:35
has joined #pact-js

mssachin
2023-07-10 13:36
Hello folks I get this error pact-core@13.15.0: Failed to initialise native module for win32-x64: Error: No native build was found for platform=win32 arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.16.0

mssachin
2023-07-10 13:37
Not much available for this. I am digging in

mssachin
2023-07-10 13:37
please if anyone encountered this before please give me a shout

yousafn
2023-07-10 13:44
1. can you try the latest version of pact-js v12 2. prior to that, are your tests failing, or are you just seeing an error? a. can you run with `LOG_LEVEL=debug`

mssachin
2023-07-10 14:07
Tests are failing. I have done debug log level now

mssachin
2023-07-10 14:08
with 12.0.0 I do not get the error but tests fail

mssachin
2023-07-10 14:11
The tests timeout

yousafn
2023-07-10 14:13
have the tests passed before?

mssachin
2023-07-10 14:37
No first time writing these set of tests

yousafn
2023-07-10 14:42
then please ask a decent question, we aren?t a general support helpdesk


mssachin
2023-07-10 14:43
Sir I have written several tests before they passed

mssachin
2023-07-10 14:43
tried today and they are failing

mssachin
2023-07-10 14:43
Anyways I will di in

yousafn
2023-07-10 14:44
> No first time writing these set of tests that implies it the first time?

yousafn
2023-07-10 14:45
unless its a typo and it is mean to say not. Can you share a reproducible example. could you let us know which version it passed in, if it did before (that exact test)

adam.witko
2023-07-10 14:53
Hey hey, I am trying to figure out an issue we're seeing on the provider verification side when it is invoked by a webhook. We have 2 providers in one repository and when the pact url is specified and we run that verifier flow, it's executing against more than the single provider the pact specifies within the consumer contract. I would assume that if a pact url is specified but the provider does not match my providers (provider-a) verification that it will ignore any pacts desinted for provider-b. Is there another step required to filter the provider verification tests to only run against the provider the pact is for?

yousafn
2023-07-10 14:56
what parameters are you passing when doing a verification by pact url? you should be omitting any consumer version selectors, enabling pending and wip pacts

adam.witko
2023-07-10 14:58
``` const failIfNoPactsFound = false const coreOptions: PactMessageProviderOptions = { messageProviders: options.messageProviders, publishVerificationResult: options.pipelineExecution, provider: options.provider, pactBrokerUsername: options.authentication.username, pactBrokerPassword: options.authentication.password, providerVersion: options.version, providerVersionBranch: options.branch, logLevel: options.logLevel || 'error', failIfNoPactsFound, } const buildOptions = { pactBrokerUrl: config.pactBrokerUrl, enablePending: true, consumerVersionSelectors: [ { mainBranch: true, }, { deployedOrReleased: true }, { matchingBranch: true }, ], includeWipPactsSince: options.workInProgressPactsSince, } const verifierOptions = options.pactUrl ? { ...coreOptions, pactUrls: [options.pactUrl], ...customOptions } : { ...coreOptions, ...buildOptions, ...customOptions } const verifier = new MessageProviderPact(verifierOptions) return verifier.verify()``` So as the pactUrl is specified, it omits the `buildOptions` therefore it doesn't verify any pending pacts, wip pacts, or have any consumer version selectors. The verification when the provider is being changed and ensuring it's not breaking any existing pacts is great, it's when the pact url is specified and there are multiple providers in this one repository.

adam.witko
2023-07-10 14:59
I'd have thought that if you specify `pactUrls` and those are the only pacts you will verify, the providers specified in the pact contract contents must match the provider being ran :confused:

yousafn
2023-07-10 15:10
I don?t believe it will consider the `provider` option and instead verify whatever is in the url, when doing an url based verification it isn?t acting as a filter, as you are expecting, I would need to check the source. there is a consumer filter `pactffi_verifier_set_consumer_filters` where you can filter consumers, again not sure if that takes effect if the pact url is set, or just on dynamically fetched pacts, we would need to check the pact-js verifier code and the rust verifier code.

yousafn
2023-07-10 15:12
so when the pact url is used, I assume this is being invoked by a webhook? the webhook says for example consumer-blah-provider-a Are you receiving one single webhook? are you then invoking one single verifier job? or are you invoking two?

yousafn
2023-07-10 15:14
> ``` const verifierOptions = options.pactUrl > ? { ...coreOptions, pactUrls: [options.pactUrl], ...customOptions } > : { ...coreOptions, ...buildOptions, ...customOptions }``` This looks right to me. sounds like you have a pact url called `example consumer-blah-provider-a` provider opt of `provider-b` and your expectation is that it shouldn?t run a test?

yousafn
2023-07-10 15:15
> We have 2 providers in one repository and when the pact url is specified and we run that verifier flow, it?s executing against more than the single provider the pact specifies within the consumer contract. I think I need a bit more detail around this. When is the pact url being specified how do you isolate the verifications between the two separate providers, that reside in the same codebase are they using the same file?

adam.witko
2023-07-10 15:28
> so when the pact url is used, I assume this is being invoked by a webhook? Yes. Each provider in this single repository has its own webhook. This URL is an example of the PACT_URL being provided by the webhook invoked triggerd https://pact-broker.localhost.io/pacts/provider/provider-a/consumer/consumer-a/pact-version/baf6a693b29853c165bc3e074effa27e9192f566/metadata/Y3ZuPWNiZGNjZmEyJnc9dHJ1ZQ. > Are you receiving one single webhook? Yes, each provider in this repository has its own webhook defined and will specify in the url the provider it is so provider-a or provider-b. I am receiving 1 webhook triggered pipeline with the above url. So no mention anywhere in the pipeline being triggered of `provider-b` . > provider opt of `provider-b` > > and your expectation is that it shouldn?t run a test? Yes exactly that. The above url is being specified and running the 'webhook verify flow' in our pipeline. It is running each of the unique provider verification test files in the repo with the pact url. The provider that has a different matching name than what's in that URL (i.e. url says provider-a but provider-b is executing too) or within the contract file itself is being executed and failing. `provider-a`verification is running as expected and passing but `provider-b` is also being executed and failing. > how do you isolate the verifications between the two separate providers, that reside in the same codebase are they using the same file? So they are two completely separate verification test files that use the options specified https://pact-foundation.slack.com/archives/C9VBGLUM9/p1689001131963479?thread_ts=1689000821.597169&cid=C9VBGLUM9 and the only major difference is the provider name and any messageProviders/stateHandlers. Unless I am missing a simple way to support multiple providers in the same project each with their own unique webhook (1 webhook per provider) then I think there may be only one solution. When the pact url is specified there needs to be manual filtering of which provider verification test files to run as it doesn't look like the pact url provider or the provider within the consumer contract are checked when the provider is ran.

yousafn
2023-07-10 15:40
ahh so any time one of two webhooks fire, both verification jobs fire, because they hit a single pipeline task. Gotcha. So for now I would use a webhook param to identify the provider name and only trigger the relevant one of the two verification jobs. For it pact side - Would probably need to get the thinking hat on as to what the user facing behaviour would or should be the case if. you provide a pact url for a provider, but specify a different provider ? should the test fail, pass or warn? its quite an assumption that only one of the three would be relevant as people may have separate use cases, some may want to know as they may have a misconfigured webhook.

adam.witko
2023-07-10 15:43
Hmmm yes. Thanks, I'll solve it for my company but I'd be interested to see if it could progress somehow in to the pact verification flow itself. However it works, if the contract specified provider != the provider being ran, it should have a flow that doesn't execute the incorrect expectations on a different provider :smile:

adam.witko
2023-07-10 15:49
Cheers for the help @yousafn

yousafn
2023-07-10 16:55
If you try and delete your node_modules and lockfile and reinstall, it should use an older version of pact-js-core - I am not sure if that may solve your issue, its a side effect of some changes we have been implementing. For full details you can see the projects changelogs

mssachin
2023-07-11 06:57
Did not work Yousaf

matt.fellows
2023-07-11 07:04
Can you please share the setup you?re having so we can help?

pgeurtsen
2023-07-11 07:30
has joined #pact-js

adam.witko
2023-07-11 07:36
Is there an applicable repo I should raise an issue for to discussion this?

adam.witko
2023-07-11 07:38
This is what I've got a the minute to circumvent this issue if the verification is executed with a pact file for a different provider

mssachin
2023-07-11 08:15
There is us not much of a setup really 1. Following dev dependencies

mssachin
2023-07-11 08:15
"@pact-foundation/pact": "^11.0.2", "@pact-foundation/pact-node": "^10.17.7",

mssachin
2023-07-11 08:15
and a consumer test

mssachin
2023-07-11 08:16
import { Matchers, Pact} from "@pact-foundation/pact"; import { term } from "@pact-foundation/pact/src/dsl/matchers"; import chai from 'chai'; import chaiHttp from 'chai-http'; import path from "path"; import { v4 as uuidv4 } from 'uuid'; const { expect } = chai; chai.use(chaiHttp); let provider: Pact; const dynamicUUID = uuidv4(); // Generate a dynamic UUID const dynamicPath =  term({ matcher: '.*', generate: '/anyguuuid' }); beforeAll(async () => {   jest.setTimeout(120000);   provider = new Pact({     consumer: 'proxy-api-secret-store-get',     provider: 'secret-store-for-proxy-api-get',     port: 50000,     log: path.resolve('logs', 'pact.log'),     dir: path.resolve('pacts'),     logLevel: 'debug',     pactfileWriteMode: 'overwrite'   });   await provider.setup(); }); beforeEach(() => {   return provider.addInteraction({     state: 'I get credentials',     uponReceiving: 'A Request for obtaining credentials',     withRequest: {       method: 'GET',       path: dynamicPath,       headers: {         'Content-Type': 'application/json',       }     },     willRespondWith: {       status: 200,       headers: {         'Content-Type': 'application/json',       },       body:  {         id: Matchers.term({           generate: "4f2fa219-c805-4781-937c-bf3296e93cc4",           matcher: '.*'         }),         details: Matchers.term({           generate: "some string",           matcher: '.*'         }),       },     },   }); }); it('Gets Credentials from Secret Store and Returns 200', (done) => {   chai     .request("http://127.0.0.1:49999")     .get('/'+dynamicUUID)     .set('Content-Type', 'application/json')     .end((err, res) => {       expect(res.status).to.equal(200);       expect(res.body).to.deep.equal({"id": "4f2fa219-c805-4781-937c-bf3296e93cc4", "details": "some string"})       done();     }); }); afterEach(() => {   return provider.verify(); }); afterAll(async () => {   await provider.finalize(); });

mssachin
2023-07-11 08:16
node version 18.6.0

rjurca
2023-07-11 08:22
has joined #pact-js

matt.fellows
2023-07-11 10:02
I just ran that example locally and it fails, but in an expected way

matt.fellows
2023-07-11 10:02
``` chai .request("http://127.0.0.1:49999") <- this needs to point to the same thing as `port` in the `Pact` setup```

matt.fellows
2023-07-11 10:03
Please next time, create a github project that can be cloned so we can run it out of the box.

matt.fellows
2023-07-11 10:03
> ?@pact-foundation/pact-node?: ?^10.17.7", you shouldn?t need to add this as an explicit dependency

tjones
2023-07-11 10:17
I feel like this is a bug in the pact core. If you get given a contract file that is not for you, you should warn and ignore it I reckon

tjones
2023-07-11 10:17
(You being the pact core, in this case)

matt.fellows
2023-07-11 10:18
Yeah, it?s probably just not a scenario that has been considered. The `provider` name was previously only used as a selector to discover pacts in the broker, and not for much else

matt.fellows
2023-07-11 10:19
in the world of (more) monorepos, this could be a nice quality of life improvement

tjones
2023-07-11 10:19
In 2000, everything was a monorepo. We have come full circle

matt.fellows
2023-07-11 10:20
haha

matt.fellows
2023-07-11 10:23
There are some filter options on the CLI (which is essentially a different interface to the same verification code): https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_verifier_cli Mind raising a feature request there to discuss this use case. Perhaps the solution is to essentially `--filter-provider` (by default) or have that as an explicit option

mssachin
2023-07-11 10:28
I am reinstalling node modules will keep you updated. I should have changed the port in setup my bad.

tjones
2023-07-11 10:30
I?m not sure that filter is the right fit, because filtered results (shouldn?t) be publishable

mssachin
2023-07-11 10:42
apologies mate. Still does not work. To my mind its pretty straight forward. It works for other repos where I have similar tests but node modules were installed much earlier than yesterday. I am now thinking all my previous tests will fail in the pipeline where I do a new npm install

matt.fellows
2023-07-11 11:03
Can you please see if this works: https://github.com/mefellows/20230711-pact-repro

matt.fellows
2023-07-11 11:18
P.S. the build passes on all key OS?s: https://github.com/mefellows/20230711-pact-repro/actions/runs/5519244766/jobs/10064255645 If you can make it fail in an unexpected way we can look into it

yousafn
2023-07-11 11:24
that would be my assumption too, that filtered shouldn?t be publishable. I?d probably start by testing both the rust and ruby core via the cli, as to what happens in this use case (with provider name diff to that in a file), both with a local file and remote file and see if that makes any diff

yousafn
2023-07-11 11:24
> that would be assumption too, that filtered shouldn?t be publishable. Should that apply to all filters, filtered desc vs filtered consumer

tjones
2023-07-11 11:25
> that would be assumption too, that filtered shouldn?t be publishable. It definitely shouldn?t, because if you filter the contract, you?re not adhering to the expectations of the consumer.

yousafn
2023-07-11 11:25
filtered consumer imo should be okay, filtered desc not so okay

yousafn
2023-07-11 11:25
the other three opts there look pact file specific (desc/int/state)

tjones
2023-07-11 11:26
I think they?re different kinds of filter.

yousafn
2023-07-11 11:27
yessum, one being a filter of contracts, one being a filter of interactions within contracts.

yousafn
2023-07-11 11:28
whether either considers which when publishing verification results, is a separate yak shave / disco session :)

yousafn
2023-07-11 11:29
good thing I?m deep diving into the world of verifications this week :sweat_smile: - :party-yak: :razor:

tjones
2023-07-11 11:29
Making a separate thread for verification discussion @yousafn

tjones
2023-07-11 11:29
I think a verification is for a unit (the contract)

tjones
2023-07-11 11:29
If you filter that, you can?t publish it

tjones
2023-07-11 11:29
Because you?re not checking whether the provider provides everything the consumer needs

tjones
2023-07-11 11:30
Now, there are SOME interactions that you might be able to live without

tjones
2023-07-11 11:31
For instance, in server-driven contracts, it doesn?t matter if the client actually hits all the endpoints

tjones
2023-07-11 11:31
This is theory, and not how pact works

tjones
2023-07-11 11:33
But it?s related to the issue where sometimes the consumer can deploy without the provider (and pact doesn?t let you do this)

tjones
2023-07-11 11:33
Eg, in message queues, you could deploy safely without the provider being deployed

yousafn
2023-07-11 11:33
Yeah interesting use case. I agree that if you filter the contract contents you aren;?t checking that the provider can provider everything exactly as the customer has specified it, and therefore a verification result here is deemed as full, even though in reality its a partial. Equally, if the provider utilises requestFilters and modifies the request, they potentially augment the consumer request. I wonder if there is a use case for a coverage metric or some way of saying that ? x amounts of interactions are tested ? x amount havent ? x contract was augmented at verification with a can-i-deploy being able to use that as a confidence level.

tjones
2023-07-11 11:34
> Equally, if the provider utilises requestFilters and modifies the request, they potentially augment the consumer request. This shouldnt? be a feature

tjones
2023-07-11 11:34
(in theory)

yousafn
2023-07-11 11:34
> Eg, in message queues, you could deploy safely without the provider being deployed Yep, so in that scenario depending on the setup, the consumer just emits a message and its never picked up, or it may not be picked up but then sent a DLQ where it could be picked up later

yousafn
2023-07-11 11:34
> Equally, if the provider utilises requestFilters and modifies the request, they potentially augment the consumer request. It?s a dangerous footgun

yousafn
2023-07-11 11:35
but useful all the same

yousafn
2023-07-11 11:35
(I?d probably be jumping through more hoops doing testing in other ways, that I can accept those caveats in my test approach)

yousafn
2023-07-11 11:36
but highlighting that they were used, could be valuable for diagnosing, possibly, idk

tjones
2023-07-11 11:37
My view is that it just needs per-interaction information: ? Needs {provider / consumer} to be present before deployment ? This interaction may be optionally verified (which means that it can be missing at verification, but if present it must be working)

tjones
2023-07-11 11:37
And then you roll that information up to the contract level

tjones
2023-07-11 11:38
This is, of course, an alternative model to Pact.

tjones
2023-07-11 11:38
The optional verification could be supported in the verifier

tjones
2023-07-11 11:39
and I think the needs-present thing is probably implementable with the right misuse of the broker API

yousafn
2023-07-11 13:11
:nodejs: - JavaScripters/TypeScripters/Nodemads We listened to our community, who https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#installation-failing-missing-python-c-or-build-tools with requiring python :python: to install pact-js :pact-open-link: - :js-4699: in order to get at that lovely rust :rust: pact-core functionality in pact-js v10 & v11 and pact-js-core v13 You can now find they both come fully charged :electric_plug: with batteries :battery: included, meaning that supported platforms can use https://www.npmjs.com/package/@pact-foundation/pact/v/12.0.0and https://www.npmjs.com/package/@pact-foundation/pact-core/v/14.0.1with `--ignore-scripts true` and no additional install time build requirements Supported platforms. ? Linux x86_64 / arm64 ? MacOS x86_64 / arm64 ? Windows x86_64 ? https://github.com/pact-foundation/pact-js/blob/master/MIGRATION.md#11xx---12xx ? Troubleshooting ? https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#failed-to-find-native-build ? https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#enoent-no-such-file-or-directory-open-nodepath Hope this helps some of you out.

mssachin
2023-07-11 14:09
my bad man it has got something to do with how my repo is structured. meaning the dev repo

mssachin
2023-07-11 14:09
apologies

mssachin
2023-07-11 14:09
I updgraded to 12 in my old repos and they work just fine

frederic.vaugeois
2023-07-11 14:12
has joined #pact-js

yousafn
2023-07-11 14:27
its ok! thanks for adding the additional context. Great to know your existing projects are working fine on pact-js 12 :rocket: Interesting around how the dev project is structured. Would it happen to be a mono-repo, or using anything like pnpm?

mssachin
2023-07-11 15:07
Will update you soon

marko.lamberg
2023-07-11 15:27
has joined #pact-js

matt.fellows
2023-07-11 22:50
This is awesome work Yousaf (and nice touch updating the troubleshooting / migration notes!) it?s going to make everyone?s lives so much easier! The whole process is much faster now too. Here is the https://github.com/mefellows/pact-js-repro-template/actions/runs/5519609100 running in just a few minutes (like a Node project should :wink: ).

tjones
2023-07-12 04:12
Awesome work

lshilling
2023-07-12 09:31
has joined #pact-js

rudydc
2023-07-12 17:53
has joined #pact-js

aram
2023-07-13 13:05
Hi folks, started getting this on the provider side, any ideas? Nothing was changed on consumer or provider sides ``` Pact::UnexpectedIndex``` _*and*_ ``` * Actual array is too long and should not contain a Hash at $.identity_locations[1]```

tjones
2023-07-13 13:08
?Hash? is the pact Rust core?s way of saying that the array contained an object

tjones
2023-07-13 13:08
(that?s probably a defect in the Rust core, as I don?t think people are used to talking about json objects as ?json hashes?)

tjones
2023-07-13 13:09
This message says that the actual array contained two items

tjones
2023-07-13 13:09
but it was expected to contain one

tjones
2023-07-13 13:09
Without more details, it?s hard to tell what has changed.

aram
2023-07-13 13:11
strange, because my expected is like so I only check types of id and name, and don?t check anything else ``` .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: { identity_locations: eachLike({ id: '123', name: 'xxx', }), }, });```

aram
2023-07-13 13:14
i can see the actual. It did not change.

tjones
2023-07-13 13:15
What do you mean by it did not change?

aram
2023-07-13 13:16
the provider response did not change. It?s as expected with nothing extra

tjones
2023-07-13 13:17
Did not change from what?

tjones
2023-07-13 13:17
Perhaps open an issue - we?ll need the logs and the full test in order to understand what is happening

aram
2023-07-13 13:18
ahh missed you message that ?but it was expected to contain one? but i have the eachLike, which handles arrays

tjones
2023-07-13 13:18
The error message is saying that it wasn?t expected to contain two.

tjones
2023-07-13 13:18
I suspect that the contract that is being verified isn?t from the code that you?re sharing.

tjones
2023-07-13 13:19
Which is why we need the full log

aram
2023-07-13 13:19
sorry, cannot provide full log but it is from correct test and i have 5 similar failures :confused:

tjones
2023-07-13 13:21
I would run the verifier with debug logging on. I guess that the contract that you?re verifying isn?t from that test, but also I can only guess without more information.

tjones
2023-07-13 13:23
> The error message is saying that it wasn?t expected to contain two. This is the key point. Either your provider is returning two when it is supposed to return one, or the expectation in the contract is expecting one, when it is supposed to be expecting one or more.

tjones
2023-07-13 13:23
Or, there?s a bug, although I think that?s unlikely as this matcher is used widely.

matt.fellows
2023-07-13 13:37
BTW I think that's a Ruby type so my guess is this an older version. The issue template will sort that out

tjones
2023-07-13 13:40
oh right yeah. I think the rust core still calls them non-objects. Dictionary, maybe?

tjones
2023-07-13 13:41
Map! Looks like I complained about this already: https://github.com/pact-foundation/pact-reference/issues/222

tjones
2023-07-13 13:41
it should be object. That?s what the O in json is for.

wesley.newcomb
2023-07-13 15:54
has joined #pact-js

joris.vaneijden
2023-07-14 10:56
has joined #pact-js

joris.vaneijden
2023-07-14 10:58
@joris.vaneijden has left the channel

tushar.adsul223
2023-07-14 15:29
has joined #pact-js

stan.amsellem
2023-07-17 07:13
Hey @yousafn & @matt.fellows, my apologies for the delayed response! I appreciate your reply. If participants agree to let us facilitate their placement in companies that provide us with a percentage of the placement fee, the course will be provided to them for free. During the first part of the bootcamp, people would worked on an open source product of their own. I'd like them to use the librairies they would then contribute to on the second part of the bootcamp. http://Pact.io would definitely be a good candidate to me. Would you be open to continuing our discussion through a brief phone call in the near future? Have a great day! Thanks :slightly_smiling_face:

mahesh.damavarapu
2023-07-17 11:14
Hello All, When i am running provider tests. Getting the following error. Can someone help me with this please ```1) Pact Verification validates the contract provided by the consumer: Error: pactffiVerifierBrokerSourceWithSelectors(arg 10) expected an array of strings at Object.validateAndExecute (node_modules/@pact-foundation/pact-core/src/verifier/argumentMapper/arguments.js:115:21) at /Users/maheshdamavarapu/GSGRepos/POC-BE-Automation/ContractTesting-GraphQL/node_modules/@pact-foundation/pact-core/src/verifier/argumentMapper/index.js:36:57 at Array.forEach (<anonymous>) at setupVerification (node_modules/@pact-foundation/pact-core/src/verifier/argumentMapper/index.js:34:11) at verify (node_modules/@pact-foundation/pact-core/src/verifier/nativeVerifier.js:38:44) at Verifier.verify (node_modules/@pact-foundation/pact-core/src/verifier/index.js:21:44) at Pact.verifyPacts (node_modules/@pact-foundation/pact-core/src/pact.js:125:49) at /Users/maheshdamavarapu/GSGRepos/POC-BE-Automation/ContractTesting-GraphQL/node_modules/@pact-foundation/pact/src/dsl/verifier/verifier.js:134:40 at processTicksAndRejections (node:internal/process/task_queues:96:5)``` ?@pact-foundation/pact?: ?^12.0.0", I am using ApolloGraphQLInteraction My Provider Code ```describe('Pact Verification', () => { it('validates the contract provided by the consumer', () => { const opts = { provider: 'GraphQLProvider', providerBaseUrl: 'http://localhost:4000/', pactBrokerUrl: 'https://gsg.pactflow.io', pactBrokerToken: 'OACUwt9HTivsWUMSCUdjJg', tags: ['test'], publishVerificationResult: true, providerVersion: '1.0.1', logLevel: 'DEBUG', consumerVersionTags: '1.0', }; return new Verifier(opts).verifyProvider().then(output => { console.log('Pact Verification Completed') console.log('________________-----------------__________'+output); }); }); }); ```

francisco.almeida
2023-07-17 11:35
has joined #pact-js

mike.lovely
2023-07-17 12:12
has joined #pact-js

matt.fellows
2023-07-17 12:43
Check the values against the rules accepted in the verifier constructor

matt.fellows
2023-07-17 12:43
I think cosumerVersionTags should be an array but I'm on my phone so it's a guess

kyam.harris_pact
2023-07-17 12:51
has joined #pact-js

drettie
2023-07-17 13:23
has joined #pact-js

mburns
2023-07-17 13:24
has joined #pact-js

tjones
2023-07-17 14:37
I think this is actually a bug - the validator and the docs say that it can be an array or a string, but the internal types only accept an array. The offending line is (at least) https://github.com/pact-foundation/pact-js-core/blob/0b168b791f6b21916448113b6384574f6811cc5e/src/verifier/argumentMapper/arguments.ts#L172C16-L172C35

tjones
2023-07-17 14:38
you can work around this by changing to `consumerVersionTags: ['1.0']`

matt.fellows
2023-07-17 22:53
thanks Tim, that code needs some rework as you have pointed out previously.

tjones
2023-07-18 03:32
Haha! Oops :sweat_smile:

amit.jadhav
2023-07-18 06:19
has joined #pact-js

aljaz.klanecek
2023-07-18 08:58
has joined #pact-js

amitw
2023-07-18 15:15
has joined #pact-js

fkelly
2023-07-18 17:28
has joined #pact-js

phananhdung104
2023-07-18 18:28
has joined #pact-js

gurubabu.jampala
2023-07-19 01:02
has joined #pact-js

a.kravchenko357
2023-07-19 11:03
has joined #pact-js

rabrosimov
2023-07-19 14:18
Hi, there! Could someone help me please. I've some error when pass nested hash with `search` key to query: ```const request_params = { page: '1' search: { wq: "NurseAction", specialty_nm: "Primary+Care"} } provider .given('generate message rooms') .uponReceiving('a request for message rooms') .withRequest({ method: 'GET', path: '/v4/message_rooms', query: request_params, headers: {}, })``` ```ERROR: pact@12.0.0: Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was incorrect: GET /v4/messaging/message_rooms``` but it works when I remove `search` key from `request_params` . Is it possible to pass a nested hash to query?

amitw
2023-07-19 15:54
@amitw has left the channel

mssachin
2023-07-19 19:55
can anyone please point me to a documenation of how to deal with aws signed urls

thiagotrinta
2023-07-19 20:00
has joined #pact-js

matt.fellows
2023-07-19 22:24
hmm I?m not sure we support nested hashes. How do you send the query over the wire (i.e. how do you encode that query?)

msiles
2023-07-20 01:05
Hi, what could be the cause of this error ``` Error: PactffiResponseStatus(arg 1) expected a number at withStatus (node_modules/@pact-foundation/pact-core/src/consumer/index.js:108:45) at Object.withStatus (node_modules/@pact-foundation/pact-core/src/consumer/checkErrors.js:9:20) at setResponseDetails (node_modules/@pact-foundation/pact/src/httpPact/ffi.js:106:17) at Pact.addInteraction (node_modules/@pact-foundation/pact/src/httpPact/index.js:196:38) at Context.<anonymous> (test/consumer.spec.js:426:20) at processImmediate (node:internal/timers:466:21)``` line 426 looks like this ``` provider.addInteraction({```

matt.fellows
2023-07-20 01:52
Can you please show the test? Looks like there is a missing type validation error that should appear higher up the stack. My guess is you are providing a non number to the field that specifies the response status code

msiles
2023-07-20 02:00
thanks, I've identify the issue... it was a problem on the ```willRespondWith...```

matt.fellows
2023-07-20 02:05
Can you please share? It sounds like a bug still and I'd like to address it.

matt.fellows
2023-07-20 02:06
Or for my adoration, a GH issue would be :muscle:

msiles
2023-07-20 02:07
let me share the issue, and you tell me if that's a bug or my bad haha

msiles
2023-07-20 02:10
instead of passing all of these things in the willRespondWith ``` status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: successBodyJsonFile,``` I was passing only the content of the successBodyJsonFile So, I was missing the headers, status, etc....

matt.fellows
2023-07-20 02:13
Yes, it's still a bug I think. It should error more clearly

matt.fellows
2023-07-20 02:13
Tha ks for sharing

msiles
2023-07-20 02:25
I'll create the GH issue, do you have handy the GH link?


mssachin
2023-07-20 09:13
HI Can I modify request headers in a provider test in request filters

mssachin
2023-07-20 09:15
SOmething like this

mssachin
2023-07-20 09:15
return new Verifier({             provider: 'post-secrets-secret-store-proxy-api',             providerBaseUrl: process.env.API_URL,             logLevel: 'debug',             requestFilter: ((req) =>{                 delete req.headers['host'];                 delete req.headers['x-amz-date'];                 delete req.headers['x-amz-security-token'];                 delete req.headers['x-amz-content-sha256'];                 delete req.headers['authorization'];                 req.headers['host']= host;                 req.headers['x-amz-date']= date;                 req.headers['x-amz-security-token']= securityToken;                 req.headers['x-amz-content-sha256']= contentSha256;                 req.headers['authorization']= authorization;                 return req;             }),             stateHandlers: {                 ['I post credentials token']: async () => {                     await chai.request(requestUrl.toString())                         .post("/")                         .set('Content-Type', contentType)                         .set('host', host)                         .set('x-amz-date', date)                         .set('x-amz-security-token', securityToken)                         .set('x-amz-content-sha256', contentSha256)                         .set('authorization', authorization)                         .send({ "details": "something to store" })                 }             }

mssachin
2023-07-20 09:15
it does not look like there is a straightforward way to do it

mssachin
2023-07-20 09:16
This test times out

mssachin
2023-07-20 09:16
If I do not have a request filter it takes the values from the pact

mssachin
2023-07-20 09:16
I did not get any help online for this

lotem.dagan
2023-07-20 10:48
has joined #pact-js

lotem.dagan
2023-07-20 10:49
@lotem.dagan has left the channel

matt.fellows
2023-07-20 10:50
at the very least, you?re not calling `next()` which is probably why it?s hanging


matt.fellows
2023-07-20 10:51
I?m not sure what your state handler is doing there.

mssachin
2023-07-20 11:19
State handler does not need headers?

mssachin
2023-07-20 11:19
also this is the log I get

mssachin
2023-07-20 11:19
pact@12.1.0: incoming request: {"body":{"details":"user credential details as string"},"headers":{"content-type":"application/json","host":"iloveorange","x-amz-date":"iloveorange","authorization":"iloveorange","x-amz-content-sha256":"iloveorange","x-amz-security-token":"iloveorange","accept":"*/*","accept-encoding":"gzip, deflate","content-length":"47"},"method":"POST","path":"/"}

mssachin
2023-07-20 11:19
I want these to be substituted to my values from signed request

matt.fellows
2023-07-20 11:32
> State handler does not need headers no, I?m just saying I don?t know what it?s doing. The results of the call aren?t going anywhere, so I?m not sure the intent behind it

mssachin
2023-07-20 11:38
man I may have totally misunderstood this, GOD. ['I post credentials token'] this method name matches exactly to the one created in pact. and for some reason when I run this test i get 201

mssachin
2023-07-20 11:57
Please do let me know if I got it wrong altogether

mssachin
2023-07-20 11:57
I have checked in this test in a number of repos now

mssachin
2023-07-20 13:07
THe full test looks like this

mssachin
2023-07-20 13:08
it('validates expectations of consumers post', async () => { return new Verifier({ provider: 'post-secrets-secret-store-proxy-api', providerBaseUrl: process.env.API_URL, logLevel: 'debug', requestFilter: ((req, res, next) =>{ req.headers["Content-Type"]= '${contentType}'; req.headers["host"]= '${host}'; req.headers["x-amz-date"]= '${date}'; req.headers["x-amz-security-token"]= '${securityToken}'; req.headers["x-amz-content-sha256"]= '${contentSha256}'; req.headers["authorization"]= '${authorization}'; next(); }), stateHandlers: { ['I post credentials token']: async () => { await chai.request(requestUrl.toString()) .post("/") // .set('Content-Type', contentType) // .set('host', host) // .set('x-amz-date', date) // .set('x-amz-security-token', securityToken) // .set('x-amz-content-sha256', contentSha256) // .set('authorization', authorization) .send({ "details": "something to store" }) } }, pactBrokerUrl: ', pactBrokerUsername: '', pactBrokerPassword: '', providerVersion: 'latest', enablePending: true, consumerVersionSelectors: [ { latest: true, }, ], publishVerificationResult: true, }).verifyProvider(); }, 20000);

mssachin
2023-07-20 14:55
Hi any pointers for me please

cmesyngi
2023-07-20 20:56
has joined #pact-js

matt.fellows
2023-07-21 01:08
what?s the actual problem, can we start with that?


mssachin
2023-07-21 04:34
it('validates expectations of consumers post', async () => { return new Verifier({ provider: 'post-secrets-secret-store-proxy-api', providerBaseUrl: process.env.API_URL, logLevel: 'debug', requestFilter: ((req, res, next) =>{ req.headers["Content-Type"]= contentType; req.headers["host"]= host; req.headers["x-amz-date"]= date; req.headers["x-amz-security-token"]= securityToken; req.headers["x-amz-content-sha256"]= contentSha256; req.headers["authorization"]= authorization; next(); }), stateHandlers: { ['I post credentials token']: async () => { await chai.request(requestUrl.hostname) .post(requestUrl.pathname) .set('Content-Type', contentType) .set('host', host) .set('x-amz-date', date) .set('x-amz-security-token', securityToken) .set('x-amz-content-sha256', contentSha256) .set('authorization', authorization) .send({ "details": "something to store" }) } }, pactBrokerUrl: ', pactBrokerUsername: '', pactBrokerPassword: '', providerVersion: 'latest', enablePending: true, consumerVersionSelectors: [ { latest: true, }, ], publishVerificationResult: true, }).verifyProvider(); }, 20000);

mssachin
2023-07-21 04:34
In this test I have tried to modify the headers using request filters

mssachin
2023-07-21 04:35
however when the request gets created the log shows below

mssachin
2023-07-21 04:35
pact@12.1.0: incoming request: {"body":{"details":"user credential details as string"},"headers":{"host":"iloveorange","x-amz-security-token":"iloveorange","content-type":"application/json","x-amz-content-sha256":"iloveorange","authorization":"iloveorange","x-amz-date":"iloveorange","accept":"*/*","accept-encoding":"gzip, deflate","content-length":"47"},"method":"POST","path":"/"}

mssachin
2023-07-21 04:36
when I created PACT from the consumer side I used Matchers.string()

mssachin
2023-07-21 04:36
in all the headers

mssachin
2023-07-21 04:36
All I would like to do is substitute signed headers in my request

matt.fellows
2023-07-21 05:44
That?s the incoming request, before the request filter

matt.fellows
2023-07-21 05:44
what does it look like when it hits the target?

matt.fellows
2023-07-21 05:56
On the provider state handler. I can?t work out what it does. The idea of a provider state is that a consumer says ?the provider must be in this state for the test to pass?. Think of it as a test precondition. When the provider test runs, the provider can (optionally) use that state handler, if needed, to prepare itself for that interaction. Normally, you would write them as you would a `given` statement in BDD e.g.

matt.fellows
2023-07-21 05:57
So in your case, it probably should be ?the user is authenticated? or ?the user has valid credentials? or something. The state handler would replace the valid credentials (that may be expired, as in the case of AWS) with a new set of valid ones.

matt.fellows
2023-07-21 05:57
Pact _does not care what these state handlers do, only that they don?t error_. It?s implementation detail

mssachin
2023-07-21 07:25
do you mean pact@12.1.0: incoming request: {"body":{"action":"teardown","params":{},"state":"I post credentials token"},"headers":{"content-type":"application/json","accept":"*/*","accept-encoding":"gzip, deflate","host":"127.0.0.1:59405","content-length":"68"},"method":"POST","path":"/_pactSetup"}

mssachin
2023-07-21 07:26
pact@12.1.0: outgoing response: {"body":"{\"message\":\"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\\n\\nThe Canonical String for this request should have been\\n'POST\\n/Prod/\\n\\ncontent-type:application/json\\nhost:http://oewstupmv1.execute-api.eu-west-1.amazonaws.com\\nx-amz-content-sha256:737eaae3db0b50b020ae2b8ebf63da3c0af99af40a11720528b528f5c5bf9ace\\nx-amz-date:20230720T145622Z\\nx-amz-security-token:IQoJb3JpZ2luX2VjEB8aCWV1LXdlc3QtMSJHMEUCIADTmp8sqz11zeXXzZtPTZqMO+RF+73p0lV7HywYBZZXAiEAjY6UvXl3VfCFCK57LyMMV2TzWcbloWpshgzA2E9zeDUqwQMIp///////////ARAAGgw2ODgzOTU5MTI5MTciDIyf251wCtyK4ohHriqVA7M5o3/GjPo31BVVZLT0RU0n+GGm4gcPhOWSl8K6Jmfj3Aaqrc1zYD0BRGIiN8cpykZyj6a8YO2t7OEzKxIYK2cy6OmQuR2ig3HPgQBZcTTWMf16a98ueplUS7d73GQCk1OK+ZyZlRqxmTLiwqCLOujli5y7fqeh6Pr0Nq7lHK5PxaBEBHe2ep0WN9sD076XULD0xvPSL5TqwG0CzEe7jRb6Bk3++SelB9R17pJi2+MCMLORZUX7fIyBjwjkO3lnPa8+P5SAiurVOJ1SJ4tdYtOYtRa2t79nDgfHBLVzZY8nozwT+UpLleCZ/6VSru0G9Jz7Fqdi2+GnucpMRNAa84NhsFcdaVf8qK572dvfuwvhv30/6VNR4e8MdEf4sPkFnNcIt3QYFFYFcVuEAlc//K4F/1BEk8PIuU/oxT1qzmx+z9vE0BNSB4Vl6uwMRQsxsqd797Gd55FjpxPjyNpkB2+q46EzjGSmaAw8HLiOnYZ/NsWK2h4tcv4Kz+FeoIntP2+1T6//sZi4HGbPlEvRqgsDVASKljD9hOWlBjqmAbnhCuG6bpTlFgOYn6DXGGTtEAapjEqmzk9q1qIESUckH9eJ8MdxrffIDN/w5Vu3f/9bUdXmewDGU73N5G/sVQuPRRiZJDBPXMHlrrp6YKgkRwi5ezZuax+om69ef/4s0dOjI9x+nOMbVlQfngUPWzgP9jZtHxhjy73okCxgKSQK9gBmaKIy2HjxfUZWkEhEOx8Uv8Z6SMYKESluZ3554Kcv/yWLA64=\\n\\ncontent-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token\\n24eca5ec17f48bf6cc35f9e76f13ac867b004ce49201fd18ecf919a4296d8574'\\n\\nThe String-to-Sign should have been\\n'AWS4-HMAC-SHA256\\n20230720T145622Z\\n20230720/eu-west-1/execute-api/aws4_request\\n04817b18dac64be4ff8e2cc2487a059bec4a4ddc7593ae1c572b4233b571b4ee'\\n\"}","headers":{"x-powered-by":"Express","content-type":"application/json","content-length":"1789","connection":"close","date":"Thu, 20 Jul 2023 14:59:37 GMT","x-amzn-requestid":"1102e99b-dd3b-42ca-a23e-804e6e099ae5","x-amzn-errortype":"InvalidSignatureException","x-amz-apigw-id":"IXjJ9GEkDoEFWZQ=","x-amzn-trace-id":"Root=1-64b94bd9-3140ac8033f7b55e0990a1e9","x-cache":"Error from cloudfront","via":"1.1 http://8eb76cf20c60ae36d4b347142eaf1140.cloudfront.net (CloudFront)","x-amz-

mssachin
2023-07-21 07:26
the above is the response I get

mssachin
2023-07-21 07:27
the headers are not getting substituted

mssachin
2023-07-21 08:08
please help me understand why are these values coming from the PACT

mssachin
2023-07-21 08:08
{"body":{"details":"user credential details as string"},"headers":{"host":"*iloveorange*","x-amz-security-token":"*iloveorange*","x-amz-content-sha256":"*iloveorange*","x-amz-date":"*iloveorange*","authorization":"*iloveorange*","content-type":"application/json","accept":"*/*","accept-encoding":"gzip, deflate","content-length":"47"},"method":"POST","path":"/"}

mssachin
2023-07-21 08:09
apologies

alan.barker
2023-07-21 09:47
has joined #pact-js

yousafn
2023-07-21 14:36
here is an example I did a little while back https://github.com/you54f/aws-auth-pact Not sure if its the correct way, but it worked for the demo


yousafn
2023-07-21 14:38
it came out the back of this feature req/convo https://github.com/pact-foundation/pact-js/issues/304

vijaya.balla.external
2023-07-21 15:06
has joined #pact-js

dennis1125dennis
2023-07-22 02:30
has joined #pact-js

muhammedalimutlu
2023-07-23 18:40
has joined #pact-js

doug.hanke
2023-07-24 17:53
has joined #pact-js

noor.hashem
2023-07-24 19:40
Hello! I wanted to know is pact contract testing useful for microfrontends? Is it common to use it for that case? I know it is *possible* but im asking if its useful/common.

matt.fellows
2023-07-24 22:56
I?ve heard people asking, but it?s still theoretical to me. Interested in the discussion?

abubics
2023-07-25 01:22
I don't see how a micro-front-end is different to any other front-end, from this testing perspective :+1: I've used it across both gaps in a MFE->BFF->API scenario (to great effect).

abubics
2023-07-25 01:24
It might depend on your MFE architecture, though? For example, if you have UIs mounted into a backing container that centralises API clients, then the MFE bit is probably irrelevant. But if each MFE has it own API clients, then they're like any other front-end. I think my conclusion is, it's irrelevant either way. But maybe there's some combo I haven't though of.

sameswar.khuntia
2023-07-25 10:17
has joined #pact-js

michal.mirecki
2023-07-25 10:28
has joined #pact-js

noor.hashem
2023-07-25 13:47
I see, well we are still working on the architecture of our MFE as we are in the process of moving from a monorepo to microfrontends. But the idea is to have each page in a seperate repo so that we can deploy them separately. We are trying to eliminate most if not all cypress e2e tests so we don't want to keep having to spin up all of our services to run e2e tests. That was when the conversation of contract testing came up as we were worried if we removed or minimized the e2e tests we might need some more assurance integrations are working together.

abubics
2023-07-25 14:08
I did https://skillsmatter.com/skillscasts/17062-tooling-up-pact-contract-testing about the balance of different kinds of tests :sweat_smile: It's a good idea to have a light run of e2e tests for connectivity checking after deploy (and ideally before real traffic is routed), but you shouldn't need heaps of e2e coverage. Best use case for Cypress is to stubbed API clients, so you don't have to do network hops & can simulate all response cases (without having to seed data in external sources, work out how to orchestrate weird cases, or keep all of those fixtures in sync). Pact might even be able to help you with stubbing API clients.

jeremyjpark
2023-07-25 15:30
has joined #pact-js

chetana.mahangare
2023-07-25 15:57
has joined #pact-js

kwan
2023-07-25 18:49
has joined #pact-js

matt.fellows
2023-07-25 22:50
It was a good talk too ^^ :stuck_out_tongue:

noor.hashem
2023-07-26 13:52
Hahha ill give it a watch then! Thanks

venkatesh.civic
2023-07-26 16:49
has joined #pact-js

bartlomiej
2023-07-26 18:06
has joined #pact-js

wongkoonwai
2023-07-27 03:14
has joined #pact-js

conrad.john
2023-07-27 08:37
has joined #pact-js

ajit.kumar
2023-07-27 11:37
has joined #pact-js

marekurbanowicz
2023-07-27 12:40
has joined #pact-js

marekurbanowicz
2023-07-27 12:43
Hi! I am pretty new to Pact and I am trying to match the dynamic Map of arrays example is like: { // rendered property is a problem rendered: { ?2023-01-01?: [0,1] } } each key in rendered should be a date and it should contain array of numbers. I can?t figure it out

maciej.krakowiak
2023-07-27 13:28
has joined #pact-js

mateusz.luty
2023-07-27 13:29
has joined #pact-js

tien.xuan.vo
2023-07-27 15:43
Hi, I has (trimmed and reformatted, not real structure) consumer test like this: ``` pact.addInteraction({ states: [...], uponReceiving: '...', withRequest: {...}, willRespondWith: { status: 200, headers: {...}, body: { min: 1, 'pact:matcher:type': 'type', // I am aware that I'm using custom version of `eachLike` value: [ // NOTE example value has 3 values, not 1 when we use `eachLike` { id: uuid(id), father: uuid(father), mother: uuid(mother), }, { id: father, }, { id: mother, } ], }, }, });``` Now provider response body (trimmed and reformatted, not real structure) look like this: ```[ { "id": "79c4b8d7-5224-32cf-8ff1-ef0bcaedc1e3", "father": "f897f1b7-3867-318c-9f34-06480ffd0fab", "mother": "7973a31e-856e-3940-acbb-9e21e7f627bf", }, { "id": "7973a31e-856e-3940-acbb-9e21e7f627bf", "father": null, "mother": null, }, { "id": "f897f1b7-3867-318c-9f34-06480ffd0fab", "father": null, "mother": null, } ]``` I expected provider's verification will failed (because matching rule `uuid` on `father` and `mother` ), but it still passed. Do you know why?

matt.fellows
2023-07-27 22:54
I?ll have to check Tien. I wonder if it?s the non standard use of the eachLike matcher that?s causing the issue. What happens if you remove the second and third object in the consusmer test? (so that the example only has items with `uuid` matchers?)

pact259
2023-07-27 23:19
has joined #pact-js

tien.xuan.vo
2023-07-28 01:35
If I remove other example values (except the first one), provider verification failed as expected. ```1) Verifying a pact between admin and relationship Given Users with full information - get list users with full information 1.1) has a matching body $[1].rels.mother -> Expected '' to match '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' $[1].rels.father -> Expected '' to match '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' $[2].rels.father -> Expected '' to match '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' $[2].rels.mother -> Expected '' to match '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'```

tien.xuan.vo
2023-07-28 01:42
So, it's because of the non standard use of the eachLike matcher

tien.xuan.vo
2023-07-28 01:44
But should the provider verification rely on the matching rules, not the example values? I thought example values are for consumer tests only.

matt.fellows
2023-07-28 03:02
I?m assuming it?s taking the matching rules from the last example you gave it, rather than the first. But we shouldn?t allow multiple different examples (i.e. in index 0, all three items have matchers, in index 1 and 2 there are no matchers at all, and there is only one valid property: `id`

tien.xuan.vo
2023-07-28 03:17
I compared 2 versions of the generated pacts, and they are exactly the same (including `matchingRules`), except the example values I removed of course

matt.fellows
2023-07-28 03:17
interesting!

matt.fellows
2023-07-28 03:18
I suspect they are used in the verification then

matt.fellows
2023-07-28 03:18
I have noticed, you can occasionally supply invalid values to a matcher definition (i.e. incompatible with the matcher) and they are accepted

matt.fellows
2023-07-28 03:18
this is one example

matt.fellows
2023-07-28 03:18
eachKey and eachValue are similar

tien.xuan.vo
2023-07-28 03:25
> you can occasionally supply invalid values to a matcher definition (i.e. incompatible with the matcher) I believe we need to handle this one in ffi library, not in every languages that use it? Should I create a bug for it, for pact-reference project, with my example code/information?

matt.fellows
2023-07-28 03:50
Yes please!

matt.fellows
2023-07-28 03:51
Obviously, the library authors need to do their best to make sure the right constraints are applied (e.g. the correct type) but shouldn?t have to do additional validation on top of it (e.g. ensure the matchers are the same, apply regexes etc.)

tien.xuan.vo
2023-07-28 03:55
And I believe my situation will never happen because ffi library will refuse to generate the pact at the first place

tien.xuan.vo
2023-07-28 05:16
Please review my ticket. It's quite long, and I have to put some text in attachments because the body is too long github can't handle it https://github.com/pact-foundation/pact-reference/issues/303

marekurbanowicz
2023-07-28 05:31
can anyone help with that? I am on the latest version of pact-js. Need to describe matching for structure like this: ```{ rendered: { '2023-01-01': [0,1], '2023-05-23': [2], '2023-06-01: [0] } }``` In summary rendered is a map, where keys are dates string and values are arrays of number

matt.fellows
2023-07-28 05:49
I think the `eachValueMatches` rule is probably what you want. It lets the keys be dynamic, but you can specify the shape of the value. Here is an example test: https://github.com/pact-foundation/pact-js/blob/master/examples/v4/matchers/consumer.spec.ts#L73

tien.xuan.vo
2023-07-28 06:06
The document said that no optional attributes supported https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes But in pact-js, I can simply don't use `eachLike` directly, instead copying it code and use it like this: ```children: { value: [uuid(child)], getValue: () => [uuid(child)], 'pact:matcher:type': 'type', min: 0, }``` And ffi library happy to create the pact. At provider side, response can contain `"children": []` and the verification still passed. Is it a bug? Should ffi library prevent to set `min = 0` at the first place? Related to this question https://pact-foundation.slack.com/archives/C9VBGLUM9/p1690472580471449 (example code are there)

matt.fellows
2023-07-28 06:53
Probably!

marekurbanowicz
2023-07-28 06:56
```rendered: eachValueMatches({'2023-01-01': [0, 1]}, atLeastOneLike(1, 2))``` but it breaks the test as instead of the example value, mockprovider returns ?pact?s stuff? around it: what am I doing wrong?

matt.fellows
2023-07-28 07:03
Why are you asserting the pact simply did what you asked it? That's not a helpful test

matt.fellows
2023-07-28 07:04
You can use the reify function to strip that away though

marekurbanowicz
2023-07-28 07:06
I just follow the examples tbh and that?s exactly what was done there.

matt.fellows
2023-07-28 07:06
Remember: the point is to unit test your API client, not assert what the API returned (pact will do this for you)

marekurbanowicz
2023-07-28 07:06
I am more than happy to do it better.

matt.fellows
2023-07-28 07:06
Fair, we should make them clearer

marekurbanowicz
2023-07-28 07:07
I agree with testing API client! The issue is that the API client fails in this way as it cann?t get the rendered values really as it tries to get it from res.rendered, not res.rendered.values From what you saying it can be done in some way?

marekurbanowicz
2023-07-28 07:09
I am asserting api client response, not what mock returns, but the first one is a result of the second one

marekurbanowicz
2023-07-28 07:12
I?ve just tried with: ``` .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8' }, body: reify(expectedPDDData) });``` but it didn?t strip that guff

matt.fellows
2023-07-28 07:15
No, reify strips the matchers away. Pact needs the matchers to know how to...match

matt.fellows
2023-07-28 07:15
Add the reify to your assertion around the `expected`

marekurbanowicz
2023-07-28 07:32
We?ve tried sth like this: ```rendered: [ eachKeyMatches({ '2023-01-01': eachLike(0) }), eachValueMatches({ '2023-01-01': eachLike(0) }, like(eachLike(0))), ]``` ```$.rendered -> Type mismatch: Expected List [{"2023-01-01":[0]},{"2023-01-01":[0]}] but received Map {"2023-01-01":[0]}``` Consumer test went through! Thanks, but the match does not work as we want :disappointed: We want to allow 0..n keys in that object (rendered). I will highly appreciate suggestion how to fix this

marekurbanowicz
2023-07-28 11:02
:pray:

hetal.patel
2023-07-28 14:04
has joined #pact-js

tien.xuan.vo
2023-07-28 14:55
I think it's the similar bug as above. So I created the bug report here https://github.com/pact-foundation/pact-reference/issues/304

thatrandybrown
2023-07-28 16:49
has joined #pact-js

matt.fellows
2023-07-29 00:36
```rendered: [ eachKeyMatches({ '2023-01-01': eachLike(0) }), eachValueMatches({ '2023-01-01': eachLike(0) }, like(eachLike(0))), ]``` ^^ is rendered an array though? I think you want: ```rendered: eachValueMatches({ '2023-01-01': [0] }, eachLike(0)),```

michael072
2023-07-29 03:08
has joined #pact-js

selniumtrainer
2023-07-29 08:10
has joined #pact-js

raylincontact
2023-07-31 01:51
has joined #pact-js

matt.fellows
2023-07-31 02:22
Hey Stan, apologies for the delay to your delay :stuck_out_tongue: I?m happy for a quick chat, or we can continue here. I?m based in Australia so the time zone isn?t great. One feature I love about Slack?

matt.fellows
2023-07-31 02:27
As far as catching up, perhaps joining us for our weekly maintainers call (https://pact-foundation.slack.com/archives/C05HCLA3C93/p1690476924812989) would be a good way to get alignement? It should be in a TZ friendly slot for you actually

ext-damian.rudzinski
2023-07-31 10:01
has joined #pact-js

rostas.laszlo.dev
2023-07-31 11:27
has joined #pact-js

anubhuti.shrivastava
2023-08-01 07:35
has joined #pact-js

pavikrish
2023-08-01 07:45
has joined #pact-js

ivan.cheung
2023-08-01 11:38
hey guys, normally the mockServer variable is instantiated during test execution e.g. ``` it('Domain exists - Responding with the correct companyId for specific domain', () => { // setup provider .... return provider.executeTest(async (mockServer: V3MockServer) => { // call function which takes in 'mockServer' as a param // test assertion here }); }); ``` and the only way to pass the `mockServer` var is within `provider.executeTest()` , but how can i set `mockServer` in a before block before the it() block? because it would say that `mockServer` is not defined

ivan.cheung
2023-08-01 11:41
the test above uses PactV3 by the way: import { V3MockServer } from ?@pact-foundation/pact/src/v3/matchers?; import { PactV3 } from ?@pact-foundation/pact

yousafn
2023-08-01 11:45
It?s only instantiated in the executeTest block

yousafn
2023-08-01 11:45
what are you trying to do?

ivan.cheung
2023-08-01 11:51
tried installing `jest-pact` which provides a wrapper for me to wrap the entire test with ```pactWith({ provider object}, () => { // ... }``` and this is using ```import { pactWith } from 'jest-pact/dist/v3'; import { V3MockServer } from '@pact-foundation/pact/src/v3/matchers';``` _to force it to use PactV3 (in theory)_ So this will allow me to define the mockServer var in a before() block, however when i do this : ```pactWith( { dir: //.. consumer: //.. provider: //.. logLevel: 'debug', }, (interaction) => { interaction('hit api', ({ provider, execute }) => { //.... functionCall( provider.mockServer), }); // tests below ....``` it says ```Property 'mockServer' does not exist on type 'PactV3'.ts(2339)``` why is that?

yousafn
2023-08-01 12:11
I?d need to create a repro or check the source. jest-pact was a convenience wrapper originally created to deal with the pact core (provided by a ruby cli)?s lifecycle methods. pact-js v10+ uses the pact-core (provided by the rust ffi) and doesn?t require the same lifecycle management. The dsl was never fully finalised in `jest-pact` and the authoring experience is pretty nice now with vanilla `pact-js` I?ve never gone back and done anything with `jest-pact` https://github.com/pact-foundation/jest-pact/issues/215

yousafn
2023-08-01 12:15
Couple of options 1. Use Pact-js directly 2. Raise an issue against jest-pact, along with a repro of what you are trying to do. a. for extra mega bonus points, feel free to raise a PR :slightly_smiling_face:

ivan.cheung
2023-08-01 12:51
for 1) do you mean not use (jest-pact) pactWith() wrapper? 2) yep thanks will see :slightly_smiling_face:

arnoldsi
2023-08-01 15:09
has joined #pact-js

tjones
2023-08-02 03:37
The mock server doesn't exist on the types that the v3 pactWith wrapper provides. The v3 pactWith wrapper was written before the DSL was finalised, and was pretty beta at the time. I'm not sure how useful you'll find it

tjones
2023-08-02 03:37
The history of jest-pact is that it was originally boilerplate to set better defaults - it would have been rolled in to pact, but we couldn't because pact doesn't require jest

wongkoonwai
2023-08-02 07:27
Hi, I am looking for JS consumer test examples that use the gRPC plugin. I only found this one https://github.com/YOU54F/pluginopedia/blob/main/example-project-js-grpc-plugin/test/matt.consumer.spec.ts. But that was last updated 8 months ago so I am not sure if that's still up to date. Are there more? Our project is a React frontend that connects to a golang backend using gRPC-Web with an Envoy proxy. The Envoy proxy is needed to convert HTTP/1.1 requests from web browsers to HTTP/2 used by gRPC. Can we use Pact for this scenario? I assume Yes since the JS consumer test will be making the gRPC requests and not a web browser.

matt.fellows
2023-08-02 08:19
This is an example using a plugin, but it doesn?t use gRPC

matt.fellows
2023-08-02 08:19
We can?t have examples in every language for every plugin, but hopefully this helps: https://github.com/pact-foundation/pact-js/blob/master/examples/v4/plugins/test/matt.consumer.spec.ts


matt.fellows
2023-08-02 08:20
Hopefully that helps get you on track

yousafn
2023-08-02 10:00
the package versions are out of date in my example but it works, and others have used it as a basis for getting their own grpc tests in js running

yousafn
2023-08-02 10:00
8 months isn?t terribly old if i?m honest

yousafn
2023-08-02 10:04
it?s difficult maintaining multiple e2e examples in our main client lib repos, especially with the multitude of test frameworks, protocols etc. should be able to use with envoy fine, i played with it back at my original adventure with grpc

stefan.waldhauser
2023-08-02 13:45
has joined #pact-js

stan.amsellem
2023-08-02 15:28
Hi Matt, so cool you've made an introductory video! Unfortunately I'm currently in a very low network area (actually in the middle of the sea :ocean: ). I'll be back next Tuesday. Then, I'll be able to properly watch the video and do the same to give you more details on the project. Thanks a lot have a great day!

shadman.equebal140
2023-08-02 19:20
has joined #pact-js

matt.fellows
2023-08-02 21:41
oh cool! I?d love a recording from the sea, even if you can just share it when you get back to land

matt.fellows
2023-08-02 21:42
no worries at all

yousafn
2023-08-03 00:17
i?ve just had a look at the example again, if you update pact-js to 12.0.0 it?ll come with the native libraries pre bundled and you can remove the pact-core import the loop back interface for the host name might cause you bother, but other than that we?ve had a few reports of success from people seeing that example note to @matt.fellows and me let?s get a recipe page up for grpc on the docs website and we can provide pointers to the tests in the various impls. i?ll get an area calculator example for pact js at some point, that is the canonical example in the pact plugins repo i?ve got one in deno pact which was a port a of the pact js interface https://github.com/YOU54F/deno-pact/blob/main/src/usage/areaCalculatorClientTest.ts so the lift shouldn?t be too hard. we would gladly appreciate a js example here :point_down: https://github.com/pact-foundation/pact-plugins/tree/main/examples/gRPC/area_calculator it keeps them all in the same home and makes them easier to test cross language

wongkoonwai
2023-08-03 02:49
Thank you so much @matt.fellows and @yousafn! Really appreciate your help. Yeah I think my teammate was having trouble with the host name. It would be awesome to have a recipe page for gRPC and find all the examples in one place. For now, we have switched to using pact golang for consumer and provider tests. But we will go back to JS soon.

aravind.pai
2023-08-03 07:06
has joined #pact-js

ganeshacse01
2023-08-03 08:10
has joined #pact-js

matt.fellows
2023-08-03 09:57
You mentioned you are moving between languages - how are you writing your tests? Usually, the tests would be unit tests - so switching languages makes that a rather difficult thing to do and worries me. Can you please elaborate?

br.holanda15
2023-08-03 14:35
has joined #pact-js

yousafn
2023-08-03 15:50
:blobwave: Anyone tried out https://deno.land/ or https://bun.sh/ yet, or even better using it in production?

abarkha1
2023-08-03 22:34
has joined #pact-js

boreyuk
2023-08-04 07:22
has joined #pact-js

evan196
2023-08-04 14:33
has joined #pact-js

shadman.equebal140
2023-08-04 18:29
I am trying to verify xml response as part of pact testing using pactjs. The consumer as well as verifier works fine in case of xml response without namespace. But with namespace , PactVerifier complains with below error message " $['https://www.w3schools.com/furniture:Student']['https://www.w3schools.com/furniture:Name']['#text'] -> Expected 'John Doe 2' to be equal to 'John Doe'" `//contract body` `const BODY = new XmlBuilder("1.0", "UTF-8", "f:Student").build((el) => {` `el.setAttributes({` `"xmlns:f":"https://www.w3schools.com/furniture"` `})` `el.appendElement("f:Name", {}, (version) => {` `version.appendText(MatchersV3.string("John Doe"))` `})` `})` response returned by the mock api `<?xml version='1.0'?>` `<f:Student xmlns:f="https://www.w3schools.com/furniture">` `<f:Name>John Doe 2</f:Name>` `</f:Student>` I am using node 18.0.0 and pactjs version 12.1.0


marek.fexa
2023-08-06 08:36
has joined #pact-js

acemilyalcin
2023-08-06 16:55
has joined #pact-js

aniket.rane
2023-08-07 02:55
has joined #pact-js

mssachin
2023-08-07 08:05
HI Still cant get it to work

mssachin
2023-08-07 08:05
it('validates expectations of consumers post', async () => { return new Verifier({ provider: 'post-secrets-secret-store-proxy-api', providerBaseUrl: process.env.API_URL, logLevel: 'debug', stateHandlers: { ['I post credentials token']: async () => { await chai.request(requestUrl.hostname) .post(requestUrl.pathname) .set(signedHeadersReq) .send(JSON.stringify({ "details": "something to store" })) } }, requestFilter: async (req, res, next) => { signRequest() .then((result) => { signedHeadersReq = result.headers; contentType = result.headers['Content-Type']; host = result.headers['host']; date = result.headers['x-amz-date']; securityToken = result.headers['x-amz-security-token']; contentSha256 = result.headers['x-amz-content-sha256']; authorization = result.headers['authorization']; }) .catch((error) => { console.error('Error signing request:', error); }); req.headers['Content-Type']= contentType; req.headers['host'] = host; req.headers['x-amz-date']= date; req.headers['x-amz-security-token']= securityToken; req.headers['x-amz-content-sha256']= contentSha256; req.headers['authorization']= authorization; next(); }, pactBrokerUrl: ', pactBrokerUsername: ', pactBrokerPassword: , providerVersion: 'latest', enablePending: true, consumerVersionSelectors: [ { latest: true, }, ], publishVerificationResult: true, }).verifyProvider(); }, 20000);

mssachin
2023-08-07 08:06
pact@12.1.0: incoming request: {"body":{"details":"user credential details as string"},"headers":{"authorization":"iloveorange","host":"iloveorange","content-type":"application/json","x-amz-security-token":"iloveorange","x-amz-content-sha256":"iloveorange","x-amz-date":"iloveorange","accept":"*/*","accept-encoding":"gzip, deflate","content-length":"47"},"method":"POST","path":"/"} [08:54:07.181] DEBUG (11168): pact@12.1.0: Proxying POST: / [08:54:07.245] DEBUG (11168): pact@12.1.0: outgoing response: {"body":"{\"message\":\"Authorization header requires 'Credential' parameter. Authorization header requires 'Signature' parameter. Authorization header requires 'SignedHeaders' parameter. Authorization=iloveorange\"}","headers":{"x-powered-by":"Express","content-type":"application/json","content-length":"203","connection":"close","date":"Mon, 07 Aug 2023 07:54:07 GMT","x-amzn-requestid":"bb15f752-31ca-4869-815d-264ef1edf931","x-amzn-errortype":"IncompleteSignatureException","x-amz-apigw-id":"JR5s7FEGDoEFkzA=","x-amzn-trace-id":"Root=1-64d0a31f-21a9ac4f22af719f3e20ef67","x-cache":"Error from cloudfront","via":"1.1 http://99c9ffdbfc5207f9665251bb3284f588.cloudfront.net (CloudFront)","x-amz-cf-pop":"LHR50-P4","x-amz-cf-id":"dpUdL4OupofzBaPtohTGrUwkyf0xLx1U5x5jNVLzj34eNCsy_ixfWQ=="},"status":403}

mssachin
2023-08-07 08:07
Please advise

matt.fellows
2023-08-07 08:08
AT the very least ``` signRequest() .then((result) => { signedHeadersReq = result.headers; contentType = result.headers['Content-Type']; host = result.headers['host']; date = result.headers['x-amz-date']; securityToken = result.headers['x-amz-security-token']; contentSha256 = result.headers['x-amz-content-sha256']; authorization = result.headers['authorization']; }) .catch((error) => { console.error('Error signing request:', error); });``` That?s a promise, and is currently not handled. So all of the code after it that relies on those values has already fired (probably) before this promise is complete. I?d look at that as a starting point

antony
2023-08-07 08:11
has joined #pact-js

mssachin
2023-08-07 09:35
No luck bro it('validates expectations of consumers post', async () => { return new Verifier({ provider: 'post-secrets-secret-store-proxy-api', providerBaseUrl: process.env.API_URL, logLevel: 'debug', requestFilter: async (req, res, next) => { const sigv4 = new SignatureV4({ service: "execute-api", region: process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION!, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID!, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!, sessionToken: process.env.AWS_SESSION_TOKEN, }, sha256: Sha256, }); const signed = await sigv4.sign({ method: "POST", hostname: requestUrl.host, path: requestUrl.pathname, protocol: requestUrl.protocol, headers: { "Content-Type": "application/json", host: requestUrl.hostname, // compulsory }, body: JSON.stringify({ "details": "something to store" }) }); contentType = signed.headers['Content-Type']; host = signed.headers['host']; date = signed.headers['x-amz-date']; securityToken = signed.headers['x-amz-security-token']; contentSha256 = signed.headers['x-amz-content-sha256']; authorization = signed.headers['authorization']; req.headers['Content-Type']= signed.headers['Content-Type']; req.headers['host'] = signed.headers['host']; req.headers['x-amz-date']= signed.headers['x-amz-date']; req.headers['x-amz-security-token']= signed.headers['x-amz-security-token']; req.headers['x-amz-content-sha256']= signed.headers['x-amz-content-sha256']; req.headers['authorization']= signed.headers['authorization']; next(); }, stateHandlers: { ['I post credentials token']: async () => { await chai.request(requestUrl.hostname) .post(requestUrl.pathname) .set('Content-Type', contentType) .set('host', host) .set('x-amz-date', date) .set('x-amz-security-token',securityToken) .set('x-amz-content-sha256', contentSha256) .set('authorization', authorization) .send(JSON.stringify({ "details": "something to store" })) } }, pactBrokerUrl: pactBrokerUsername: , pactBrokerPassword: , providerVersion: 'latest', enablePending: true, consumerVersionSelectors: [ { latest: true, }, ], publishVerificationResult: true, }).verifyProvider(); }, 20000);

mssachin
2023-08-07 09:53
Bro even if I am doing something fundamentally wrong I am not aware please advise.

matt.fellows
2023-08-07 09:57
I can?t speak for the AWS use case, but I?d look at the `DEBUG` (or perhaps even `TRACE` log level) to see what the request is sent to AWS

yousafn
2023-08-07 09:57
please format your code with three backs ticks it is painful trading this thread

yousafn
2023-08-07 09:57
i?ve provided an example, your code looks incorrect

matt.fellows
2023-08-07 09:58
As for this: ``` ['I post credentials token']: async () => { await chai.request(requestUrl.hostname) .post(requestUrl.pathname) .set('Content-Type', contentType) .set('host', host) .set('x-amz-date', date) .set('x-amz-security-token',securityToken) .set('x-amz-content-sha256', contentSha256) .set('authorization', authorization) .send(JSON.stringify({ "details": "something to store" })) }``` I?m not sure what this is doing. This will be executed before the provider test, but it?s just dangling. It shouldn?t be hitting your AWS service, the Pact verifier will do that

yousafn
2023-08-07 09:58
you need to be using values from the pact to send to the request sign, if that is all your code it?s not going to work

yousafn
2023-08-07 09:58
please create a example repo, you can use my example i?ve linked in this thread as a start

yousafn
2023-08-07 09:59
ie start here https://github.com/you54f/aws-auth-pact try and get that running and let us know if you have issues

yousafn
2023-08-07 10:00
we can collab around that.


mssachin
2023-08-07 11:09
All my attempts are failing bro

mssachin
2023-08-07 11:09
it('validates expectations of consumers post', async () => { return new Verifier({ provider: 'post-secrets-secret-store-proxy-api', providerBaseUrl: process.env.API_URL, logLevel: 'debug', stateHandlers: { ['I post credentials token']: async () => { await chai.request(requestUrl.hostname) .post(requestUrl.pathname) .set(signedHeadersReq) .send( JSON.stringify({ "details": "something to store" })) } }, requestFilter:async(req, res, next) => { const sigv4 = new SignatureV4({ service: "execute-api", region: process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION!, credentials: { accessKeyId: process.env.AWS_ACCESS_KEY_ID!, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!, sessionToken: process.env.AWS_SESSION_TOKEN, }, sha256: Sha256, }); const signed = await sigv4.sign({ method: "POST", hostname: requestUrl.host, path: requestUrl.pathname, protocol: requestUrl.protocol, headers: { "Content-Type": "application/json", host: requestUrl.hostname, // compulsory }, body: JSON.stringify({ "details": "something to store" }) }); signedHeadersReq = signed.headers; // console.log(authHeaders) req.headers['host'] = signedHeadersReq && signedHeadersReq['host'] ? signedHeadersReq['host'].toString() : ''; req.headers['x-amz-date'] = signedHeadersReq && signedHeadersReq['x-amz-date'] ? signedHeadersReq['x-amz-date'].toString() : ''; req.headers['authorization'] = signedHeadersReq && signedHeadersReq['authorization'] ? signedHeadersReq['authorization'].toString() : ''; // The following is required if using AWS STS to assume a role req.headers['x-amz-security-token'] = signedHeadersReq && signedHeadersReq['x-amz-security-token'] ? signedHeadersReq['x-amz-security-token'].toString() : ''; req.headers['x-amz-content-sha256'] = signedHeadersReq && signedHeadersReq['x-amz-content-sha256'] ? signedHeadersReq['x-amz-content-sha256'].toString() : ''; next(); }, pactBrokerUrl: pactBrokerUsername: pactBrokerPassword: providerVersion: 'latest', enablePending: true, consumerVersionSelectors: [ { latest: true, }, ], publishVerificationResult: true, }).verifyProvider(); }, 20000);

mssachin
2023-08-07 13:59
not working for me sir

mssachin
2023-08-07 13:59
please advise

andreas.marcec.extern
2023-08-07 14:35
has joined #pact-js

mssachin
2023-08-07 15:24
I think I get you now

mssachin
2023-08-07 15:24
Will report back

jeffreykey
2023-08-07 17:44
has joined #pact-js

mssachin
2023-08-08 07:24
Bro its trying to hit localhost

mssachin
2023-08-08 08:48
Request Failed - error sending request for url (http://127.0.0.1:62608/Prod): operation timed out

vaishali.rastogi
2023-08-08 12:29
has joined #pact-js

michael.knoll
2023-08-08 14:02
has joined #pact-js

michelle.he
2023-08-08 19:02
has joined #pact-js

mohammed.a.ezzedin501
2023-08-09 11:17
has joined #pact-js

jacopo
2023-08-09 15:34
has joined #pact-js

enrique519
2023-08-09 23:57
has joined #pact-js

sheyanr
2023-08-10 02:55
has joined #pact-js

rcalvo
2023-08-10 08:28
has joined #pact-js

endikaposadas
2023-08-10 08:40
has joined #pact-js

chinmaya.mishra
2023-08-10 10:05
has joined #pact-js

anderson.aeb
2023-08-10 12:37
has joined #pact-js

mahesh.damavarapu
2023-08-10 13:29
Hi All. I am getting this below error ```1) returns the correct response Pact verification failed! Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was incorrect: POST /graphql 1.0 Mismatch with header 'Content-Type': Expected value 'application/json' at index 1 but was missing (actual has 1 value(s))``` My code from consumer.js is ```const { ApolloClient, InMemoryCache, HttpLink, gql } = require('@apollo/client/core'); const fetch = require('cross-fetch'); const client = new ApolloClient({ cache: new InMemoryCache({ addTypename: false }), link: new HttpLink({ uri: 'http://127.0.0.1:5000/graphql', fetch, headers: { 'Content-Type': 'application/json; charset=utf-8' }, }) });``` consumer.spec.js is ```.willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8' },```

mahesh.damavarapu
2023-08-10 13:29
I see ```2023-08-10T13:24:19.586178Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Request did not match: Request did not match - HTTP Request ( method: POST, path: /graphql, query: None, headers: Some({"Content-Type": ["application/json", "application/json"]}), body: Present(499 bytes, application/json) ) 0) Mismatch with header 'Content-Type': Expected value 'application/json' at index 1 but was missing (actual has 1 value(s))```

yousafn
2023-08-10 13:39
I believe there is a bug, if you drop the content-type header it should be automatically detected

mahesh.damavarapu
2023-08-10 13:49
I commented the headers in both consumer and consumer spec. Same issues coming up

mahesh.damavarapu
2023-08-10 13:49
I used const graphqlQuery = new ApolloGraphQLInteraction()

yousafn
2023-08-10 13:50
cool. you?ve not shared the whole test so its really hard to tell

mahesh.damavarapu
2023-08-10 13:51
consumer.js ```const { ApolloClient, InMemoryCache, HttpLink, gql } = require('@apollo/client/core'); const fetch = require('cross-fetch'); const client = new ApolloClient({ cache: new InMemoryCache({ addTypename: false }), link: new HttpLink({ uri: 'http://127.0.0.1:5000/graphql', fetch, //headers: { // 'Content-Type': 'application/json; charset=utf-8' //}, }) }); async function query() { return await client .query({ query: gql` query Query($input: pageInput) { page(input: $input) { id_client id_page similar_shops_widget { id widget_api_mapping __typename } __typename } } `, variables: { "input": { "id_retailer": "****", "id_client":"*****" } }, }); //.then((result) => result.data); } module.exports.query = query```

yousafn
2023-08-10 13:51
the log message is about the request, not the response, what does your full consumer.spec.js look like

mahesh.damavarapu
2023-08-10 13:53
consumer.spec.js ```const chai = require("chai"); const chaiAsPromised = require("chai-as-promised"); const path = require("path"); const { query } = require("../consumer"); const { Pact } = require("@pact-foundation/pact"); const { ApolloGraphQLInteraction } = require("@pact-foundation/pact") const expect = chai.expect chai.use(chaiAsPromised) describe("GraphQL example", () => { const provider = new Pact({ port: 5000, log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"), dir: path.resolve(process.cwd(), "pacts"), consumer: "GraphQLConsumer", provider: "GraphQLProvider", logLevel: 'trace', }) before(() => provider.setup()) after(() => provider.finalize()) describe("query graphql on /graphql", () => { before(() => { const graphqlQuery = new ApolloGraphQLInteraction() .uponReceiving("a graphql request") .withQuery( ` query Query($input: pageInput) { page(input: $input) { id_client id_page similar_shops_widget { id widget_api_mapping __typename } __typename } } ` ) .withOperation('Query') .withVariables( { "input": { "id_retailer": "****", "id_client":"****" } } ) .withRequest({ path: "/graphql", method: "POST", }) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8' }, body: { data: { "page": { "id_client": "****", "id_page": "****", "similar_shops_widget": { "id": "***", "widget_api_mapping": "wtSimilarShopsGroup" } } }, }, }) return provider.addInteraction(graphqlQuery) }) it("returns the correct response", async() => { return expect(query()).to.eventually.deep.equal({ data: { "page": { "id_client": "***", "id_page": "***", "similar_shops_widget": { "id": "***", "widget_api_mapping": "wtSimilarShopsGroup" } } }, }) const output = await query(); console.log('output ', output); }) // verify with Pact, and reset expectations afterEach(() => provider.verify()) }) })```

yousafn
2023-08-10 13:54
Ahh the issue is probably in `ApolloGraphQLInteraction` if that is setting a content header on the request

yousafn
2023-08-10 13:54
I?ve not used that wrapper myself

yousafn
2023-08-10 13:56
We?ve not updated it for the V3 interface because of reasons https://github.com/pact-foundation/pact-js/issues/1093 See https://github.com/pact-foundation/pact-reference/issues/306 & https://github.com/pact-foundation/pact-js/issues/1058 for related issues with the content-type header, which I believe will be causing your issues

yousafn
2023-08-10 13:57
If this has only just occurred, you might be able to pin a version of your pact-js lib

yousafn
2023-08-10 13:57
until its fixed upstream

yousafn
2023-08-10 13:57
ty for code snippets btw

mahesh.damavarapu
2023-08-10 13:57
I changed the const graphqlQuery = new GraphQLInteraction() but still facinf the same issue

yousafn
2023-08-10 14:00
yes, that the apollo one is just a wrapper around the graphql one, which is a wrapper around the pact-js?s dsl

yousafn
2023-08-10 14:00
it sets the content type


yousafn
2023-08-10 14:01
you can just create your own wrapper, or modify that, to not set the content-type for now

mahesh.damavarapu
2023-08-10 14:15
Comment the code line works fine. Is there any link for creating custom wrapper around existing code and using it in our code base ?

poojarylatika1
2023-08-10 14:17
has joined #pact-js

sebastianmsandri
2023-08-10 16:01
has joined #pact-js

biancoc
2023-08-11 14:27
has joined #pact-js

enrique519
2023-08-11 18:29
Hello, guys! New here, could you point me to where in the docs can I understand what is the difference between PactV3 vs Pact or PactV4 vs Pact?

matt.fellows
2023-08-11 22:28
They represent the version of the pact spec they support and this what features they can support If you are new, start with the V3 one

james.jenks
2023-08-13 03:47
Can the Pact JS mock provider be run in-process, or does it require an external process to be launched? I know that it used to be true that the mock provider was out-of-process, but I'm wondering if that's changed.

matt.fellows
2023-08-13 04:37
It can't be run separately any more as it's no longer stateful. you're right that it used to be though.

svarakantham
2023-08-14 00:19
has joined #pact-js

carrm
2023-08-14 13:22
has joined #pact-js

jd.courtoy
2023-08-14 16:25
has joined #pact-js

elenadoty
2023-08-14 20:01
has joined #pact-js

a.adeyeye.gr
2023-08-15 08:49
has joined #pact-js

bas.plijnaer
2023-08-15 12:32
has joined #pact-js

mspector
2023-08-15 14:45
hi pact-js community - I'm working on a project hosted in github that follows the https://yarnpkg.com/features/zero-installs (in short: we commit our `.yarn/cache` directory). we noticed that the pact-core npm package exceeds github's 100mb file size limit. we're not on the latest version of pact, but even the latest version of pact-core is large. if I understand correctly, pact-core is so large because of the included CLI tools, which we don't use directly. is there any way around this? or can anyone think of other creative solutions?

mspector
2023-08-15 14:50
`git-lfs` is an option, but one that we'd like to avoid if possible

yousafn
2023-08-15 14:53
even if you remove the cli tools (which has been proposed), the bundle will probably still be over 100mb, it includes 5 shared libs for the pact ffi (one for each support platform, x86_64 across windows/macos/linux and arm64 for macos/linux) - each one weighs in at 20mb+ You will always need at least one shared library for the system you are running on, you could do this with separate npm packages for each platform, I believe that was tried before in the pact-node but was removed

yousafn
2023-08-15 14:56
in previous versions there was a post install script that would fetch the remote sources, (the ruby tools ) which meant smaller bundle at download time, but the package still remains the same at the end once its usable (downloaded the files from the remote source) the shared libs from the pact reference core, could be fetched at install time from a github release, for the relevant platform. We elected not to do that, as we have users generally want to included `--ignore-scripts` so it would stop pact-js from fetching out the required libs.

mspector
2023-08-15 14:58
thank you @yousafn - that's very helpful context. I may reach out with other questions but I'll bring this back to our team in the meantime while we figure out what to do

yousafn
2023-08-15 15:00
np, I think a quick solution would be maybe to mirror a fork of the project, that excludes the binaries from being packaged into the npm package, and fetch the required sources which are published on the pact-js-core release package we publish the required shared libary and associated pact.node native module that has been prebuilt per release of pact-js-core https://github.com/pact-foundation/pact-js-core/releases/tag/untagged-5c14dbdc4c8fa1c42fcb

yousafn
2023-08-15 15:04
ps you can also override in Pact-js-core/pact-js-core with an env var as to where the binaries live, so they don?t need to be in the source npm package. if that helps

yousafn
2023-08-15 15:04
ps. first time I?ve heard of zero-install from yarn.

yousafn
2023-08-15 15:04
thanks for bringing it up :slightly_smiling_face:

liam.butler
2023-08-15 15:20
has joined #pact-js

liam.butler
2023-08-15 15:33
Hi folks! Very new to Pact here, coming mainly from e2e testing with Cypress. I'm having some difficulty in transitioning from the 'Getting Started' workshop to actually getting started in my repo. My question (and I feel dumb even asking): *what's the bare minimum command I'd need to run a pact consumer test in my CLI*, after installing with something like npm/yarn? Most of the examples in the Pact docs have references to mocha, react-scripts, jest, etc, and I'm trying to figure out what is and isn't necessary. Ideally I'm thinking there must be something like `yarn run pact --spec product.pact.test.js --prefix consumer` Seems such an obvious one, but I've been looking through docs and examples for a lot of this afternoon

yousafn
2023-08-15 16:51
you need a test runner for your language, jest, mocha etc are all examples. Cypress bundles mocha in a single package, (along with other stuff) ideally you need your code, and there should be some unit tests for that, somewhere in there they hopefully will be component integration tests which mock out a provider api. this is where you would use pact, to stand in for that provider mock.

yousafn
2023-08-15 16:51
react-scripts is used for create-react-app, a bundle of tools for building a react application, it includes jest as a test runner.

liam.butler
2023-08-15 17:44
Ah! So it isn't a runner in itself. Now it makes a heap of sense! I can see some jest specs here and there in the team's repo, so I'll start from there. Thank you!

yousafn
2023-08-15 19:48
Anytime my friend, and yep you got it. Any problems, just pop back up in here and we got you!

marcocbarbieri
2023-08-15 22:47
has joined #pact-js

juandiegopalacio
2023-08-16 09:00
has joined #pact-js

liam.butler
2023-08-16 12:00
That example was super helpful to me as I get to grips with this stuff. Thank you!

tjones
2023-08-16 13:00
You?re welcome!

mssachin
2023-08-16 14:23
HI Does any one have any examples of contract tests in a Kafka setup

mssachin
2023-08-16 14:23
I am new to kafka and contract tests with kafka

mssachin
2023-08-16 14:24
any help much appreciated

matt.fellows
2023-08-16 21:55
howtoexamples


matt.fellows
2023-08-16 21:56
^^ there?s a Kafka JS example there

matt.fellows
2023-08-17 00:48
hmm that link (zero installs) doesn?t work for me, and annoyingly, the search on that site isn?t working for me right now. Anyway, thanks for sharing. I think I can guess why `zero-installs` is a good idea.

t.vandenberk
2023-08-17 09:12
has joined #pact-js

mssachin
2023-08-17 09:46
Cheers Matt

mspector
2023-08-17 14:29
that link (and a bunch of others on http://yarnpkg.com) stopped working just the other day - I read it, and found it gone when I went to review it :confused: I'm trying a different tack - using `yarn patch` to remove the /standalone directory. I'm having some trouble, though. I'm guessing nobody here has tried this before, but if you have any thoughts about that approach, please let me know

jianbin.lin
2023-08-17 15:07
has joined #pact-js

artur.suhaniaka
2023-08-17 20:34
has joined #pact-js

aniruddhasingh.kushwa
2023-08-18 01:40
has joined #pact-js

parthiban.rajasekaran
2023-08-18 08:32
has joined #pact-js

gowthamgopal24
2023-08-18 09:52
has joined #pact-js

jacopo
2023-08-18 13:42
Hi all! Does anyone know how to generate a provider-verification-result file? I'm using NodeJS to build some REST services

yousafn
2023-08-18 14:53
the results are an artefact of a provider verification run and are published to a pact broker

jacopo
2023-08-18 14:55
Thank you!But: ? how to produce this file? ? Is it the only chance to verify compatibility between consumer using API from the provider? Or is the provider OAS checked during the can-i-deploy stage (from a provider standpoint)?

yousafn
2023-08-18 15:08
i think you are asking a pactflow specific question which should belong in #pactflow the file is produced however you like, it?s your choice. you publish a self verification result to say whether the oas matches your impl, that is on you, your team and what tooling you use to test your provider

yousafn
2023-08-18 15:09
when an oas is uploaded, and an associated pact exists, a verification comparison occurs in pactflow. this also occurs at can i deploy, if there are no existing verifications. note this is for bi directional contact testing only

naimun.siraj
2023-08-18 16:50
has joined #pact-js

eugeniosaulo
2023-08-18 21:28
has joined #pact-js

pere.villega
2023-08-20 17:49
has joined #pact-js

navin.dhanaraj
2023-08-21 00:10
has joined #pact-js

eduardo.rodrigues
2023-08-22 08:05
has joined #pact-js

nickkeers
2023-08-22 08:35
has joined #pact-js

christophe.laranjo
2023-08-22 17:34
has joined #pact-js

huthayfa
2023-08-23 08:10
has joined #pact-js

dsherwin
2023-08-23 09:20
has joined #pact-js

mssachin
2023-08-23 11:22
Hello Guys, I have a below use case. Not quite sure how to approach about writing contract test for this scenario. any help will be much appreciated.

mssachin
2023-08-23 11:23
Basically I have a API Post request which gets inserted into DynamoDB. The insert event then generates a message and posts it on a topic.

mssachin
2023-08-23 11:23
I need to write tests now to basically produce and consume these events

mssachin
2023-08-23 11:24
Not sure where to start, been trying a couple of things in vain

mssachin
2023-08-23 11:24
I am not looking for a solution, I am looking for some tips on how can this be structured

mssachin
2023-08-23 11:26
Basically from a contract perspective what I think is I need to validate that each producer should post the message in a valid format.

mssachin
2023-08-23 11:26
is that correct?

mssachin
2023-08-23 11:27
So consumer says I need message in this format and when something changes on the producer side it flags as error in broker loosely speaking

marcel.novak
2023-08-23 13:53
has joined #pact-js

davidm
2023-08-23 15:57
has joined #pact-js

mssachin
2023-08-24 05:35
Any words for me please

abubics
2023-08-24 06:22
Sounds like a pretty clear https://docs.pact.io/implementation_guides/javascript/docs/messages use case, have you read about it before?

mssachin
2023-08-24 08:07
Yes I did

svmanikantakumar
2023-08-24 08:50
has joined #pact-js

abubics
2023-08-24 10:05
Do you have any more specific questions? It's pretty wide open, I'm not sure I know how to help :slightly_smiling_face: Like you said, the consumer says "I expect messages in this shape" and the provider says "I will send messages in that shape for you", and everything else about the broker interactions works the same as synchronous Pact tests, afaik.

eomeroff
2023-08-24 13:49
has joined #pact-js

yousafn
2023-08-24 14:29
I would agree with Boris?s sentiment here > Do you have any more specific questions? It?s pretty wide open, I?m not sure I know how to help You are agnostic of the transport mechanism in MessagePact, you just care about testing the message.


yousafn
2023-08-24 14:30
some random messaging examples I pulled together https://github.com/YOU54F/pact-logical-replication

mssachin
2023-08-24 15:19
Please pardon my ignorance

mssachin
2023-08-24 15:19
const wal2JsonHandler = function (wal2JsonEvent: Wal2JsonEvent) { console.log(wal2JsonEvent) // if (!wal2JsonEvent.xid || !wal2JsonEvent.change) { if (!wal2JsonEvent.change) { console.log(wal2JsonEvent); throw new Error("missing change data"); }

mssachin
2023-08-24 15:19
what is this function for?

yousafn
2023-08-24 15:20
that would be where you business logic is, where you would process the message and do something

mssachin
2023-08-24 15:20
aah

yousafn
2023-08-24 15:23
code usually needs to be separated out so the business logic of dealing with the messages is agnostic of its transport mechanism, (like hexagonal arch practises) so essentially you can swap out the underlying transport mechanism without affecting your business logic. That way you can test the bit that processes the message, without having to worry about kafka, or grpc, etc.

yousafn
2023-08-24 15:25
in the above situ, I am testing database replication, but in reality I am just checking the json messages creating conform to a certain shape. that are emitted by the wal2json convertor (which takes database writes and converts them to a json payload)

mssachin
2023-08-24 15:30
Ok so if I understand it right. In my case. 1. I need to validate the content of the JSON payload which gets generated as a result of a database write. 2. This write is a result of a POST call to an endpoint So from what I see const wal2JsonHandler = function (wal2JsonEvent: Wal2JsonEvent) { console.log(wal2JsonEvent) // if (!wal2JsonEvent.xid || !wal2JsonEvent.change) { if (!wal2JsonEvent.change) { console.log(wal2JsonEvent); throw new Error("missing change data"); }

mssachin
2023-08-24 15:30
the above should be validated the JSON

mssachin
2023-08-24 15:31
and the actual test should be the post call?

mssachin
2023-08-24 15:31
Is that understanding correct

mssachin
2023-08-24 15:31
Please pardon my ignorance

mssachin
2023-08-24 15:32
I am just trying to get my head around things as a test engineer

riley.marzka
2023-08-24 17:47
has joined #pact-js

jared.anderson
2023-08-24 18:15
has joined #pact-js

timofeev1valeriy
2023-08-25 08:32
has joined #pact-js

kastala.nirosha
2023-08-25 09:17
has joined #pact-js

kkanova
2023-08-25 12:55
has joined #pact-js

theteea
2023-08-25 13:18
has joined #pact-js

theteea
2023-08-25 13:26
@theteea has left the channel

eomeroff
2023-08-25 13:38
Hi all, I am using `"@pact-foundation/pact": "^9.16.0"`, with node 18 and I am failing to install pact dependencies (the code below): `#!/usr/bin/env bash` `set -e` `apk --no-cache add ca-certificates wget` `wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub` `wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.34-r0/glibc-2.34-r0.apk` `apk add glibc-2.34-r0.apk` I get the following error: `2023-08-25 09:31:12 (36.2 MB/s) - 'glibc-2.34-r0.apk' saved [1940882/1940882]` `125fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz` `126fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz` `127(1/1) Installing glibc (2.34-r0)` `128ERROR: glibc-2.34-r0: trying to overwrite etc/nsswitch.conf owned by alpine-baselayout-data-3.4.3-r1.` `1291 error; 20 MiB in 27 packages`


eomeroff
2023-08-25 13:38
the error started after I switched from node 16 to 18

yousafn
2023-08-25 13:54
so alpine isn't supported for the latest release with the rust core for the ruby backed core, see https://github.com/pact-foundation/pact-ruby-standalone/wiki/Using-the-pact-ruby-standalone-with-Alpine-Linux-Docker or just use a debian based image or similar (non musl)

yousafn
2023-08-25 13:58
Also for future reference, I would advise reading up on https://docs.pact.io/help/how_to_ask_for_help#4-ask-a-good-question It provides some good advise at to how to communicate your problem with others. Basic information like > ? Details of the environment you're using (Mac/Window/Linux, Docker). Save the to and fro, and actually helps others, help you :+1:

yousafn
2023-08-25 14:00
so provide a reproducible case in node 16 and a failing case in node 18

yousafn
2023-08-25 14:00
We can't help you really, if we can't replicate it

eomeroff
2023-08-25 14:04
You helped enough. thank you.

yousafn
2023-08-25 14:06
```FROM --platform=linux/amd64 node:18-alpine RUN apk --no-cache add gcompat libc6-compat bash WORKDIR /usr/app RUN npm install @pact-foundation/pact@9.16.0``` builds for me :shrug:

eomeroff
2023-08-25 14:11
:+1:

charlan.bettiol
2023-08-25 16:32
has joined #pact-js

david.tu
2023-08-25 17:51
has joined #pact-js

viktor.stephanyk
2023-08-28 12:46
has joined #pact-js

arpit.gawande
2023-08-28 12:58
has joined #pact-js

alexander.doppelbauer
2023-08-28 17:52
has joined #pact-js

jayapriya.m
2023-08-29 00:22
has joined #pact-js

grnmeadow7
2023-08-29 03:27
has joined #pact-js

sayantini.basak
2023-08-29 10:02
has joined #pact-js

shayanadc
2023-08-29 18:19
has joined #pact-js

jack.jones9512
2023-08-30 15:49
has joined #pact-js

craftyqa
2023-08-30 16:54
has joined #pact-js

mssachin
2023-08-31 10:02
@yousafn @abubics apologies for tagging. However now I understand what you guys were talking about. Took me a while but got there eventually. Thanks a ton. Apologies been a test engineer for far to long and used to thinking in a certain fashion. Thanks agian

yousafn
2023-08-31 11:48
It?s okay Sachin! I can understand and emphasise with you, as I was in that position prior to learning about contract testing, and more of an insight into what the developers were doing, and trying to cut overlaps in testing, and push concerns down the stack. Glad things are beginning to fall into place. I?m still learning every day!

jean-baptiste.bronisz
2023-08-31 15:48
has joined #pact-js

razorangel
2023-08-31 18:41
has joined #pact-js

dsharma
2023-08-31 19:11
has joined #pact-js

eytan.hanig
2023-08-31 22:10
has joined #pact-js

abubics
2023-09-01 00:08
Yeah, great that it's making more sense :tada: and also maybe a separate tip: sometimes it's better to step away from the code, and draw a diagram of the important pieces, then put a circle (or a box, or whatever shape you like) around the bits that are relevant to this testing case.

eytan.hanig
2023-09-01 03:07
@eytan.hanig has left the channel

munitheja91
2023-09-01 13:14
has joined #pact-js

alvarado.kelvin
2023-09-02 12:48
has joined #pact-js

sautade
2023-09-04 01:23
has joined #pact-js

sautade
2023-09-04 02:22
Hi all, I really like the idea of contract testing the microservices and I am trying to introduce this in our organisation. But I have hit a problem where the request made by the consumer is just flagged incorrect without much explanation. Please refer the test execution logs below. I can't see why this request is incorrect. If you think following log is not enough to debug it I am happy to share more context and the test code. I am using `"@pact-foundation/pact": "^12.1.0",` and `PactV3` *Can someone please help me resolve this issue ?* ```? ~/Documents/projects/squiz/dxp-console/ [feat/quality-47*] npm run test:pact > dxp-console@0.1.0 test:pact > jest --config=jest.pact.config.ts at Object.<anonymous> (apps/component-service/src/Services/component/src/contract-test/helpers/ComponentProvider.ts:8:9) console.log MOCK SERVER URL => http://127.0.0.1:8081 at apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts:80:17 RUNS apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts 2023-09-04T02:23:57.073080Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request OPTIONS /__dxp/au/components-management/dx-team-uat-6287/v1/component-set 2023-09-04T02:23:57.073488Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /__dxp/au/components-management/dx-team-uat-6287/v1/component-set, query: Some({"sort[]": ["displayName"], "page": ["1"]}), headers: Some({"origin": ["http://localhost"], "accept": ["*/*"], "accept-language": ["en"], "user-agent": ["Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML", "like Gecko) jsdom/20.0.3"], "connection": ["keep-alive"], "content-type": ["application/json"], "x-requested-with": ["XMLHttpRequest"], "accept-encoding": ["gzip", "deflate"], "host": ["localhost:8081"], "referer": ["http://locahost/"]}), body: Missing ) 2023-09-04T02:23:57.075548Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Responding to CORS pre-flight request 2023-09-04T02:23:57.076940Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request GET /__dxp/au/components-management/dx-team-uat-6287/v1/component-set 2023-09-04T02:23:57.076963Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /__dxp/au/components-management/dx-team-uat-6287/v1/component-set, query: Some({"sort[]": ["displayName"], "page": ["1"]}), headers: Some({"origin": ["http://localhost"], "accept": ["*/*"], "accept-language": ["en"], "user-agent": ["Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML", "like Gecko) jsdom/20.0.3"], "connection": ["keep-alive"], "content-type": ["application/json"], "x-requested-with": ["XMLHttpRequest"], "accept-encoding": ["gzip", "deflate"], "host": ["localhost:8081"], "referer": ["http://locahost/"]}), body: Missing ) [12:23:57.079] ERROR (29361): pact@12.1.0: Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was incorrect: GET /__dxp/au/components-management/dx-team-uat-6287/v1/component-set FAIL apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts Pact with Component/Management API - Consumer (DXP-Console) Test GET /component-set ? returns an HTTP 200 and a list of component sets (29 ms) ? Pact with Component/Management API - Consumer (DXP-Console) Test ? GET /component-set ? returns an HTTP 200 and a list of component sets Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 5.041 s Ran all test suites.```

tjones
2023-09-04 03:09
Can you post your test code? It should be failing with details

tjones
2023-09-04 03:10
Also, those log messages don't look right at all

tjones
2023-09-04 03:11
I'm not sure where they're coming from

tjones
2023-09-04 03:11
Looks like some pact internals that shouldn't be showing up

sautade
2023-09-04 04:21
my test code goes something like this ```import { PactV3 as Pact } from '@pact-foundation/pact'; import path from 'path'; const port = 8081; export const componentProvider = new Pact({ consumer: 'dxp-console', cors: true, dir: path.resolve(process.cwd(), 'apps/component-service/src/Services/component/contract-test/pacts'), logLevel: 'info', port: port, provider: 'component-service', }); describe('Pact with Component/Management API - Consumer (DXP-Console) Test', () => { describe('GET /component-set', () => { beforeAll(async () => { componentProvider .given('I have a component set') .uponReceiving('a request for all component sets') .withRequest({ method: 'GET', path: '/__dxp/au/components-management/dx-team-uat-6287/v1/component-set', query: { page: '1', 'sort[]': ['displayName'], }, headers: { 'accept': '*/*', 'accept-encoding': 'gzip, deflate', 'accept-language': 'en', 'content-type': 'application/json', 'connection': 'keep-alive', 'host': 'localhost:8081', 'origin': 'http://localhost', 'referer': 'http://locahost/', 'user-agent': 'Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/20.0.3', 'x-requested-with': 'XMLHttpRequest', }, }) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json; charset=utf-8', }, body: GET_COMPONENT_SET_EXPECTED_RESPONSE, }); }); it('returns an HTTP 200 and a list of component sets', async () => { await componentProvider.executeTest(async (mockserver) => { console.log("MOCK SERVER URL => " + mockserver.url); const componentServiceConfig: ComponentServiceConfiguration = { ...mockBaseServiceConfiguration, baseUrl: mockserver.url + '/__dxp/au/components-management/dx-team-uat-6287/v1/component-set', sessionUrl: 'http://localhost:8081/__dxp/au/components-management/dx-team-uat-6287', }; componentServiceConfig.httpService = newHttpService; const componentService = new ComponentService(componentServiceConfig); const response = await lastValueFrom(componentService.getComponentSet(dto)); //Assert expect(response).toEqual(GET_COMPONENT_SET_EXPECTED_RESPONSE); }); }); }); });```

tjones
2023-09-04 04:22
The line that says `sessionUrl: 'http://localhost:8081/` looks suspicious

tjones
2023-09-04 04:22
should that be `mockserver.url` ?

tjones
2023-09-04 04:23
Also, is your `baseUrl` correct? Usually it would just be `mockserver.url`, and your API code would know the path

sautade
2023-09-04 04:24
yes correct. That was an oversight. I fixed it to be like this. But that URL is purely provided because of some URL logic in our app. ```const componentServiceConfig: ComponentServiceConfiguration = { ...mockBaseServiceConfiguration, baseUrl: mockserver.url + '/__dxp/au/components-management/dx-team-uat-6287/v1/component-set', sessionUrl: mockserver.url + '/__dxp/au/components-management/dx-team-uat-6287', };```

sautade
2023-09-04 04:27
It still fails with the same error ```[14:26:20.038] ERROR (35262): pact@12.1.0: Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was incorrect: GET /__dxp/au/components-management/dx-team-uat-6287/v1/component-set FAIL apps/component-service/src/Services/component/src/contract-test/ComponentServiceConsumer.spec.ts Pact with Component/Management API - Consumer (DXP-Console) Test GET /component-set ? returns an HTTP 200 and a list of component sets (27 ms) ? Pact with Component/Management API - Consumer (DXP-Console) Test ? GET /component-set ? returns an HTTP 200 and a list of component sets```

tjones
2023-09-04 04:29
My guess is this is a bug @matt.fellows - probably this code doesn't do the right thing: https://github.com/pact-foundation/pact-js/blob/ce5973cd6864e7b85c44468553ea6f94e8e34d3f/src/v3/display.ts#L141

tjones
2023-09-04 04:29
Also, those info messages shouldn't be being printed. I fixed that ages ago, looks like it has been unfixed.


tjones
2023-09-04 04:31
(that might not be the problem, of course)

tjones
2023-09-04 04:32
Anyway, I think this is a bug. It's hard to ask you to open a bug report if you don't know what the actual problem is, but, I would confirm that you really are sending the request that you're expecting to send

tjones
2023-09-04 04:33
you can do this by setting the log level to debug, and confirming that the query parameters and headers really are what you say they are

sautade
2023-09-04 04:38
thanks a lot for taking time to analyze this @tjones. some deductive reasoning exposed a header that was the problem. I have removed it now and the test seems to pass. But yes, It would be nice if Pact error could point me to the wrong header.

tjones
2023-09-04 04:39
Can you open a bug report on the pact js repo? I?m not a maintainer any more, otherwise I?d do it for you

sautade
2023-09-04 04:44
Yes I am happy to do it. Just to confirm the problem here is it safe to say => `Pact doesn't display the matcher errors when actual and expected requests are different.`?


tjones
2023-09-04 04:45
Well, in this case it?s to do with header mismatches

tjones
2023-09-04 04:45
So that?s (at least) the problem

tjones
2023-09-04 04:45
And the example with your specific header is useful - maybe there?s something about it

joshua.ellis
2023-09-04 04:51
has joined #pact-js

sautade
2023-09-04 05:57
Also I didn't understand your comment about INFO messages. I had log level set to `info` . Is that why its showing up?

tjones
2023-09-04 06:33
No, it's for the maintainers. The core logs aren't supposed to show when log level is set to info

matt.fellows
2023-09-04 06:51
hmm that log level at INFO looks suspicious indeed. I?m wondering if a config has changed somewhere.

matt.fellows
2023-09-04 06:53
In any case, if you could please raise a bug https://github.com/pact-foundation/pact-js/issues/new/choose that would be ace. There are at least 2 issues:

matt.fellows
2023-09-04 06:53
1. log levels incorrect (INFO when they should be DEBUG or TRACE) 2. Not printing a helpful error in the case the client can?t determine the problem

sautade
2023-09-04 06:55
Sure @matt.fellows, let me raise the bugs :bug: :raised_hands:

bbodoque.atsistemas
2023-09-04 10:21
has joined #pact-js

bbodoque.atsistemas
2023-09-04 10:25
Hi #pact-js, I'm new on using pact and I do have a doubt I'm not able to resolve by myself. Would it be this a right place to post my question? > I have already checked stackoverflow and the documentation. I have also asked chatgpt for some help but I still have a doubt.

bbodoque.atsistemas
2023-09-04 11:42
*Is it possible to create consumer pacts for multiple providers from a angular application using PactWeb?* I've seen that this might be possible using Pact. I've also seen that PactWeb is an https://docs.pact.io/implementation_guides/javascript/docs/migrations/9-10, but the project I am currently working with is quite old and I inherited that behaviour. I've checked https://stackoverflow.com/questions/58520585/pact-vs-pactweb and it only mentions that Pact and PactWeb difference is that PactWeb allows to work in non-node based environments. I have tried to find some extra info in old versions but I couldn't. I've also tried asking chat GPT and I got the following answer, although I could not get the source of such affirmation. ```I apologize for any confusion earlier. PactWeb, the JavaScript library for Pact, is primarily designed for consumers to define and verify contracts with a single provider at a time. However, you can work around this limitation by creating separate Pact instances for each provider you want to interact with.```

matt.fellows
2023-09-04 22:48
The answer should be yes. You would just need to create a separate `PactWeb` instance for each provider _and_ create a separate https://github.com/pact-foundation/pact-js-core#create-mock-server for each one outside of the angular process

tjones
2023-09-05 01:30
Also note that pact web is deprecated, and not the recommended way to use pact

tjones
2023-09-05 01:30
It's better to do your contract tests separately from the browser

tjones
2023-09-05 01:31
> PactWeb, the JavaScript library for Pact, is primarily designed for consumers to define and verify contracts with a single provider at a time. This is almost, but not quite, entirely unhelpful. I wouldn't recommend asking GPT for anything to do with pact

bbodoque.atsistemas
2023-09-05 04:55
Thank you so much for your answers!! It is crystal clear now to me. :heart:

avanlent
2023-09-05 05:56
has joined #pact-js

mspector
2023-09-05 14:51
could someone help me understand the expected behavior of `MatcherV3.timestamp`? in the documentation (https://docs.pact.io/implementation_guides/javascript/docs/matching#v3-matching-rules) it shows that `timestamp` can be used without a second argument representing an example. however, when I try using it without an example, it throws the error `you must provide an example timestamp` the code and documentation talk about "generators" - do I need to specify that somehow? (I'll post a code snippet in thread)

mspector
2023-09-05 14:52
```const expectedResponse = { fully_updated: boolean(true), run_sets: eachLike([ { submission_timestamp: timestamp("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"), last_modified_timestamp: timestamp("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"), }, ], { min: 1 }), }; await cbasPact.addInteraction({ states: [{ description: 'at least one run set exists with method_id 00000000-0000-0000-0000-000000000009' }], uponReceiving: 'get run set with method_id=00000000-0000-0000-0000-000000000009 and page_size=1', withRequest: { method: 'GET', path: '/api/batch/v1/run_sets', query: { method_id: '00000000-0000-0000-0000-000000000009', page_size: 1 } }, willRespondWith: { status: 200, body: expectedResponse }, });```

yousafn
2023-09-05 15:26
Hey buddy, From the docs, and the doc string, it suggests that it should generate one as you expect https://github.com/pact-foundation/pact-js/blob/9bb0d10d609559493e8fb3b1c1fd952ca8f724b2/src/v3/matchers.ts#L344 however example is required to be set (it?s not optional in the function params) and it explicitly throws an error. The example tests in the repo, all show an example being provided. So there is either a discrepancy between the docs/comments and code, and not sure currently as to which is correct.

mspector
2023-09-05 15:38
ok I see. the docs must be incorrect, because the language is very clear: > String value that must match the provided datetime format string. See https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html for details on the format string. If the example value is omitted, a value will be generated using a Timestamp generator and the current system date and time.

yousafn
2023-09-05 16:46
the docs, match up with the comment in the code. the code implementation differs, from both the comment in the code, and the documentation. the tests confirm the behaviour of the code, and contradict (or rather don?t test the case suggested in the docs, or code comment - that omitting the example value, will generate a new one)

yousafn
2023-09-05 16:48
My next port of call would be to check the git history to see when the code was last touched, and also check with the pact-reference implementation in rust to check the source behaviour, and confirm if pact-js matches that or not.

callum.atkinson
2023-09-05 17:00
has joined #pact-js

emilie.bline
2023-09-05 22:27
has joined #pact-js

matt.fellows
2023-09-06 00:02
See also https://github.com/pact-foundation/pact-js/issues/1076, would you be up for a PR to help address it?

matt.fellows
2023-09-06 00:03
I think option (1) as described here would be ideal (probably supporting (3), which might just come for free with some documentation to make it clear it?s possible)


matt.fellows
2023-09-06 02:51
Amazing, thank you!


me1414
2023-09-06 12:37
has joined #pact-js

juantamosaitis2015
2023-09-06 13:24
has joined #pact-js

ali.tariq
2023-09-06 14:51
has joined #pact-js

anas.zakarneh
2023-09-06 15:04
has joined #pact-js

jvillars
2023-09-06 17:53
has joined #pact-js

mspector
2023-09-07 13:04
thanks for the context, it's helpful! > would you be up for a PR to help address it? potentially - I don't want to commit just yet (I've solved my immediate problem with a regex), but if I do, I'll post again in this thread, find the contributor guidelines, and take it from there. I agree option (1) would be ideal

kwongs
2023-09-08 01:45
has joined #pact-js

alicankarayelli
2023-09-08 10:43
has joined #pact-js

sgregory875
2023-09-08 12:23
has joined #pact-js

amagana
2023-09-08 22:40
has joined #pact-js

heverson.amorim
2023-09-09 10:43
has joined #pact-js

vdlre1994
2023-09-11 05:55
has joined #pact-js

rware4
2023-09-11 10:16
has joined #pact-js

hdjikine
2023-09-11 13:55
has joined #pact-js

andrea.paschal
2023-09-11 16:48
has joined #pact-js

amagana
2023-09-11 20:49
Hello, I'm new to writing contract tests and was trying to set up a test using Pact but am running into an odd error when I run the test file. I was hoping someone might be able to point me in the right direction here. Will post code in thread.

amagana
2023-09-11 20:51
```import axios from 'axios'; import { MatchersV3 } from '@pact-foundation/pact'; import provider from './pact'; import { getProcessingAccounts } from '../../src/rest/processing-accounts'; import { processingAccountMock } from '../mocks/processing-accounts'; const { like } = MatchersV3; describe('onboarding/risk api test', () => { describe('getting processing account status', () => { beforeAll(() => { provider .given('I have a list of processing accounts') .uponReceiving('a request for all processing accounts for a business') .withRequest({ method: 'GET', headers: { Authorization: like('12345') }, url: '/v2/processingAccounts', query: { businessId: '111222333' } }) .willRespondWith({ status: 200, body: like(processingAccountMock) }); }); it('should return the correct processing account format', async () => { await provider.executeTest(async (mockserver) => { axios.defaults.baseURL = mockserver.url; const response = await getProcessingAccounts('111222333', '12345'); expect(response).toStrictEqual(processingAccountMock); }); }); }); });```


yousafn
2023-09-11 22:13
withRequest should have `path` not `url` ``` provider .given('I have a list of dogs') .uponReceiving('a request for all dogs with the builder pattern') .withRequest({ method: 'GET', path: '/dogs', query: { from: 'today' }, headers: { Accept: 'application/json' }, }) .willRespondWith({ status: 200, headers: { 'Content-Type': 'application/json' }, body: EXPECTED_BODY, });```

amagana
2023-09-11 22:14
Ahh, that makes sense, I had been following a different tutorial before and switched but forgot to change that, thank you

tigrandza
2023-09-12 03:14
@tigrandza has left the channel

olof.stalnacke
2023-09-12 05:31
has joined #pact-js

nvangari
2023-09-12 05:39
has joined #pact-js

alan.zhu
2023-09-12 07:13
Hey folks I tried to generate pact with header - `Content-Type": "application/x-protobuf-json-format` but generates some weird represation of expected response string(not a map as `application/json`) like `"{"requestId":{"pact:matcher:type":"type","value":"2b0124bf-4b7a-4ac7-938c-6021be9cb661"}}"`and fail the provider's verification, is it because of pact-js doesn't support this type of type(`application/x-protobuf-json-format`) of content well right now?

matt.fellows
2023-09-12 07:19
mind sharing a bit more about your setup - e.g. consumer test, logs etc.?

alan.zhu
2023-09-12 07:30
sure, I had setup consumer test with `Content-Type": "application/x-protobuf-json-format` (I haven't tried this type of content before), define a response like this ``` const responsePostOffers = { requestId: string(UUID) }``` and pact generate the expected response in a string like this: ```"body": "{\"requestId\":{\"pact:matcher:type\":\"type\",\"value\":\"2b0124bf-4b7a-4ac7-938c-6021be9cb661\"}\"}"``` when I tried to verify it in the provider side, it fails, because the request id only contain a single UUID instead of the matcher that pact generated : (

alan.zhu
2023-09-12 07:38
I can show you the pact I generated, like this ```{ "consumer": { "name": "test1" }, "interactions": [ { "description": "Get test as an offer from TopK", "providerStates": [ { "name": "the service is operating normally" } ], "request": { "body": "{\"productsPerVertical\":{\"INSURANCE\":1}}", "headers": { "Content-Type": "application/x-protobuf-json-format" }, "method": "POST", "path": "/v3/cross-sell/products" }, "response": { "body": "{\"requestId\":{\"pact:matcher:type\":\"type\",\"value\":\"2b0124bf-4b7a-4ac7-938c-6021be9cb661\"}}", "headers": { "Content-Type": "application/x-protobuf-json-format" }, "status": 200 } } ], "metadata": { "pact-js": { "version": "10.4.1" }, "pactRust": { "ffi": "0.4.0", "models": "1.0.4" }, "pactSpecification": { "version": "3.0.0" } }, "provider": { "name": "test2" } }```

matt.fellows
2023-09-12 08:03
I want to see how you write the test. The generated pact looks incorrect

alan.zhu
2023-09-12 08:13
yeah, I think so, here is the consumer test I have ```/* eslint-disable @typescript-eslint/no-explicit-any */ import {MatchersV3} from '@pact-foundation/pact'; import {OffersClient} from '../offersClient'; import path from 'path'; import {PactV3} from '@pact-foundation/pact'; import {CONSUMER, PROVIDER_TOPK} from '../constants'; import {AxiosResponse} from '@sample/topk-api-client'; import {TopKResponse} from '../../../src/server/services/top-k/types'; const {string, integer, decimal} = MatchersV3; const UUID = '2b0124bf-4b7a-4ac7-938c-6021be9cb661'; //This ID is static to avoid updates to the published contracts every time the CI job runs. describe('The Offers API', () => { const pactPath = `${process.env.CI_BUILDS_DIR || process.cwd()}/pacts`; const mockProvider = new PactV3({ port: 8081, dir: path.resolve(pactPath), // folder with created contracts consumer: CONSUMER, provider: PROVIDER_TOPK, logLevel: 'debug', }); const requestHeaders = {'Content-Type': 'application/x-protobuf-json-format'}; const responseHeaders = {'Content-Type': 'application/x-protobuf-json-format'}; const requestPostOffers = { productsPerVertical: { INSURANCE: 1, }, }; const responsePostOffers = { requestId: string(UUID), }; it('returns 200 when test addons are posted', () => { // Arrange: Setup our expected interactions mockProvider .given('the service is operating normally') .uponReceiving('Get test as an offer from test') .withRequest({ method: 'POST', path: '/v3/test/products', headers: requestHeaders, body: requestPostOffers, }) .willRespondWith({ status: 200, headers: responseHeaders, body: responsePostOffers, }); // Act: make request to Pact mock server return mockProvider.executeTest(async () => { const offersClient = new OffersClient(); const offersResponse = (await offersClient.products( requestPostOffers as any )) as AxiosResponse<TopKResponse>; // assert that we got the expected response expect(offersResponse.status).toEqual(200); return; }); }); });```

alan.zhu
2023-09-12 08:16
I think the key point may be related to `{'Content-Type': 'application/x-protobuf-json-format'}` if I change it to `application/json` ,everything looks fine(I can generate right matcher rules and request&response as a map)

rksekar5
2023-09-12 12:30
has joined #pact-js

ying.li
2023-09-13 02:54
has joined #pact-js

romuald.quantin
2023-09-13 15:24
Hi all, looking at https://github.com/pactflow/pact-cypress-adapter for pact bi-directional flow. This can only intercept requests made client side right? Any advice to cover request made server-side in a NextJS app (SSR) for example?

yousafn
2023-09-13 15:31
Hello Romu, long time. it?s designed to work with cypresses own request interception mechanism. Are you testing your nextjs ssr app with cypress?

yousafn
2023-09-13 15:34
It?s works similar to pmpact, it just leverages whatever mechanism in the native test tool you are using and converts that into a pact specification


yousafn
2023-09-13 15:35
oh sorry pmpact is the inverse, pact -> postman

romuald.quantin
2023-09-14 08:52
Hey @yousafn Yes we have an SSR NextJS App, with requests on the server-side (using NodeJS) and client-side (using XHR). I thought that Cypress was not able to intercept server-side requests but it seems that it does if I read that well: https://docs.cypress.io/guides/guides/network-requests So that should be all good, I just misunderstood what I could and could not do. Thanks for looking into that!

romuald.quantin
2023-09-14 09:00
Sorry another question, how is the GraphQL support with the bi-directional flow. I know that?s just http requests, but any difficulties or blockers in intercepting graphQL requests to generate the Pact contracts?

sreenivas.chaitanya
2023-09-14 11:26
Hi , Iam trying to use the pact js trial version broker , in my test code , can some one tell me how I can use pact broker with token instead of user name and password ? in this code ```"test:publish": "pact-broker publish /pacts --consumer-app-version=\"$(npx absolute-version)\" --auto-detect-version-properties --broker-base-url=https://ysi5tc076m.execute-api.eu-west-2.amazonaws.com:443 --broker-username user --broker-password passxx"```

yousafn
2023-09-14 12:36
Hey, Not sure what this is > pact js trial version broker Could you clarify? Regarding usage of the pact-cli, see our https://docs.pact.io/pact_broker/client_cli/readme#usage---cli If it is is the OSS Pact Broker ? https://github.com/pact-foundation/pact-broker-docker ? https://github.com/pact-foundation/pact-broker It only supports basic auth mechanisms. > Basic auth parameters can be specified using the `$PACT_BROKER_USERNAME` and `$PACT_BROKER_PASSWORD` environment variables, or the `-u` or `--broker-username` and `-p` or `--broker-password` parameters. If it is a http://Pactflow.io broker > Authentication using a bearer token can be specified using the environment variable `$PACT_BROKER_TOKEN` or the `-k` or `--broker-token` parameters. This bearer token authentication is used by https://pactflow.io/ and is not available in the https://docs.pact.io/pact_broker/, which only supports basic auth.

sreenivas.chaitanya
2023-09-14 13:48
> using `--broker-toke I was able to connect thanks`

david.hodnett
2023-09-14 18:06
has joined #pact-js

matt.fellows
2023-09-14 22:15
Just remember that Pact is free and open source. Pactflow is the commercial product

jonatan.bjork
2023-09-15 13:30
has joined #pact-js

jonatan.bjork_test1
2023-09-15 13:41
has joined #pact-js

you1
2023-09-15 13:41
has joined #pact-js

jonatan.bjork_test2
2023-09-15 13:42
has joined #pact-js

you1634
2023-09-15 13:43
has joined #pact-js

m_testnewinvite
2023-09-17 22:43
has joined #pact-js

georg.duemlein
2023-09-18 04:09
has joined #pact-js

sam647
2023-09-18 14:37
has joined #pact-js

edward
2023-09-19 07:24
has joined #pact-js

dbc216
2023-09-19 14:17
has joined #pact-js

amagana
2023-09-19 21:45
Hello again, I'm working on verifying a pact I generated. I set the log level to `debug` and am seeing a lot of this error: `[tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35)` as well as `Caught panic with error: failed printing to stderr: Resource temporarily unavailable (os error 35)` It seems like the test is getting about halfway through the matchers before randomly stopping. Unsure if theres a setting I need to change so any advice here would be appreciated.

amagana
2023-09-19 22:47
`thread '<unnamed>' panicked at 'failed printing to stderr: Resource temporarily unavailable (os error 35)', library/std/src/io/stdio.rs:1019:9`

matt.fellows
2023-09-19 23:30
A panic whilst printing to stderr, haven't seen that one before. Could be a red herring. Feel free to share the logs here and we can a peek

tan.k.h.usa
2023-09-20 00:31
has joined #pact-js

daniel.hyun.chae
2023-09-20 13:19
has joined #pact-js

daniel.hyun.chae
2023-09-20 13:25
Hi, Pact Matcher api has a type based matcher 'like', For example, if there are types and a matcher is generated from this type. Will Pact (contract) be created based on typescript type 'TestType'? or Pact will guess the type based on the example value? (In this case, field1, field2 are string). So, essentially, the question is whether 'like' matcher is based on typescript type definition or type inferred from example value. ```type TestType = { field1: string | number; field2: TestType2 } type TestType2 = "option1" | 'option2' const testData:TestType = { field1: 'stringValue', field2 'option1' } const matcher = MatcherV3.like(testData)```

yousafn
2023-09-20 13:27
Hey, Type is inferred from the value provided, with the `like` matcher

yousafn
2023-09-20 13:27
so in your case it would be a string

daniel.hyun.chae
2023-09-20 13:33
Thanks for the quick answer! Do you know if there is a plan to support matcher based on typescript type instead of inferred type from provided value? I know that Pact doesn't have a vision to be a schema checker but just to know:)

yousafn
2023-09-20 14:03
I?m not sure, I probably wouldn?t implement it. You could raise a feature request and ascertain interest? I have seen this project https://github.com/HLTech/pact-gen-ts I haven?t used it however

yousafn
2023-09-20 14:03
looks like it could be cool though, similar to how annotations are used to generate openapi docs with certain tools

yousafn
2023-09-20 14:04
I have a love / hate relationship with type checkers in general


amagana
2023-09-20 19:15
The issue is that there's not much to show from the logs, its just going through the matcher but occasionally it will show something like this ```[tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) [tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) [tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) [tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) [tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) [tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) [tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) [tracing-subscriber] Unable to write an event to the Writer for this Subscriber! Error: Resource temporarily unavailable (os error 35) 2023-09-20T19:07:44.686013Z DEBUG ThreadId(02) verify_interaction{interaction="a request for all processing accounts for a business"}: pact_matching::json: compare: Comparing path $.processingAccounts[2].parent.serviceType```

amagana
2023-09-20 19:15
If theres something specific I should look for in the logs that would help, I can't really copy the whole thing since its hundreds of lines

amagana
2023-09-20 19:16
```Caught panic with error: failed printing to stderr: Resource temporarily unavailable (os error 35) [12:07:44.693] DEBUG (38324): pact-core@14.0.4: shutting down verifier with handle 0 2023-09-20T19:07:44.694175Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_shutdown FFI function invoked [12:07:44.694] DEBUG (38324): pact-core@14.0.4: response from verifier: null, 1 [12:07:44.694] ERROR (38324): pact-core@14.0.4: Verification unsuccessful```

matt.fellows
2023-09-20 22:54
So it looks like it does complete. Any chance you could put together a repro for this we could use to debug the issue? Is this locally on your machine, or CI and what is the OS etc.? You can then raise it here: https://github.com/pact-foundation/pact-js/issues and we can investigate

abubics
2023-09-20 23:59
Yeah, since Pact is concerned with what is actually sent, not what is "promised" to be sent, I would be surprised if it happens. But I don't think there's anything technically preventing it.

jake.corn
2023-09-21 14:01
has joined #pact-js

karl980
2023-09-21 16:44
has joined #pact-js

sashi.kandru
2023-09-21 20:00
HI Team, As the pact specification https://docs.pact.io/getting_started/specification#client-language-support are different for different languages. Is it ok to have all teams in an organization use one language say JS, if we want to build a centralized pipeline for all the teams? What are the disadvantages to do something like this from a contract test writing perspective?

matt.fellows
2023-09-21 22:38
Pact should be thought of as a unit testing tool, so that makes it hard to test non JS languages with JS. You can just serialise the pact files to the lowest common pact version supported by the languages you use (e.g. v2) and they should be interoperable

uglyog
2023-09-21 23:05
But there is no reason not to have your tests in a different language as your implementation, as long as you can call the non-JS code from JS.

uglyog
2023-09-21 23:06
It just people like to see the same code and frameworks. For instance, a .Net developer will not liking see JS tests in a .Net project.

sashi.kandru
2023-09-21 23:15
Got it!! The teams have to also manage the dependencies for 2 languages I guess. Not sure if you have seen such pattern anywhere else ?

yousafn
2023-09-22 11:38
Yeah that is the common blocker, if you are a .NET developer shop, writing tests in JS could mean you may struggle to adopt developers into maintaining the tests, potentially allowing for drift between the generated contracts and actual implementation, which is really want to you want to avoid, as it gives the provider a hard time in being able to meet the actual applications expectations. The Pact libraries are also available as command line tools, so they can be language agnostic, if that helps. see https://docs.pact.io/implementation_guides/other_languages

yousafn
2023-09-22 11:39
I see the same pattern play out with UI test suites, being written in different languages than the client apps, and them struggling to gain adoption from others bar the test team authoring them.

doctormiguel
2023-09-22 14:31
has joined #pact-js

abhishek.lamba
2023-09-22 15:36
HI Team, I have short question, For ex: there is one provider which has contract test with 3 consumers. Now for one consumer provider verification fails but its successfully verified the contract for other two consumers , now will can-i-deploy for these 2 consumers will also fail?

felipe.simoes702
2023-09-22 17:37
has joined #pact-js

kgrady
2023-09-22 19:12
Hi there, I?m having an issue with consumer test request headers. After upgrading our nestjs app (a ?Backend For Frontend? and consuming external APIs) to PactV3, a significant amount of the consumer tests are failing. In fact every test that is not a GET is failing with a simple error: ```ERROR (65379): pact@12.1.0: Test failed for the following reasons: Mock server failed with the following mismatches: 0) The following request was incorrect: POST /productentitlements/{exampleID1}/tenants/{exampleID2}``` After doing some digging into the node_modules pact files we were able to console.log out something more helpful: ```console.log mismatches: [ { actual: '', expected: 'application/x.avidxchange.productentitlements+json;version=1.0.0', key: 'Content-Type', mismatch: "Mismatch with header 'Content-Type': Expected value 'application/x.avidxchange.productentitlements+json;version=1.0.0' at index 1 but was missing (actual has 1 value(s))", type: 'HeaderMismatch' } ] at generateMockServerError (../../../node_modules/@pact-foundation/src/v3/display.ts:135:3)``` This implies that our Content-Type is somehow being removed at some point after the test is run. Has anyone seen an issue like this? We tried following the path the headers take through the compiled pact code but were unable to find a place where the Content-Type was removed. One thing to note is that same header is being passed with all requests, including the GETs which are passing. It seems to be something related to requests that contained a body, but I don?t have any evidence to say that?s what it is beyond correlation.

sashi.kandru
2023-09-22 20:17
@yousafn: On a different note, If a provider has 2 consumers, with one using Pact specification v2 and one using v3, does the provider have to write verification tests for both v2 and v3 ?

suat.kose
2023-09-22 22:13
has joined #pact-js

marius.grigoriu
2023-09-23 15:33
has joined #pact-js

noahmcivor
2023-09-24 06:54
has joined #pact-js

matt.fellows
2023-09-24 23:23
Hi Kevin, it sounds like a bug. I did discover an error message bug recently Do you have a repro we can use to see this, or could you share the consumer test and how the HTTP request is sent to help us? https://github.com/pact-foundation/pact-js/issues/1113#issuecomment-1708215909. I wonder if the log message is being impacted by that too

matt.fellows
2023-09-24 23:39
no, the verification process can understand both. As long as the provider SDK supports V3 you should be fine (and the latest Pact JS version does)

abubics
2023-09-25 02:46
Intuitively, if contracts are verified for 2 consumers, they're safe to deploy with that version of the provider.

abubics
2023-09-25 02:47
But if the failed verification consumer is already deployed, and can-i-deploy fails for the provider, it won't be able to deploy a new release until it fulfils all 3 contracts.

marek19922209
2023-09-25 08:09
has joined #pact-js

abhishek.lamba
2023-09-25 09:29
Thanks @abubics.

corey_maynard
2023-09-25 20:07
has joined #pact-js

rammohan_mididoddi
2023-09-25 20:12
has joined #pact-js

kevin
2023-09-26 02:31
has joined #pact-js

michael.lemos1
2023-09-26 12:36
has joined #pact-js

sliu
2023-09-27 00:00
has joined #pact-js

ankush.hasani
2023-09-27 10:01
has joined #pact-js

kai
2023-09-27 15:31
has joined #pact-js

a.monteiro
2023-09-28 09:59
has joined #pact-js

ml210993
2023-09-29 05:12
has joined #pact-js

prempooon.hc
2023-09-29 11:35
has joined #pact-js

jaishankar.nedunchezh
2023-09-29 17:07
has joined #pact-js

devin.woods
2023-09-29 19:28
has joined #pact-js

vittorio.gue
2023-09-30 10:51
has joined #pact-js

honglu11
2023-10-01 16:47
has joined #pact-js

idd90i
2023-10-02 10:37
has joined #pact-js

idd90i
2023-10-02 10:38
Hi guys, do you have some up-to-date example of integration pact with angular application?

matt.fellows
2023-10-02 10:57
Not that I'm aware, there is nothing specific to angular that I'm aware of. Is there something specific you're struggling with?

idd90i
2023-10-02 11:01
Thanks for reply. I just wanted to have full example of how it is integrated in angular app. I mean intial setup settings, for example, how to change angular.json and other files like that. I found few examples in internet, but they are outdated.

matt.fellows
2023-10-02 11:41
Fair enough.

matt.fellows
2023-10-02 11:41
I guess one thing to consider, is that Pact JS is not compatible with Karma (is that still a thing with Angular?). You need to use a NodeJS based test runner (e.g. Jest, Mocha)

idd90i
2023-10-02 12:06
Yes, that is true. Our application uses karma at the moment.

kgrady
2023-10-02 18:30
It might be difficult to share a repro, as it?s part of a large monorepo but I can certainly start with the consumer tests and the HTTP requests. Test file with 2 passing GET tests, 1 failing POST, 1 failing PUT: ```import { HttpModule } from '@nestjs/axios'; import { ConfigModule, ConfigService } from '@nestjs/config'; import { Test } from '@nestjs/testing'; import { PactV3 } from '@pact-foundation/pact'; import { like, regex } from '@pact-foundation/pact/src/dsl/matchers'; import { camelCaseObjectKeys } from '@ui-coe/shared/bff/util'; import { lastValueFrom } from 'rxjs'; import { HttpConfigService } from '../../../services/http-config.service'; import { CreateOrganizationDto, IListWrapperAPI, IOrganizationAPI, OrganizationAddressAPI, UpdateAddressDto, UpdateOrganizationDto, } from '../models'; import { OrganizationService } from './organization.service'; import { PACT_MOCK_SEVER_CONFIG_HOST, PACT_MOCK_SEVER_CONFIG_PORT } from '@ui-coe/shared/bff/types'; const mockProvider = new PactV3({ consumer: 'AvidPay Network', provider: 'Organization.Api', dir: './pact/orgaization/', host: PACT_MOCK_SEVER_CONFIG_HOST, // "127.0.0.1" port: PACT_MOCK_SEVER_CONFIG_PORT, // 65535 }); const requestHeaders = { 'Content-Type': 'application/x.avidxchange.accounting+json;version=1.0.0', Accept: 'application/x.avidxchange.accounting+json;version=1.0.0', Authorization: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIwMHUxMnR5bWNnMHk3OHJUejFkNyIsInRlbmFudElkIjoiY3Zoa3pqMndjZGZjNGlnZWkwcTIiLCJuYmYiOjE2ODE5MTE4MjYsImV4cCI6MTcxMzQ0NzgyNiwiaWF0IjoxNjgxOTExODI2LCJpc3MiOiJBY2NvdW50aW5nQXV0aFNlcnZlciIsImF1ZCI6IkFjY291bnRpbmcifQ.QNcP0fo0fmIm3UQ85tgpQzz6AHlk621JrCtt_XRHLPY', 'x-tenant-id': '7qvmnw5nfupmb6j9gp6m', }; const responseHeaders = { 'Content-Type': regex({ generate: 'application/x.avidxchange.accounting+json;charset=utf-8;version=1.0.0', matcher: 'application\\/x\\.avidxchange\\.accounting\\+json;charset=utf-8;version=([0-9]\\.?){3}', }), }; describe('Organization Service', () => { let service: OrganizationService; const mockServerUrl = `http://${PACT_MOCK_SEVER_CONFIG_HOST}:${PACT_MOCK_SEVER_CONFIG_PORT}`; beforeEach(async () => { const app = await Test.createTestingModule({ imports: [ConfigModule, HttpModule], providers: [ OrganizationService, HttpConfigService, { provide: 'MOCK_ENV', useValue: false, }, { provide: ConfigService, useValue: { get: jest.fn((key: string) => { if (key === 'ACCOUNTING_BASE_URL') return mockServerUrl; }), }, }, ], }).compile(); service = app.get<OrganizationService>(OrganizationService); }); describe('createOrganization', () => { const reqBody: CreateOrganizationDto = { organization_name: 'Stark Industries', organization_code: 'SI', source_system: 'Swagger-UI', }; const returnData: IOrganizationAPI = { organization_id: 'upcd981lg8z84tozng3w', organization_name: 'Stark Industries', organization_code: 'SI', is_active: 'true', created_timestamp: '2023-04-28T00:00:00.000Z', created_by_user_id: '7nsxqpkecdggnk3i1wqj', last_modified_timestamp: '2023-04-28T00:00:00.000Z', last_modified_by_user_id: '7nsxqpkecdggnk3i1wqj', }; it('should return the correct data from POST call', async () => { await mockProvider.addInteraction({ states: [], uponReceiving: 'a request to create an organization', withRequest: { method: 'POST', path: '/accounting/organization', headers: requestHeaders, body: like(reqBody), }, willRespondWith: { status: 201, headers: responseHeaders, body: like(returnData), }, }); await mockProvider.executeTest(async () => { const response = await lastValueFrom(service.createOrganization(requestHeaders, reqBody)); expect(response).toStrictEqual(camelCaseObjectKeys(returnData)); }); }); }); describe('getOrganization', () => { const returnData: IListWrapperAPI<IOrganizationAPI> = { items_requested: 10, items_returned: 10, items_total: 10, offset: 0, items: [], }; it('should return the correct data from GET call', async () => { await mockProvider.addInteraction({ states: [ { description: 'a list of tenants exists', parameters: {}, }, ], uponReceiving: 'a request to get organizations', withRequest: { method: 'GET', path: '/accounting/organization', headers: requestHeaders, }, willRespondWith: { status: 200, headers: responseHeaders, body: like(returnData), }, }); await mockProvider.executeTest(async () => { const response = await lastValueFrom(service.getOrganizations(requestHeaders, {})); expect(response).toStrictEqual(camelCaseObjectKeys(returnData)); }); }); }); describe('getOrganizationById', () => { const id = 'upcd981lg8z84tozng3w'; const returnData: IOrganizationAPI = { organization_id: 'upcd981lg8z84tozng3w', organization_name: 'Stark Industries', organization_code: 'SI', is_active: 'true', created_timestamp: '2023-04-28T00:00:00.000Z', created_by_user_id: '7nsxqpkecdggnk3i1wqj', last_modified_timestamp: '2023-04-28T00:00:00.000Z', last_modified_by_user_id: '7nsxqpkecdggnk3i1wqj', }; it('should return the correct data from getOrganizationById call', async () => { await mockProvider.addInteraction({ states: [ { description: 'a organization exists with id ' + id + '', parameters: { organization_id: id, is_active: 'true' }, }, ], uponReceiving: 'a request to get organizations', withRequest: { method: 'GET', path: '/accounting/organization/' + id, headers: requestHeaders, }, willRespondWith: { status: 200, headers: responseHeaders, body: like(returnData), }, }); await mockProvider.executeTest(async () => { const response = await lastValueFrom(service.getOrganizationById(id, requestHeaders)); expect(response).toStrictEqual(camelCaseObjectKeys(returnData)); }); }); }); describe('updateOrganization', () => { const id = 'upcd981lg8z84tozng3w'; const reqBody: UpdateOrganizationDto = { organization_name: 'New Stark Industries', }; const returnData: IOrganizationAPI = { organization_id: 'upcd981lg8z84tozng3w', organization_name: 'New Stark Industries', organization_code: 'SI', is_active: 'true', created_timestamp: '2023-04-28T00:00:00.000Z', created_by_user_id: '7nsxqpkecdggnk3i1wqj', last_modified_timestamp: '2023-04-28T00:00:00.000Z', last_modified_by_user_id: '7nsxqpkecdggnk3i1wqj', }; it('should return the correct data from PUT call', async () => { await mockProvider.addInteraction({ states: [ { description: 'a organization exists with id ' + id + '', parameters: { organization_id: id, is_active: 'true' }, }, ], uponReceiving: 'a request to update an organization', withRequest: { method: 'PUT', path: '/accounting/organization/' + id, headers: requestHeaders, body: like(reqBody), }, willRespondWith: { status: 200, headers: responseHeaders, body: like(returnData), }, }); await mockProvider.executeTest(async () => { const response = await lastValueFrom( service.updateOrganization(id, requestHeaders, reqBody) ); expect(response).toStrictEqual(camelCaseObjectKeys(returnData)); }); }); }); });```

kgrady
2023-10-02 18:30
Service file with HTTP: ```import { HttpService } from '@nestjs/axios'; import { HttpException, Injectable } from '@nestjs/common'; import { Observable } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; import { camelCaseObjectKeys, snakeCaseObjectKeys } from '@ui-coe/shared/bff/util'; import { IGenericStringObject, IListWrapperAPI } from '@ui-coe/shared/bff/types'; import { HttpConfigService } from '../../../services/http-config.service'; import { busHierErrorMapper } from '../../shared'; import { BusHierError, CreateOrganizationDto, IOrganizationAPI, ListWrapper, Organization, OrganizationAddress, OrganizationAddressAPI, OrganizationList, OrganizationMapped, UpdateAddressDto, UpdateOrganizationDto, } from '../models'; @Injectable() export class OrganizationService { constructor(private http: HttpService, private httpConfigService: HttpConfigService) {} /** * @method createOrganization * @description Create a new Organization * @param headers IGenericStringObject * @param body CreateOrganizationDto * @returns `Observable<Organization | BusHierError>` */ createOrganization( headers: IGenericStringObject, body: CreateOrganizationDto ): Observable<Organization | BusHierError> { return this.http .post(this.httpConfigService.createOrganization(), snakeCaseObjectKeys(body), { headers }) .pipe( map(response => camelCaseObjectKeys<IOrganizationAPI, Organization>(response.data)), catchError(err => { throw new HttpException(busHierErrorMapper(err), err.response?.status); }) ); } /** * @method createOrganizationAddress * @description Get a list of Organizations * @param headers IGenericStringObject * @param query IGenericStringObject * @returns `Observable<OrganizationList>` */ getOrganizations( headers: IGenericStringObject, query: IGenericStringObject ): Observable<OrganizationList> { return this.http .get(this.httpConfigService.getOrganizations(), { headers, params: snakeCaseObjectKeys(query), }) .pipe( map(response => { const camelCaseResponse: ListWrapper<Organization> = camelCaseObjectKeys< IListWrapperAPI<IOrganizationAPI>, ListWrapper<Organization> >(response.data); const items: OrganizationMapped[] = camelCaseResponse.items.map((item: Organization) => ({ organizationId: item.organizationId, organizationName: item.organizationName, organizationCode: item.organizationCode, isActive: item.isActive, })); return { ...camelCaseResponse, items, }; }), catchError(err => { throw new HttpException(busHierErrorMapper(err), err.response?.status); }) ); } /** * @method getOrganizationById * @description Get Organization by Id * @param id string representing the organizationId * @param headers IGenericStringObject * @returns `Observable<Organization>` */ getOrganizationById(id: string, headers: IGenericStringObject): Observable<Organization> { return this.http.get(this.httpConfigService.getOrganizationById(id), { headers }).pipe( map(response => camelCaseObjectKeys<IOrganizationAPI, Organization>(response.data)), catchError(err => { throw new HttpException(busHierErrorMapper(err), err.response?.status); }) ); } /** * @method getOrganizationAddresses * @description Update an Organization * @param id string representing the organizationId * @param headers IGenericStringObject * @param body UpdateOrganizationDto * @returns `Observable<Organization | BusHierError>` */ updateOrganization( id: string, headers: IGenericStringObject, body: UpdateOrganizationDto ): Observable<Organization | BusHierError> { return this.http .put(this.httpConfigService.updateOrganization(id), snakeCaseObjectKeys(body), { headers }) .pipe( map(response => camelCaseObjectKeys<IOrganizationAPI, Organization>(response.data)), catchError(err => { throw new HttpException(busHierErrorMapper(err), err.response?.status); }) ); } }``` The httpConfigService simply determines whether the method will use a local path or not for example: ``` public createOrganization(): string { const config: httpConfig = { path: this.organizationUrl, localPath: '/create-organization.json', }; return this.getPath(config); }```

kgrady
2023-10-02 18:33
Sorry for the wall of text. Let me know if this is sufficient or if you need anything else from me

nathan
2023-10-03 00:43
has joined #pact-js

jonathan.ryding
2023-10-03 12:02
has joined #pact-js

gabe.hollombe
2023-10-04 03:17
has joined #pact-js

pratyusha.boyapati
2023-10-04 08:35
has joined #pact-js

mateusz.socha
2023-10-04 10:41
has joined #pact-js

maja.vitaz
2023-10-05 10:37
has joined #pact-js

martindjk92
2023-10-05 13:05
has joined #pact-js

james814
2023-10-05 20:24
has joined #pact-js

craig.kilpatrick
2023-10-06 00:33
has joined #pact-js

prabakaranplaced
2023-10-06 08:00
has joined #pact-js

likekeys
2023-10-06 14:22
has joined #pact-js

lcruz
2023-10-06 16:07
Hey - I was just about to ask about microfrontends X pact. Admittedly, microfrontends is a completely new term for me. and for context, I'm an EM on a Developer Experience group and one of our tech leads who heads up our frontend architecture team is looking into possible solutions for testing interactions between Frontend modules. > 1. Prescribing a natural way to integrate Contract Tests with FE modules (Imagine: To sub to a channel, you declare your disposition as a provider or consumer, e.g.) Again, I'm not too privy to microfrontends and my only experience with pact is just with testing interactions between services in a monorepo...but I'd imagine that Pact is pretty agnostic of the whether or not something is a frontend; so long as it's a contract between 2 independent services?

chris.odryna
2023-10-06 16:51
has joined #pact-js

rezaur.rahman
2023-10-06 17:39
has joined #pact-js

julie.laursen
2023-10-06 17:43
has joined #pact-js

pratibha.kachi
2023-10-06 20:02
has joined #pact-js

robert579
2023-10-06 20:22
has joined #pact-js

matt.fellows
2023-10-06 23:11
Exactly. I couldn?t tell you implementation wise, but the principle is the same

sbalaranganathan
2023-10-09 12:10
has joined #pact-js

henrik
2023-10-09 18:15
has joined #pact-js

johnkavadias
2023-10-10 09:37
has joined #pact-js

jose-antonio.cano
2023-10-10 16:21
has joined #pact-js

matt.fellows
2023-10-10 23:22
Sorry for missing this Kevin

matt.fellows
2023-10-10 23:28
I can?t reproduce locally, but it could be something I?m not getting right. Could you please modify this test to make it fail in the way that reproduces your problem: https://github.com/pact-foundation/pact-js/blob/repro/x.avidxchange/examples/mocha/test/get-dogs.spec.js If you can reproduce it, please https://github.com/pact-foundation/pact-js/issues so that we can get it fixed

panagiotis.liaros
2023-10-11 10:15
has joined #pact-js

ananya
2023-10-11 10:38
has joined #pact-js

omar.sakka
2023-10-11 14:38
has joined #pact-js

kgrady
2023-10-11 16:54
Thanks for the reply, Matt. I?ll fork this repo and do my best to modify it to replicate. I?ll keep you updated

brandon.king
2023-10-11 18:35
has joined #pact-js

sridhar.nayakwadi
2023-10-11 20:56
has joined #pact-js

saroja.bhogadhi
2023-10-11 20:58
has joined #pact-js

chris.paul
2023-10-12 15:54
has joined #pact-js

ryan.standley
2023-10-12 17:34
has joined #pact-js

joseph
2023-10-12 20:58
has joined #pact-js

laurie.green
2023-10-12 22:46
has joined #pact-js

nikesh1123
2023-10-13 10:32
has joined #pact-js

nikesh1123
2023-10-13 11:01
Hello Guys, I'm facing an issue with *can-i-deploy* in pact and I'm getting this message: > _There is no verified pact between version a85efd3be850cc56a9b of Foo and the latest version of Bar with tag nonprod (2fnrc0bf5a2dafa6e1252e)_ pact-consumer results: ? Consumer -> passing & version is published ? Provider -> Failing with ??? And above error is published that no verified version. The pact-broker version was upgraded from 2.79.1.2 to *2.106.0.0* and this where the error started. We're executing below commands in the pipeline: 1. `npx pact-broker create-or-update-pacticipant --broker-base-url=$PACT_BROKER_URL --broker-username=$PACT_BROKER_USER --broker-password=$PACT_BROKER_PSWD --name=Foo --main-branch=$CURRENT_BRANCH_NAME` 2. `npx pact-broker publish "./pacts/" --broker-base-url=$PACT_BROKER_URL --broker-username=$PACT_BROKER_USER --broker-password=$PACT_BROKER_PSWD --consumer-app-version=$GIT_COMMIT_SHA --branch=$CURRENT_BRANCH_NAME` 3. `npx pact-broker can-i-deploy --broker-base-url=$PACT_BROKER_URL --broker-username=$PACT_BROKER_USER --broker-password=$PACT_BROKER_PSWD --retry-while-unknown=5 --retry-interval=60 --pacticipant=Foo --version=$GIT_COMMIT_SHA --to=nonprod --main-branch --verbose` ```// this is the code for verifying pact provider describe('Foo Provider', () => { test('validates the expectations of API consumers', async () => { const opts = { "providerBaseUrl":"http://localhost:3001/envname", "pactBrokerUrl":"https://my-pact-broker", "pactBrokerUsername":"userName", "pactBrokerPassword":"password", "provider":"Foo", "providerVersion": GIT_COMMIT_SHA, "providerVersionBranch":"pact-testing-branch", "consumerVersionSelectors":[ { "mainBranch":true }, { "matchingBranch":true } ], "publishVerificationResult":true, } await new Verifier(opts).verifyProvider().then((output) => { console.log(output); }); }); }); ``` ```package.json "devDependencies": { "@pact-foundation/pact": "^9.18.1", "@pact-foundation/pact-node": "^10.17.4" }``` Environment: Mac & Windows Any help is appreciated :)

imthu55
2023-10-13 11:05
has joined #pact-js

yousafn
2023-10-13 11:33
you are publishing and verifying with branches but using tags in can i deploy with the to parameter. you probably want to-environment=env_name the can i deploy output it telling you there isn?t a verification against that tag. is there in your matrix?

nikesh1123
2023-10-13 11:49
Thanks, trying build with to-environment. Yes, the matrix shows blank in case of the provider.

dzianis_frydliand
2023-10-13 12:36
has joined #pact-js

nikesh1123
2023-10-13 13:39
After adding to-environment, I am getting the following error: > _There is no verified pact between version 197831453a22289ffa89fc7adf of Foo and a version of Bar currently in nonprod (no version is currently recorded as deployed/released in this environment)_ Tried adding `npx pact-broker record-deployment --pacticipant=Foo --version=$GIT_COMMIT_SHA --environment=nonprod` and still the issue persists.

john.maynard
2023-10-13 14:35
has joined #pact-js

imthu55
2023-10-15 03:05
@yousafn, @bethskurrie Could you please help us with this issue?

cmuddam.testing
2023-10-15 06:46
has joined #pact-js

matt.fellows
2023-10-15 09:53
Please don't directly address maintainers, especially on weekends (probably why you aren't getting nee updates) The thread of conversation is already active. If you want to help, perhaps a view of the matrix to help us understand why can I deploy is failing but why you think it shouldn't. It's highly unlikely it's a bug, so it's likely the data points aren't lining up somehow

david.vadkerti.toth
2023-10-17 08:28
has joined #pact-js

shirley.houter
2023-10-17 08:52
has joined #pact-js

nikesh1123
2023-10-17 13:22
Hello guys, can you please share any approach I can try?

harwin1494
2023-10-17 15:22
Hi team, is there any documentation/sample project available for react-native application?

yousafn
2023-10-17 15:44
you?ve said in your first post you don?t have any provider verification > ? Provider -> Failing with ??? > And above error is published that no verified version. > Yes, the matrix shows blank in case of the provider. With no verifications from your provider, can-i-deploy will never return true

yousafn
2023-10-17 15:44
> perhaps a view of the matrix to help us understand why can I deploy is failing but why you think it shouldn?t. :this:

yousafn
2023-10-17 15:45
I?d recommend https://docs.pactflow.io/docs/workshops/ci-cd/ & https://docs.pact.io/pact_nirvana as exercises to understand how it all fits together

tony.nguyen
2023-10-17 17:03
Hi, has anyone faced these issues? this is the first time we seen these. `One or more of the teardown state change handlers has failed` `Request Failed - One or more of the setup state change handlers has failed`

ruth.kurniawati
2023-10-17 20:02
has joined #pact-js

matt.fellows
2023-10-17 21:42
The problem is some data is not lining up. When you call `can-i-deploy` it looks into the target deploy location (e.g. environment), finds dependencies (e.g. providers), looks at the version of that provider, and then checks if that version of the provider satisfies the needs of the consumer you?re trying to deploy. If the version of the provider in the target is not compatible with the consumer, you?ll get a failure. So, the version of the provider that is deployed is not compatible with the version of the consumer you?re trying to deploy How can that be? 1. There is a genuine problem 2. You haven?t deployed a version of the provider that has verified the contract 3. You are using non deterministic versions (version `abc1` of the provider is what verified the contract, it was then merged and deployed which created a new version `abc2` which has no verification status). This is another reason why each build should verify

matt.fellows
2023-10-17 22:17
What does your logs say around it? I?d expect to see a state handler attempting to execute, but failing. Perhaps set your logs to `debug` and share

matt.fellows
2023-10-17 22:17
Not that I know of. It shouldn?t make a difference, if it?s JS/TS then it should work whether or not it?s a native app or not

balaaji196
2023-10-18 10:46
has joined #pact-js

tony.nguyen
2023-10-18 15:08
this is some of the logs we are seeing ```2023-10-18T15:03:49.520839Z DEBUG ThreadId(02) verify_interaction{interaction="recommend-dataset-keys-for-elements"}: pact_verifier::provider_client: State change request failed with error error sending request for url (http://127.0.0.1:62176/_pactSetup): operation timed out 2023-10-18T15:03:49.521020Z DEBUG ThreadId(02) verify_interaction{interaction="recommend-dataset-keys-for-elements"}: pact_verifier: State Change: "ProviderState { name: "a recommendation can be made", params: {} }" -> Err(Provider state failed: (interaction_id: 66051c9c5088764c2d469d74f855cd957d7d4a7d) Invalid response: error sending request for url (http://127.0.0.1:62176/_pactSetup): operation timed out) 2023-10-18T15:03:49.521042Z ERROR ThreadId(02) verify_interaction{interaction="recommend-dataset-keys-for-elements"}: pact_verifier: Provider setup state change for 'a recommendation can be made' has failed - MismatchResult::Error("Invalid response: error sending request for url (http://127.0.0.1:62176/_pactSetup): operation timed out", Some("66051c9c5088764c2d469d74f855cd957d7d4a7d")) 2023-10-18T15:03:49.848428Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to /pact-version/58527d1d8bd6e127e7e92ccd2feb5450d162b8f5/metadata/c1tdW2xdPXRydWUmc1tdW2N2XT0yMTAw/verification-results using POST: {"providerApplicationVersion":"1","success":false,"testResults":[{"exceptions":[{"message":"One or more of the teardown state change handlers has failed"}],"interactionId":"382004ff8189aa179cedc852efa0e3f5f0096d44","success":false},{"exceptions":[{"message":"One or more of the setup state change handlers has failed"}],"interactionId":"10c1e72196f76471c4ad2979a9a661e57643bb5f","success":false},{"exceptions":[{"message":"One or more of the setup state change handlers has failed"}],"interactionId":"66051c9c5088764c2d469d74f855cd957d7d4a7d","success":false}],"verifiedBy":{"implementation":"Pact-Rust","version":"1.1.11"}}```

mpokala
2023-10-18 20:37
has joined #pact-js

hiroki.gota
2023-10-18 22:26
has joined #pact-js

matt.fellows
2023-10-18 22:35
> ```a recommendation can be made``` looks like that state handler is failing

matt.fellows
2023-10-18 22:35
can you please share the state handler code?

mattisrobin
2023-10-18 22:37
has joined #pact-js

silvimasss
2023-10-18 23:43
has joined #pact-js

sautade
2023-10-19 06:10
I am really struggling to find a good documentation/example of contract tests for asynchronous systems in Typescript/Javascript. Can someone please point me in the right direction please :pray: . *Context:* The consumer I want to contract test is a lambda function (handler) that processes some AWS EvenBridge events and inserts data in dynamoDB. Nothing fancy, pretty standard setup. But all the examples I could find are in Java :sadface: and are not relatable to functions in `pact-js` like `MessageConsumerPact` or `asynchronousBodyHandler`, etc. I am referring to following links: https://dius.com.au/2017/08/22/contract-testing-serverless-and-asynchronous-applications/ https://dius.com.au/2018/10/01/contract-testing-serverless-and-asynchronous-applications-part-2/ I found https://github.com/pactflow/example-consumer-js-snsthat uses SAM and SNS but its not clear to me what part of the pact test in this repo generates the pact json file. May be I am missing something obvious here. Would really appreciate if someone can explain how it generates json contract. Are there any Docs that show how to use MessageConsumerPact with a detailed example?


matt.fellows
2023-10-19 06:13
`receiveProductUpdate` <- thing that processes (consumers) the event


matt.fellows
2023-10-19 06:15
Yousaf ran a workshop last week on this for Pactober: https://youtube.com/live/81N25-4x27E

sautade
2023-10-19 06:32
Thanks for your prompt reply @matt.fellows, as always. That helps. But I find it counter intuitive because in synchronous pact test, calling `verifyProvider` verifies a contract json on provider service, as opposed to generating it on the consumer side. Could be just me though. :stuck_out_tongue: Also the event handler I want to test needs 6 parameters. Do I just pass those in the `asynchronousBodyHandler`? Is there a doc on how to use this method?

sautade
2023-10-19 06:51
let me go through the workshop recording to see if it has a solution for my use case.

matt.fellows
2023-10-19 10:57
Yes, it feels a bit backwards I understand the confusion!

matt.fellows
2023-10-19 10:57
But as you think through it it will make sense. You will need to either create a wrapper for the piece of code that handles the message, or refactor it to be more open to having the raw payload injected as per the example

wanghedi88
2023-10-19 11:16
has joined #pact-js

sautade
2023-10-19 11:33
Thanks @matt.fellows! This is exactly what I needed to know. Much appreciated :pray:

sarah.diendorfer
2023-10-19 12:34
has joined #pact-js

ahmed.elakour
2023-10-19 12:35
has joined #pact-js

parmin.rock
2023-10-19 14:57
has joined #pact-js

victor.yusuf
2023-10-19 14:58
has joined #pact-js

luke.dove
2023-10-19 15:46
has joined #pact-js

lee.andrews
2023-10-19 15:52
has joined #pact-js

mitchellp
2023-10-19 16:06
has joined #pact-js

mickelback00
2023-10-19 22:25
has joined #pact-js

philip.buttinger
2023-10-20 10:36
has joined #pact-js

adrian.kosyra
2023-10-20 11:58
has joined #pact-js

dave.hooson
2023-10-20 15:13
has joined #pact-js

pavankumar.cse88
2023-10-20 17:58
has joined #pact-js

the.m.bjorklund
2023-10-21 21:05
has joined #pact-js

thepiesaresquared
2023-10-22 09:58
has joined #pact-js

vasile.vetisan
2023-10-22 17:50
has joined #pact-js

sartom1994
2023-10-22 18:52
has joined #pact-js

rebecca.fulton
2023-10-23 09:27
has joined #pact-js

joao.jesus
2023-10-23 10:20
has joined #pact-js

kai.moseley
2023-10-23 10:47
has joined #pact-js

gunarajs
2023-10-23 19:23
has joined #pact-js

ctrando
2023-10-23 21:14
has joined #pact-js

thibault.alix
2023-10-23 22:29
has joined #pact-js

kwapisz.bartosz
2023-10-24 08:38
has joined #pact-js

btacca
2023-10-24 12:02
has joined #pact-js

anton.l.petersson
2023-10-24 13:54
has joined #pact-js

jowhalen13
2023-10-24 16:27
has joined #pact-js

charlan.bettiol
2023-10-24 18:49
Hi guys, I'm having a strange problem in my project, when I run my tests locally using yarn test they pass correctly, locally my machine is a macOs, when I go to build on my treadmill which uses a linux alpine node image the following error happens , Has anyone ever experienced this?

charlan.bettiol
2023-10-24 18:49
```[18:42:36.415] ERROR (121): pact-core@14.0.5: Failed to find native module for linux-x64: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel') FAIL test ? Test suite failed to run Failed to load native module, try setting LOG_LEVEL=debug for more info 23 | 24 | describe('The Subscription API', () => { > 25 | const provider = new Pact({ | ^ 26 | dir: path.resolve(process.cwd(), 'pacts'), 27 | spec: 2,```

yousafn
2023-10-24 18:57
Unfortunately Alpine isn?t officially supported in pact-js atm, you?ll need to use a debian based image (with glibc, not musl basically) https://docs.pact.io/docker#alpine-linux There has been some workarounds listed in this thread https://docs.pact.io/implementation_guides/javascript/docs/troubleshooting#unable-to-run-tests-in-alpine-linux but generally not recommended,

charlan.bettiol
2023-10-24 18:57
tks

matt.fellows
2023-10-25 01:51
> when I go to build on my treadmill treadmill, I?ve not seen/heard of this before. Mind sharing a link? (I tried googling but all I got was?treadmills)

matt.fellows
2023-10-25 06:21
Just a quick one Tony, it looks like you raised a PactFlow support ticket for this. If you wouldn?t mind next time popping the ticket # here so we can avoid double handling that would be super helpful. How did you go with the above btw?

tanyagorn.benjaprompa
2023-10-25 08:09
has joined #pact-js

charlan.bettiol
2023-10-25 11:58
In this case, the mat would be the project pipeline where we are using pact, so to build the node application we use the alpine linux image

charlan.bettiol
2023-10-25 12:55
@yousafn i found this image FROM frolvlad/alpine-glibc:latest, this work with pact-js-core

benguizat
2023-10-25 14:04
has joined #pact-js

tony.nguyen
2023-10-25 15:31
@matt.fellows we did with but still have the same error ``` stateHandlers: { "a recommendation can be made for elements": () => { console.log('state totally handled'); return Promise.resolve(); }, }, };```

tony.nguyen
2023-10-25 19:01
also we tried with something like this ```stateHandlers: { "a recommendation can be made for elements": () => { console.log('state totally handled'); return Promise.resolve({includePartialMatches: `1`}); }, },```

tony.nguyen
2023-10-25 20:33
finally got it to somewhat working. However, it is missmatching on the body. ``` recommend-dataset-keys-for-elements (1s loading, 456ms verification) Given a recommendation can be made for elements returns a response which has status code 200 (FAILED) includes headers "content-type" with value "application/json" (OK) has a matching body (FAILED) Failures: 1) Verifying a pact between REPLACE and REPLACE Given a recommendation can be made for elements - recommend-dataset-keys-for-elements 1.1) has a matching body $ -> Actual map is missing the following keys: datasetKeys, elements 1.2) has status code 200 expected 200 but was 400``` I added a filter hoping it would fix but still nothing. ``` stateHandlers: { "a recommendation can be made for elements": () => { console.log('state totally handled'); return Promise.resolve({includePartialMatches: `1`}); }, }, requestFilter: ( req, res, next ) => { res.statusCode = 200; next(); } };```

stan196
2023-10-25 23:42
has joined #pact-js

matt.fellows
2023-10-26 00:45
Thanks Charlan. I?m still confused by the word treadmill in the above - is that a saying for a CI/CD pipeline, a tool or something else (this is purely for my interest)

marekurbanowicz
2023-10-26 06:30
Hi, I am trying to get the dead simple example working, but I don?t get what is wrong. Based on docs it should work, but it does not. The same happens if I do import MatchersV3.

marekurbanowicz
2023-10-26 06:41
it only works with `Matchers` which is import from what I understand - v2 matchers. It does not work for v3 matchers at all.

manalikhanna92
2023-10-26 07:09
has joined #pact-js

aaron_carey
2023-10-26 09:26
has joined #pact-js

ms.maheshhwari
2023-10-26 09:54
has joined #pact-js

ohisproperties2
2023-10-26 16:34
has joined #pact-js

thibault.alix
2023-10-26 18:22
Hi! based on a quick search, there might not be a way to verify an array contains some elements, unless using Pactv4. In which case, how would I go about testing the response contains at least "A", "C" and "D"? Thanks ```{ "_internal": { "entries": [ { "data": { "value": [ "A", "B", "C", "D", "E" ]}}]}}``` ```.willRespondWith(200, (builder) => { builder .jsonBody({ _internal: { entries: [{ data: { value: arrayContaining("A", "C", "D") } }] } })```

anupama_enakula
2023-10-26 21:45
has joined #pact-js

matt.fellows
2023-10-26 21:47
Yes something like that, is it not working as you expected?

matt.fellows
2023-10-26 21:47
And yes, it?s a V4 thing

thibault.alix
2023-10-26 21:59
in the contract, the response looks like: ``` "data": [ null, null, null ]``` and in the matcher section: ```"matchers": [ { "match": "arrayContains", "variants": [ { "index": 0, "rules": {} }, { "index": 1, "rules": {} }, { "index": 2, "rules": {} } ] }``` the producer test is failing with: ```...data -> Variant at index 0 (null) was not found in the actual list ...data -> Variant at index 1 (null) was not found in the actual list ...data -> Variant at index 2 (null) was not found in the actual list```

matt.fellows
2023-10-26 22:02
I think `arrayContaining` accepts an `[]` right?

matt.fellows
2023-10-26 22:03
oh no it?s variadic I think

matt.fellows
2023-10-26 23:20
It might be a type definition/conflict. They look the same, but come from different packages. Thanks for raising the bug

thibault.alix
2023-10-27 03:00
I might schedule a call with our AM to go over this. Also perhaps the test is too value driven as opposed to shape/type driven

matt.fellows
2023-10-27 04:39
It would be best to understand the true use case (I suspect the above was just conceptual)

matt.fellows
2023-10-27 04:39
`arrayContaining` is not an anti-pattern, but usually you can avoid it. You might be right in that it is too shape/type driven


marekurbanowicz
2023-10-27 04:59
I would help with PR, but unfortunately I do not know Pact?s internals enough yet

marekurbanowicz
2023-10-27 05:05
currently it?s blocking our work on Pact introduction to our project :disappointed:

roger.liu
2023-10-27 07:15
has joined #pact-js

matt.fellows
2023-10-27 08:44
Why can?t you just use `Matchers`? If you want it to match exactly, you can actually just skip the matcher altogether

matt.fellows
2023-10-27 08:45
_(it?s only needed within another matcher to reset the matching context)_

marekurbanowicz
2023-10-27 08:45
Matchers are V2 from what I see, so it is somehow limited with the capabilities

matt.fellows
2023-10-27 08:50
what capabilities do you need?

matt.fellows
2023-10-27 08:50
> currently it?s blocking our work on Pact introduction to our project presumably, you could coerce the types into the correct ones as needed. It looks like a TS definition issue, rather than a real problem

marekurbanowicz
2023-10-27 08:51
I bet so, but it has to be fixed at pact?s package to get it working correctly for us(all users)

marekurbanowicz
2023-10-27 08:51
I was trying to figure it out, but I didn?t find it. Really werid as in theory types are matching :confused:

matt.fellows
2023-10-27 08:51
for sure!

marekurbanowicz
2023-10-27 08:52
If I would, I would already issue a PR there

senbaga.kumarsigamani
2023-10-27 16:12
has joined #pact-js

alejandro.ignacio
2023-10-27 17:42
has joined #pact-js

devendra.patil
2023-10-27 21:40
has joined #pact-js

shenkesi.shiva
2023-10-30 06:57
has joined #pact-js

guido.lenacota
2023-10-30 09:48
has joined #pact-js

yihong.wang
2023-10-30 10:01
has joined #pact-js

ruth.bassindale
2023-10-30 20:54
has joined #pact-js

ruth.bassindale
2023-10-30 20:56
@ruth.bassindale has left the channel

sgavathe
2023-10-31 22:00
has joined #pact-js

ntthaibk
2023-11-01 04:36
has joined #pact-js

rskilling
2023-11-01 10:23
has joined #pact-js

victor_do_val
2023-11-01 19:08
has joined #pact-js

james.corry
2023-11-01 19:23
has joined #pact-js

victor_do_val
2023-11-01 20:34
Hi, I was wondering, is it is possible to use pact in a scenario where a child mfe that is in an iframe is sending an event to the parent window with json data?

matt.fellows
2023-11-01 21:02
I guess? How does it send the data? REST?

nicolas.cote-nolin
2023-11-02 12:30
has joined #pact-js

sivaganesh.sivakumar
2023-11-02 13:18
has joined #pact-js

kgrady
2023-11-02 20:57
hey @matt.fellows starting to take a look at those tests. Some key differences here are that we are using PactV3, and using Jest to test as opposed to Mocha/Chai. Would it be alright if I forked our repo and sent you an example version of our code base with the failing Pact tests?

abubics
2023-11-03 07:13
Probably JS callback :think_potato:

id.akanksha26
2023-11-03 11:38
has joined #pact-js

prasant.iragavarapu
2023-11-03 15:06
has joined #pact-js

victor_do_val
2023-11-03 15:15
@abubics is right. It's a JS callback. It's not a REST API call. In fact not really an API at all

yagocre
2023-11-03 22:46
has joined #pact-js

renan.santos
2023-11-05 18:30
Hello everyone! I'm reaching out to seek some guidance on an issue I've encountered with the Pact Broker in relation to our contract tests. Here's what's happening: I've noticed that when running contract tests for my provider microservice, the branch responsible for executing the test isn't displayed in the Pact Broker as expected. Instead of showing the branch name, only the generated UUID is listed, as seen in the screenshot I've attached. Curiously, if I run a single test with Jest, the provider's branch is displayed correctly. However, when executing a full suite of tests, this doesn't seem to work. Could someone assist me in figuring out what might be causing this issue? Is there a parameter I might be missing or incorrectly specifying, or could this be a bug? I'm providing my "pact-provider-setup.ts" file below for reference: ```import { PactProviderModule, PactProviderOptions } from 'nestjs-pact'; import * as dotenv from 'dotenv'; import { generateRandomValue, getCurrentBranch, getGitDirectoryName } from '../helper/utils'; export enum ConsumerName { KK_SHOPPINGCART_SERVICE = 'KK-SHOPPINGCART-SERVICE', KK_PURCHASE_SERVICE = 'KK-PURCHASE-SERVICE' } const DEFAULT_BRANCH = 'master'; const MASTER_WEBHOOK = 'master-webhook'; export const configurePactProvider = (consumer: ConsumerName) => { dotenv.config({ path: './.env.test' }); const GET_PROVIDER_NAME = getGitDirectoryName(); const GET_RANDOM_VALUE = generateRandomValue(); const consumerWebhookBranch = process.env.CONSUMER_VERSION_TAGS; const [GET_CURRENT_BRANCH, GET_PROVIDER_BRANCH] = consumerWebhookBranch ? [consumerWebhookBranch, MASTER_WEBHOOK] : [getCurrentBranch(), getCurrentBranch()]; if (!consumer?.length) { throw new Error( 'Error: PACT_BROKER_BASE_URL environment variable is not set.' ); } const options: PactProviderOptions = { pactBrokerUrl: String(process.env.PACT_BROKER_BASE_URL), provider: GET_PROVIDER_NAME, providerVersion: GET_RANDOM_VALUE, providerVersionBranch: GET_PROVIDER_BRANCH, providerVersionTags: [GET_PROVIDER_BRANCH], logLevel: 'error', consumerVersionSelectors: [ { fallbackTag: DEFAULT_BRANCH, tag: GET_CURRENT_BRANCH, latest: true, consumer: consumer } ], publishVerificationResult: true }; return PactProviderModule.register(options); };``` I'm currently using the following versions and dependencies: ? Node: 16.14.0 ? pact-foundation/pact: 12.1.0 ? nestjs-pact: 2.3.1 ? jest: 28.1.3 ? @types/jest: 29.0.0 ? ts-jest: 28.0.8 Any guidance or suggestions would be greatly appreciated!

renan.santos
2023-11-05 19:49
Here is one of my contract test files: ```describe('Verification', () => { let verifierService: PactVerifierService; let app: INestApplication; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ imports: [ CacheModule.register(), configurePactProvider(ConsumerName.KK_PURCHASE_SERVICE) ], controllers: [OfferController], providers: [ { provide: OfferService, useValue: { readManyOffers: jest .fn() .mockResolvedValue([cartOfferDtoMock]), lockStock: jest .fn() .mockResolvedValue([offerLockStockMock]), unlockStock: jest.fn() } } ] }).compile(); verifierService = module.get(PactVerifierService); app = module.createNestApplication<NestFastifyApplication>( new FastifyAdapter() ); app.useGlobalPipes(new BodyValidationPipe()); await app.init(); }); afterEach(async () => { await app.close(); }); it('Shall validate the expectations', async () => { await verifierService.verify(app); }); });```

yousafn
2023-11-06 10:28
just first look, why are you using random uuids for the application version? that will surely change every time you run the test, even if the provider codebase hasn?t changed

yousafn
2023-11-06 10:31
providerVersionBranch is the correct value to use but it might not be mapped through in nestjs-pact which isn?t particularly up to date. if you run with debug what do you see sent to the broker for the providers parameters ( branch / version / consumer version selectors )

renan.santos
2023-11-06 10:40
Hello, good morning! So, regarding why I used the 'providerVersion', it's because sending it to the broker is mandatory

renan.santos
2023-11-06 10:56
And I've also noticed that when I execute the tests (test suite), one of these tests always sends the current branch, but only for a single test, when executing all 8 tests together. And I've also noticed that if I access "The Matrix" part of these 8 microservices, the branch and tag appear as usual, but in the "dashboard/provider/KK-PRODUCT-SERVICE/consumer/KK-PURCHASE-SERVICE" section they don't appear, as shown in the previous screenshot.

yousafn
2023-11-06 11:54
I am aware providerVersion is mandatory, but it should only change, when your code changes, using a randomly generated number, isn?t going to give you consistent results at all. https://docs.pact.io/getting_started/versioning_in_the_pact_broker#rules

renan.santos
2023-11-06 14:11
I've adjusted my code by creating the `getGitCommitSha()` function, and I passed this function's result to the "providerVersion" property, and everything started working properly. Now, the provider's branch is showing up. :raised_hands: @yousafn Thank you so much for your help and quick response!!

yousafn
2023-11-06 14:35
Happy days! I assume you were getting a different random number for each test and you were only seeing the latest on the matrix (perhaps). I would hope that with our change, our provider version is now deterministic for each test, and will only change when your provider code changes (given that the codebase would publish pacts or verify pacts in CI, when publishing results, and be associated with a commit) versus running on your machine, where you may make a change but your codebase is _dirty_ because the change isn?t committed.

renan.santos
2023-11-06 14:49
I probably should apply the same logic to the command that publishes the pacts for the consumers. Therefore, I would replace this "uuidgen" in the command below with "git rev-parse HEAD," right? `"publish:contract": "pact-broker publish $(sed -n 's/^PACTS_PATH=//p' .env.test) --consumer-app-version=$(uuidgen) --tag-with-git-branch --broker-base-url=$(sed -n 's/^PACT_BROKER_BASE_URL=//p' .env.test)"`

steve.blomeley
2023-11-06 14:50
has joined #pact-js

yousafn
2023-11-06 14:52
oh yeah 110% so, you won?t be able to trace that uuid back to the point in time it was generated from and it will change every time you publish a pact, even if you just re-run your ci build against the same commit on the same branch

yousafn
2023-11-06 14:53
did you get that info from a guide or docs somewhere for using a uuid/random number there? just wondering if we need to mop something up

renan.santos
2023-11-06 15:47
No, the documentation is correct. I think I initially took the uuid/random approach when I was learning how to use the system, and for some reason (which I don?t recall now), it ended up requiring me to update the 'consumer-app-version' every time I published a pact, because it wouldn't allow me to publish saying that the same hash ('consumer-app-version') was already published. But with the way my command is set up now, everything is working fine after I added '--consumer-app-version=$(git rev-parse HEAD)'. It allows me to run the same command with the same hash ('consumer-app-version'), and everything is correct with the change here; I've already tested it.

ndomingues10
2023-11-07 10:14
has joined #pact-js

nswetha.reddy
2023-11-07 19:21
has joined #pact-js

aparnakrishna1115
2023-11-08 14:55
has joined #pact-js

harry.talbot
2023-11-08 15:05
has joined #pact-js

daniel.phillips
2023-11-08 17:18
has joined #pact-js

yuliya.rahalski
2023-11-08 20:15
has joined #pact-js

olivier.picaud
2023-11-08 21:51
has joined #pact-js

joseenrique.garcia
2023-11-09 12:56
has joined #pact-js

ashish.patel5
2023-11-09 15:20
has joined #pact-js

jowhalen13
2023-11-09 16:48
How do I view the actual full response headers and body when doing a pact verification? The console logs in the `Verifier` callback don't actually print when there's a failure, so how do I inspect the results? ```import { Verifier } from '@pact-foundation/pact' const { API_URL, PACTFLOW_TOKEN } = process.env const opts = { providerBaseUrl: API_URL, pactBrokerUrl: 'https://my-pactflow.pactflow.io/', pactBrokerToken: PACTFLOW_TOKEN, provider: 'normalizer', consumerVersionTags: ['v2'], providerVersionTags: ['v1'], providerVersionBranch: 'my-branch', providerVersion: 'v1' } console.log(opts) new Verifier(opts).verifyProvider().then(output => { console.log('Verify provider function') console.log(output) })```

jowhalen13
2023-11-09 16:55
ah I figured this out by using the `requestFilter` middleware to access the response ``` requestFilter: (req, res) => { console.log(res) }```

jowhalen13
2023-11-09 17:07
ok so two things: 1. the response body is a huge object that I don't know what to make sense of; looks nothing like what my provider actually sends 2. by simply adding this `requestFilter` function, my verification test breaks in a different way with the error `Request Failed - One or more of the setup state change handlers has failed` How do you all deal with this?

matt.fellows
2023-11-09 22:20
Hey Joel! ok, a few things. 1. the request filter is not really meant for logging. If you do use it, there is a third argument to the fn called `next` which needs to be called as the last thing i.e. `next()` (it?s actually just a standard Express middleware, so it needs to return. This is why your state change handlers are failing. See https://github.com/pact-foundation/pact-js/blob/master/docs/provider.md#modify-requests-prior-to-verification-request-filters 2. the `new Verifier(opts).verifyProvider().then(?` is a promise - this looks to be dangling (i.e. unhandled), and so it seems possible the test is finishing before the verification can report problems back

matt.fellows
2023-11-09 22:21
Problems should be properly reported and printed to console otherwise

matt.fellows
2023-11-09 22:21
Lastly, you could set the `logLevel` property to `DEBUG` (or perhaps `TRACE`) and see all of the gory detail

jowhalen13
2023-11-09 22:21
Thank you, I'll try this when I get home later tonight

jowhalen13
2023-11-09 22:22
Ah that's the string that logLevel field needed. Ok cool

matt.fellows
2023-11-09 22:23
Are you using JS or typescript? Even if using JS, most editors will show you the types available to the verifier

jowhalen13
2023-11-09 22:24
Typescript. For some reason my vscode IDE just says it's string type

cnguyen
2023-11-10 08:31
has joined #pact-js

nam.nguyen414
2023-11-10 12:35
has joined #pact-js

jowhalen13
2023-11-10 15:18
alright that worked! Thank you. I'm still trying to understand the the actual sent request/response pairs, and printing doesn't seem to be helping. The entire `res` or `req` objects are *huge* and don't seem to contain the headers or body detailed in the pact. For example, these are my print statements ``` requestFilter: (req, res, next) => { req.headers['Authorization'] = `Bearer ${jwtGenerator()}` console.log(req.headers) console.log(req.body) next() },``` but the `req.body` isn't what I'm expecting at all (it should be an address object) ```{ 'content-type': 'application/json', accept: '*/*', 'accept-encoding': 'gzip, deflate', host: '127.0.0.1:34111', 'content-length': '76', Authorization: 'Bearer my-correct-token-here' } { action: 'teardown', params: {}, state: 'I am able to normalize addresses' }```

jowhalen13
2023-11-10 15:23
I guess what I'm looking for is a better log than the test output ```1) Verifying a pact between flow-controller and normalizer Given I am able to normalize addresses - a request to normalize an address 1.1) has a matching body / -> Expected body Present(1698 bytes) but was empty 1.2) has status code 200 expected 200 but was 204 1.3) includes header 'Accept' with value '"application/json"' Expected header 'Accept' to have value '"application/json"' but was '' Expected header 'Content-Type' to have value '"application/json"' but was ''``` I'd like to see the full response to figure out why it returned 204, especially since when I open up my running server logs I don't see a 204 status code anywhere, just 401 unauthorized

jowhalen13
2023-11-10 15:24
OHHH there are multiple `req` and `res` objects... I was looking at the wrong one. Ok slowly starting to wrap my head around this....

lewis
2023-11-10 16:33
has joined #pact-js

anna.lorenzi
2023-11-10 17:42
has joined #pact-js

nathan334
2023-11-10 18:34
has joined #pact-js

matt.fellows
2023-11-13 01:20
Yes, it?s middleware. There is actually a separate set of calls (provider states) that you might be first seeing, followed by the actual calls to your API. It?s a really advanced feature that is for edge cases.

matt.fellows
2023-11-13 01:21
> I?d like to see the full response to figure out why it returned 204, especially since when I open up my running server logs I don?t see a 204 status code anywhere, just 401 unauthorized hmm perhaps it?s `TRACE` logs that log the full request/response.

matt.fellows
2023-11-13 01:27
Jus checked, you should be seeing something like this when set to `debug`: ```[12:26:29.534] DEBUG (99705): pact@11.0.2: incoming request: {"body":{},"headers":{"accept":"text/plain","authorization":"Bearer token","accept-encoding":"gzip, deflate","host":"127.0.0.1:50430"},"method":"GET","path":"/animals/100"} Middleware invoked before provider API - injecting Authorization token [12:26:29.536] DEBUG (99705): pact@11.0.2: Proxying GET: /animals/100 [12:26:29.544] DEBUG (99705): pact@11.0.2: outgoing response: {"body":"id=100;first_name=Nanny;last_name=Doe;animal=goat","headers":{"x-powered-by":"Express","access-control-allow-origin":"*","content-type":"text/plain; charset=utf-8","date":"Mon, 13 Nov 2023 01:26:29 GMT","connection":"close","content-length":"49"},"status":200}```

jowhalen13
2023-11-13 20:10
yes, the trace log helped a ton! Thanks, I figured out the issue with the 204 error, my request was just incorrect for our use case. Fixed it.

jowhalen13
2023-11-13 20:14
Of course I'm having another issue though - I've changed the pact version tags and am getting ```2023-11-13T20:12:39.610158Z INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/pacts/provider/normalizer/for-verification' from pact broker 2023-11-13T20:12:40.250435Z ERROR ThreadId(11) pact_verifier: No pacts found matching the given consumer version selectors in pact broker 'https://my-broker.pactflow.io/': Link/Resource was not found - No pacts were found for this provider``` In the broker, the consumer version has been published as `1.0.0`, and my verification looks like this ```new Verifier({ providerBaseUrl: API_URL, pactBrokerUrl: 'https://my-broker.pactflow.io/', pactBrokerToken: PACTFLOW_TOKEN, provider: 'normalizer', consumerVersionTags: ['1.0.0'], providerVersionTags: ['v1'], providerVersionBranch: 'my-branch', providerVersion: 'v1', // logLevel: 'trace', //@ts-ignore requestFilter: (req, res, next) => { req.headers['Authorization'] = `Bearer ${jwtGenerator()}` console.log(res.statusCode) console.log(req.headers) next() } }) .verifyProvider() .then(output => { console.log('Verify provider function') console.log(output) })``` Did I specify the `consumerVersionTags` list incorrectly?

matt.fellows
2023-11-13 21:06
This should be one ore more _tags_ associated with a consumer, not the version of the consumer (hence why it?s not finding it, because there are no tags for that consumer) ```consumerVersionTags: ['1.0.0'],``` Similarly, this should be one ore more _tags_ to apply to the provider _version (_which is _`v1`)_ upon verification. It would then tag it as `v1` as well, which is probably not what you want ```providerVersionTags: ['v1'],``` You should be avoiding tags though and using branches/environments/releases instead: ? https://docs.pact.io/pact_broker/branches ? https://docs.pact.io/pact_broker/recording_deployments_and_releases

jowhalen13
2023-11-13 21:07
Ahh ok so it needs the tag not the version, I see. I was following the docs for publishing to the broker and it had omitted the tag argument. I'll re add it

matt.fellows
2023-11-13 21:08
yep, I?d avoid tags altogether though if you?re starting fresh. They are the ?old? way of doing this.

jowhalen13
2023-11-13 21:09
Oh then how do I get verification to work without a consumer tag?

jowhalen13
2023-11-13 21:09
Is there a branch option for verification?

matt.fellows
2023-11-13 21:14
(I?ll update this. I can see this is out of date, or at least implies that tags is the way to go: https://github.com/pact-foundation/pact-js/blob/master/docs/provider.md#verification-options)


jowhalen13
2023-11-13 21:19
Awesome this looks much nicer

mvliannoi
2023-11-14 12:14
Greetings! I'm wondering if we have a dedicated approach for writing Pact contract tests with Vitest instead of using Jest? It would also be nice to know if anyone already tried to migrate existing tests from Jest (using the `jest-pact` adapter) to Vitest

yousafn
2023-11-14 12:37
I don?t really use jest-pact anymore as due to different lifecycle methods with the new rust based core, the experience with vanilla pact-js and jest is decent enough. some reported issues with vitest, you can search via pact-js issues. I have an example I tried out last week https://github.com/YOU54F/vscode-pact-snippets/pull/2/files there is no reason pact-js shouldn?t work with any javascript test runner, so best attempting it and seeing how far you get, and reporting if there are any issues. There are too many test frameworks for us to test and keep up to date with them all, so end users feedback from actually trying it out is best

jowhalen13
2023-11-14 15:06
I must be missing something. I published the consumer with the `--branch=main` property, but still getting this failure on verification ```2023-11-14T15:05:11.303680Z INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/' from pact broker 2023-11-14T15:05:12.241720Z INFO ThreadId(11) pact_verifier::pact_broker: Fetching path '/pacts/provider/normalizer/for-verification' from pact broker 2023-11-14T15:05:13.544083Z INFO ThreadId(11) pact_verifier::pact_broker: error response for pacts for verification: failed validation - ["consumerVersionSelectors: must specify a value for environment or tag or branch, or specify mainBranch=true, matchingBranch=true, latest=true, deployed=true, released=true or deployedOrReleased=true (at index 2)"] 2023-11-14T15:05:13.544474Z ERROR ThreadId(11) pact_verifier: No pacts found matching the given consumer version selectors in pact broker 'https://updaterinc.pactflow.io/': failed validation - ["consumerVersionSelectors: must specify a value for environment or tag or branch, or specify mainBranch=true, matchingBranch=true, latest=true, deployed=true, released=true or deployedOrReleased=true (at index 2)"] 2023-11-14T15:05:13.544587Z ERROR ThreadId(11) pact_verifier: Failed to load pact - No pacts found matching the given consumer version selectors in pact broker 'https://updaterinc.pactflow.io/'``` The error message is saying to setup my consumerVersionSelectors, but I have, and they look like this ``` consumerVersionSelectors: [ { mainBranch: true }, { matchingBranch: true }, { consumer: 'flow-controller' }, { branch: 'main' } ]```

matt.fellows
2023-11-14 22:11
is `providerBranch` set (on the `VerifierOptions` type)? I think possibly, `matchingBranch` validation is failing because it doesn?t know the provider?s branch. We could possibly improve the client side validation in this case (and also the error message coming from the broker, which isn?t helpful in this case)

banghung859
2023-11-15 08:38
has joined #pact-js

jowhalen13
2023-11-15 14:33
Oh I had `providerVersionBranch` set. Ok so I set `providerBranch` but still getting the same error

jowhalen13
2023-11-15 15:08
good news I was able to get verification to work just by hard copying over the pactfile, so that's a good step. Just want to make this work with the pact broker so I can start setting up CI

jowhalen13
2023-11-15 15:35
finally got the broker to work; I had to delete mainBranch, matchingBranch, and consumer options from the `consumerVersionSelectors` object ```{ providerBaseUrl: API_URL, pactBrokerUrl: 'https://updaterinc.pactflow.io/', pactBrokerToken: PACTFLOW_TOKEN, // pactUrls: ['./src/flow-controller-normalizer.json'], provider: 'normalizer', providerVersionBranch: 'UCS-779-verify-normalizer', providerVersion: '8edfcd4984a01a823b0b56e5ee8c306d847751e0', consumerVersionSelectors: [ // { mainBranch: true }, // { matchingBranch: true }, // { consumer: 'flow-controller' }, { branch: 'main' } ], //@ts-ignore requestFilter: (req, res, next) => { req.headers['Authorization'] = `Bearer ${jwtGenerator()}` next() } }```

matt.fellows
2023-11-15 22:45
hmm strange that `mainBranch` doesn?t work :thinking_face:

matt.fellows
2023-11-15 22:47
Sorry about the confusion, you?re right with `providerVersionBranch`. Either should work though

jowhalen13
2023-11-15 23:06
What file are those comments located in? I followed the type defs but there were no comments like that


jowhalen13
2023-11-16 00:14
how do you guys handle `consumer-app-version` in ci? I thought if I had the `--branch` flag I wouldn't need to use this? ```No value provided for required options '--consumer-app-version'```

jowhalen13
2023-11-16 00:14
we don't do semantic versioning so could I just make up a hardcoded string here?

jowhalen13
2023-11-16 00:15
ohhh this should be git sha, nevermind that will work

ali
2023-11-16 04:50
has joined #pact-js

matt.fellows
2023-11-16 06:28
`branch` is more to indicate the feature/line of work happening. The version is extremely important, because that uniquely identifies the piece of software that is being changed/deployed/verified etc.

emmanuel
2023-11-16 09:40
has joined #pact-js

dan.corder
2023-11-16 11:37
has joined #pact-js

vikash.kumar.singh
2023-11-16 22:58
has joined #pact-js

barbara.szczygiel
2023-11-17 14:08
has joined #pact-js

maria.olivero
2023-11-17 16:57
has joined #pact-js

anna.lorenzi
2023-11-17 18:22
Hi all, I am attempting to run my tests with Jest. When I run then on windows, everything works fine. However, when I run the tests inside a docker linux container, I encounter some issues. The dockerfile to create a container is as follows: ```FROM node:19 RUN apt-get update -y && \ apt-get install -y git g++ python3 build-essential && \ rm -rf /var/lib/apt/lists/* RUN apt-get install -y bash CMD ["bash"]``` To run this container, I create a volume to acces the react app code from within container: ```wsl docker run -it -v /mnt/c/source/my-project:/src my-project-test:my-project-test``` After that, I attempt to run tests with Jest inside the container: ```jest --testPathPattern "/src/services" --env=jsdom``` However, it is not work. With debian and ubuntu the bash stays frozen for hours (see image bellow). Could someone help me, please?

anna.lorenzi
2023-11-17 18:26
To provide better context, the image will be shared among many teams to create GitLab pipelines. Once the container is allocated, a script to run tests will be executed.

vittorio.gue
2023-11-17 20:23
Hi @anna.lorenzi , i dont know what would cause it but I have a couple of ideas to find out more answer. Have you tried running any other jest tests inside the container? Basically reduce the scope of your problem until you find where the problem lives. Jest should also have a verbose option

matt.fellows
2023-11-19 00:58
Note if you volume mount a windows volume into a Linux container any node modules will need to be reinstalled, because any that require native compilation etc won't work. I like Vittorio's advice though. Remove pact from the test - does that work?

madhawa
2023-11-21 04:59
has joined #pact-js

pascal
2023-11-21 05:25
has joined #pact-js

srinu.innovatus
2023-11-21 08:09
has joined #pact-js

somya.khandelwal
2023-11-21 08:39
has joined #pact-js

daniel.phillips
2023-11-21 11:56
Hi there, what would be recommended for the following scenario? I am writing a PACT for an API call which retrieves information related to a footer, I want to ensure that it has at most 2 rows of data, each row can contain 4 columns. Each item within a column can be of varying data structures so using a like matcher is not fit for purpose, instead I am using `arrayContaining`. I can constrain the outer array (rows) however I cannot constrain the inner columns array. (If I use a `constainedArrayLike`, this implies that the `items` must appear in every single column, which they do not. (See inline comment in code below). ```body: constrainedArrayLike( arrayContaining({ # Cannot constrain here, but must use arrayContaining to allow the below state.structure to appear in at least one of the columns. Using any other constained matcher implies it must appear in all columns columnAlignment: like('left'), items: arrayContaining(like(state.structure)), }), MIN_ALLOWED_ROWS, MAX_ALLOWED_ROWS, // At most MAX_ALLOWED_ROWS can be included in the response ),```

matt.fellows
2023-11-21 12:17
So are you saying a data structure like this? ```[ {"a": 1, "b": "string", "c": true, "d": null}, // allows four columns {"a": {/* object allowed?*/}, "b": "string"} // only two columns ]``` Is the limitation on rows a constraint of your consumer or provider? i.e. what would happen if you got more than 2 rows? 0 rows? _(I?m trying to understand if this is a functional test, and potentially a test that is too constraining on the provider)_

daniel.phillips
2023-11-21 12:36
Thanks for getting back to me @matt.fellows! Here is an example of what the JSON response may look like. ```[ # Array size of 2 at most [ # Array size of 4 at most { "columnAlignment": "left", "items": [ { "type": "structure1", "attribute": "value", "attribute": "value" }, { "type": "structure2", "attribute": "value", }, { "type": "structure3", "attribute": "value", "attribute": "value" "attribute": "value" }, ] }, { "columnAlignment": "left", "items": [ { "type": "structure4", "attribute": "value", }, ] }, { "columnAlignment": "left", "items": [ { "type": "structure1", "attribute": "value", "attribute": "value" }, { "type": "structure4", "attribute": "value", }, ] } ] ]``` I'd say the limitation is on our (the consumer) side, we will build our application against the 2x4 grid, any more and it may not display content properly, violate WCAG guidelines etc. The provider will not be developing their API for another few months, so yes we're purposefully being constraining on the provider (happy to be challenged on this if I'm thinking about this in the wrong way). So using the above, let's say I want to ensure that `when a footer exists which contains the structure4 type,` what would you recommend? It doesn't exist in the first column, only 2 & 3 (which is fine), all I'm really wanting to test here is that it's structure of the entire response is the 2x4 grid and my `structure4` json object is somewhere and matches it's required structure

aniket.rane
2023-11-22 03:06
Hello all. Question here. We are trying to install a pact-js for our project that is using node 12. Unfortunately the Node version supported by latest pact-js version is Node 16. For previous pact-js version, github has a note saying: (https://github.com/pact-foundation/pact-js#requirements) _*make sure the ignore-scripts option is disabled...*_ So what does that mean? do I run the command as `npm i @pact-foundation/pact@11.0.2 --ignore-scripts` or I do something like: `npm config set ignore-scripts false` `npm i @pact-foundation/pact@11.0.2`

matt.fellows
2023-11-22 04:29
It just means you shouldn't use the option to disable scripts. I.e. install in the usual way

ndruzhinina
2023-11-22 14:25
has joined #pact-js

jaspal.puri
2023-11-23 10:05
has joined #pact-js

ogbofjnr
2023-11-23 12:25
has joined #pact-js

patricio.dossantos_sl
2023-11-23 20:08
has joined #pact-js

martin.gallauner
2023-11-24 10:40
has joined #pact-js

aschaff
2023-11-24 15:27
has joined #pact-js

bruno.petkovic99
2023-11-25 13:55
has joined #pact-js

carlrconn
2023-11-27 02:22
has joined #pact-js

yi.wu
2023-11-27 08:10
has joined #pact-js

brian_worsham
2023-11-27 14:30
has joined #pact-js

jessie.eteng
2023-11-27 15:25
has joined #pact-js

crisciano.botelho
2023-11-27 18:57
has joined #pact-js

ajg.public
2023-11-27 21:44
has joined #pact-js

lukasz.lawicki
2023-11-28 10:06
has joined #pact-js

jawad.sefiani
2023-11-28 14:08
has joined #pact-js

jawad.sefiani
2023-11-28 14:21
Hey guys, I'm having trouble writing a Pact consumer test using form data. The form data object includes a file and some metadata. Example: ```const formData = new FormData(); formData.append( 'meta', JSON.stringify({ some_key: "some_value", }), ); formData.append('file', createFile()); provider .given('I have file with more than 1000 values') .uponReceiving('a request to create a rule using a file with more than 1000 values') .withRequest({ method: 'POST', path: '/rules', body: formData, headers: { 'Content-Type': 'multipart/form-data', }, }) .willRespondWith({ status: 201, body: mockedResponse, contentType: 'application/json', }); return provider.executeTest(async (mockServer) => { http://axiosInstance.post("/rules", formData, { baseURL: mockServer.url, headers: { 'Content-Type': 'multipart/form-data', }, }) // some assertion });``` I'm getting the following error: ``` Mock server failed with the following mismatches: 0) The following request was incorrect: POST /rules 1.0 Mismatch with header 'Content-Type': Expected value 'multipart/form-data' at index 1 but was missing (actual has 1 value(s)) 1.1 Expected a body of 'application/json' but the actual content type was 'multipart/form-data;boundary=--------------------------087154011299288967847178'``` Axios adds this annoying boundary value to the content type but Pact doesn't know about this value. How can I solve this?

elaine.silva
2023-11-28 17:50
has joined #pact-js

jawad.sefiani
2023-11-28 20:18
Btw I also tried using the native fetch API, didn't work either. For some reason it adds the multipart/form-data content type twice :sweat_smile: Here is the error: ```Mock server failed with the following mismatches: 0) The following request was expected but not received: Method: POST Path: /rules Headers: Content-Type: multipart/form-data;, multipart/form-data; Body: {}... (2 length)```

jawad.sefiani
2023-11-28 23:02
I created a ticket with a reproducible example :pray: https://github.com/pact-foundation/pact-js/issues/1140

tomasz.myszka
2023-11-29 14:21
has joined #pact-js

tom.willmott944
2023-11-29 14:44
has joined #pact-js

anna.nava
2023-11-29 20:56
has joined #pact-js

pasc.ther
2023-11-29 22:19
has joined #pact-js

matt.fellows
2023-11-29 23:34
Thanks for raising it. I think what is required is to build up the body manually, but axios doesn?t seem to provide a way to introspect the boundary.

matt.fellows
2023-11-29 23:34
I wonder if we could improve the matching so that we can ignore the boundaries as they seem to be dynamic

awade
2023-11-30 13:49
has joined #pact-js

aniket.rane
2023-11-30 22:29
One of our services (consumer) is still using Node 12 (and we plan to upgrade soon), However, meanwhile I want to implement contract tests for it. Is `@pact-foundation/pact@9.18.1` my best option for now?

matt.fellows
2023-11-30 23:35
Yes, I think the latest in the 9.x.x range is your best bet

vspallas
2023-12-03 10:18
has joined #pact-js

nicholaspatrickshaw
2023-12-04 10:32
has joined #pact-js

malvine.logina
2023-12-04 11:52
has joined #pact-js

renan.santos
2023-12-04 15:51
Hello everyone, Does anyone know if it's possible for a consumer to publish to the pactBroker with two possibilities for "withRequest" and "willRespondWith" for the same route? The rest of the request structure is the same for both, with the only difference being that there could be two distinct forms for the request body and response body. Below is my consumer-side test script: ```dotenv.config({ path: './.env.test' }); const port = getAvailablePort(); const API_BASE_URL = `${process.env.BASE_URL_AXIOS_REQUEST}:${port}`; const ACCEPT_HEADER = { 'Content-Type': 'application/json' }; const pact = new PactV3({ consumer: 'KK-CHECKOUT-SERVICE', provider: 'KK-PAYMENT-SERVICE', port: port, dir: path.resolve(process.cwd(), String(process.env.PACTS_PATH)), logLevel: 'error' }); const mockData = { paymentMethodDtoMock: applyMatchersToDto(paymentMethodDtoMock) }; describe('KK-CHECKOUT-SERVICE consuming from KK-PAYMENT-SERVICE', () => { const PAYMENT_METHOD_PATH = '/payment-methods/checkout'; describe(`POST - ${PAYMENT_METHOD_PATH}`, () => { it('Should create a new payment method into checkout', async () => { pact.uponReceiving(`post - ${PAYMENT_METHOD_PATH}`) .withRequest({ method: 'POST', path: PAYMENT_METHOD_PATH, headers: ACCEPT_HEADER, body: eligiblePaymentMethodsDtoRequestMock }) .willRespondWith({ status: 201, headers: ACCEPT_HEADER, body: [mockData.paymentMethodDtoMock] }); return pact.executeTest(async () => { const response = await http://axios.post( `${API_BASE_URL}${PAYMENT_METHOD_PATH}`, eligiblePaymentMethodsDtoRequestMock, { headers: ACCEPT_HEADER } ); expect(response.status).toEqual(201); }); }); }); });```

joshua.ellis
2023-12-04 22:49
You certainly can have multiple `withRequest` and `willRespondWith` for the same route. You typically need to have some other differentiator though (e.g., one might be a `POST` and another a `GET`; or there may be different provider states, set `GET /user/1` might respond with a `200` or a `404`). This Pact-JS example might be helpful if you haven't seen it: https://github.com/pact-foundation/pact-js/blob/eb3110c0785f861c9befbcff354886eb37328dc8/examples/e2e/test/consumer.spec.js#L113-L156

matt.fellows
2023-12-05 02:56
Exactly. Generally speaking, you would differentiate with the scenario name (description), provider state(s) and response codes/bodies.

matt.fellows
2023-12-05 02:57
When writing Pact tests, it?s good to think of a ?given/when/then? / BDD style, as it makes the scenario meanings clearer

vinicius.gabriel
2023-12-05 13:59
has joined #pact-js

stasiekps
2023-12-05 15:13
has joined #pact-js

antal.tettinger
2023-12-05 15:50
has joined #pact-js

archaanaaa8
2023-12-06 07:19
has joined #pact-js

visaliparimi
2023-12-06 10:03
has joined #pact-js

indrani.r
2023-12-06 10:06
has joined #pact-js

frank.weitmann
2023-12-06 10:23
has joined #pact-js

venketeshvenky
2023-12-06 10:40
has joined #pact-js

jawad.sefiani
2023-12-06 10:59
Yeah, indeed, would be helpful, but even with the browser's native fetch, I am having issues.

kyle.r.shrader
2023-12-07 01:33
has joined #pact-js

matt.fellows
2023-12-07 05:14
You would need to know in advance of the Pact test what the name of the boundary is, and include that in the `body` expectation.

ajay991610
2023-12-07 05:27
has joined #pact-js

marko.stevanovic
2023-12-07 10:01
has joined #pact-js

mahesh.manglani
2023-12-07 16:49
has joined #pact-js

gerard.molina
2023-12-07 17:00
has joined #pact-js

boyd.social
2023-12-07 17:52
has joined #pact-js

muhd_syamil.dzulkafta
2023-12-08 05:47
has joined #pact-js

omer.sucu
2023-12-08 10:04
has joined #pact-js

hermoine807
2023-12-08 12:04
has joined #pact-js

blake.norrish
2023-12-08 17:05
has joined #pact-js

robert.jelic
2023-12-10 23:02
has joined #pact-js

pragna.reddy
2023-12-11 11:32
has joined #pact-js

oguzhannvarol
2023-12-11 14:13
has joined #pact-js

ryan.quinn
2023-12-11 17:57
has joined #pact-js

arnon
2023-12-12 09:01
has joined #pact-js

lewis.blackwood
2023-12-12 14:04
has joined #pact-js

ilie.cotiuga
2023-12-12 14:26
has joined #pact-js

remyjaume
2023-12-12 15:46
has joined #pact-js

amelie.frappier
2023-12-12 18:55
has joined #pact-js

flament.thom
2023-12-12 20:43
has joined #pact-js

ckbisk
2023-12-12 22:18
has joined #pact-js

sterankin
2023-12-13 10:57
has joined #pact-js

shane.bogdan
2023-12-13 12:06
has joined #pact-js

luis.nuno
2023-12-13 18:08
has joined #pact-js

raleigh.schickel
2023-12-13 23:15
has joined #pact-js


thibault.alix
2023-12-14 20:18
Hi! In a provider test, what could be the reason using `mainBranch: true` triggers an error (No pacts found matching the given consumer version selectors in pact broker xxx), and `latest: true` doesn't? The consumer publishes contracts in feature branches as well as in `main` ; we've also confirmed the participant's details `Main Branch: main` thank you

thibault.alix
2023-12-14 20:34
using `mainBranch:true` in conjunction of `deployed: true` seems to work in some cases: ? ConsA <> ProvA: :white_check_mark: ? ConsA <> ProvB: :x:

matt.fellows
2023-12-15 00:52
The main branch is for selecting contracts that match the _consumer_?s main branch. If a consumer hasn?t published a contract for its main branch, that would likely be the reason

thibault.alix
2023-12-15 02:07
the weird thing is that the consumer is publishing contracts to the main branch... Could this also be related to marking contracts are deployed/released or not? I've deleted all the contracts and restarted from scratch, I'll check within the next couple of days as PRs get pushed from all services.

matt.fellows
2023-12-15 02:10
If you set logs to verbose, we should be able to see the calls to the broker and why it isn?t finding anything

hataipat.sup
2023-12-15 05:26
has joined #pact-js

hakan.dilaver
2023-12-15 13:54
has joined #pact-js

kyle.r.shrader
2023-12-15 18:43
Can I do value matching on a map in V4 pact-js with pact-jest? I mean, does V4 have something like this: `MatchersV3.eachValueMatches` Or, can I use this in a v4 pactWith?

kyle.r.shrader
2023-12-15 18:48
I saw a builder method in an example that used the chained syntax approach to pass a builder function. But that function isn't available in v4 and the MatchersV3.eachValueMatches doesn't pass type checking in V4.

matt.fellows
2023-12-16 02:06
It should work with the V4 builder. What error are you getting?

kyle.r.shrader
2023-12-16 02:12
I had type issues. The matcher is not of type AnyMatcher, or whatever the union matcher type's name is. (I'm away from work pc atm)

kyle.r.shrader
2023-12-16 02:16
I am using pact-jest's v4 pactWith function. Then in beforeEach calling provider.addInteraction (provider being the Pact from pactWith). The example I saw uses ```.addInteraction() .... .withResponse(200, (builder)=>{})``` But I suspect that's v3 pactWith, while v4's addInteraction only accepts an object for body.

kyle.r.shrader
2023-12-16 04:28
Failing approach using v4 pactWith: ```import { Matchers, MatchersV3 } from '@pact-foundation/pact' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { render } from '@testing-library/react' import { pactWith } from 'jest-pact' import FilterPane from '@/modules/properties/filtering/FilterPane' const queryClient = new QueryClient() const originalFetch = fetch pactWith( { consumer: 'environment-comparison-application', provider: 'environment-comparison-service', }, (provider) => { beforeAll(() => { const { port } = provider.opts jest.spyOn(global, 'fetch').mockImplementation((input, init) => { const url = typeof input === 'string' ? input : (input as Request).url if (url.startsWith('/api')) { return originalFetch(`http://localhost:${port}${input}`, init) } return originalFetch(input, init) }) }) afterAll(() => { jest.restoreAllMocks() }) beforeEach(async () => { await provider.addInteraction({ uponReceiving: 'a request for supported items', withRequest: { method: 'GET', path: '/api/supported', }, willRespondWith: { status: 200, body: { itemGroups: { 'Database Tables': Matchers.eachLike('Table1', { min: 1 }), 'Property Files': Matchers.eachLike('Service1', { min: 1 }), Environments: Matchers.eachLike('Env1', { min: 1 }), }, environmentSupport: MatchersV3.eachValueMatches( { Env1: ['Service1'], }, MatchersV3.eachLike('Service1', 1) ), }, }, }) }) describe('returns a list of supported items', async () => { const { findByText } = render( <QueryClientProvider client={queryClient}> <FilterPane /> </QueryClientProvider> ) const env1 = await findByText('ENV1') expect(env1).toBeInTheDocument() const service1 = await findByText('Service1') expect(service1).toBeInTheDocument() const table1 = await findByText('Table1') expect(table1).toBeInTheDocument() }) } )``` The ts error on body: ```Type '{ itemGroups: { 'Database Tables': ArrayMatcher<string[]>; 'Property Files': ArrayMatcher<string[]>; Environments: ArrayMatcher<string[]>; }; environmentSupport: MatchersV3.RulesMatcher<...>; }' is not assignable to type 'AnyTemplate | undefined'. Types of property 'environmentSupport' are incompatible. Type 'RulesMatcher<string[]>' is not assignable to type 'string | number | boolean | JsonArray | JsonMap | Matcher<AnyTemplate> | ArrayMatcher<AnyTemplate> | TemplateMap | ArrayTemplate | null | undefined'. Type 'RulesMatcher<string[]>' is not assignable to type 'TemplateMap'. Index signature for type 'string' is missing in type 'RulesMatcher<string[]>'.ts(2322)``` Working approach using V3 pactWith: ```import { Matchers, MatchersV3 } from '@pact-foundation/pact' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { render } from '@testing-library/react' import { pactWith } from 'jest-pact/dist/v3' import FilterPane from '@/modules/properties/filtering/FilterPane' const queryClient = new QueryClient() const originalFetch = fetch const mockFetch = (port: number) => { jest.spyOn(global, 'fetch').mockImplementation((input, init) => { const url = typeof input === 'string' ? input : (input as Request).url if (url.startsWith('/api')) { return originalFetch(`http://localhost:${port}${input}`, init) } return originalFetch(input, init) }) } pactWith( { consumer: 'environment-comparison-application', provider: 'environment-comparison-service', }, (interaction) => { interaction('has a list of supported items', ({ provider, execute }) => { beforeAll(() => {}) afterAll(() => { jest.restoreAllMocks() }) beforeEach(async () => { await provider.addInteraction({ uponReceiving: 'a request for supported items', withRequest: { method: 'GET', path: '/api/supported', }, willRespondWith: { status: 200, body: { itemGroups: { 'Database Tables': Matchers.eachLike('Table1', { min: 1 }), 'Property Files': Matchers.eachLike('Service1', { min: 1 }), Environments: Matchers.eachLike('Env1', { min: 1 }), }, environmentSupport: MatchersV3.eachValueMatches( { Env1: ['Service1'], }, MatchersV3.eachLike('Service1', 1) ), }, }, }) }) describe('returns a list of supported items', () => { execute('api call', async (mockserver) => { mockFetch(mockserver.port) const { findByText } = render( <QueryClientProvider client={queryClient}> <FilterPane /> </QueryClientProvider> ) const env1 = await findByText('ENV1') expect(env1).toBeInTheDocument() const service1 = await findByText('Service1') expect(service1).toBeInTheDocument() const table1 = await findByText('Table1') expect(table1).toBeInTheDocument() }) }) }) } )```

eliranbardavid
2023-12-17 09:06
has joined #pact-js

anthony.trad
2023-12-17 12:30
has joined #pact-js

sergewar
2023-12-18 12:28
Hi. Can anyone provide an example for *message* consumer with `arrayContaining` matcher? I can't find anything.

kyle.r.shrader
2023-12-18 17:39
I guess a better question would have been to ask where to get the v4 builder, but now I see it isn't available in the Pact object given by pactWith.

m.mohammadi.se
2023-12-18 19:31
has joined #pact-js

matt.fellows
2023-12-18 20:29
Why does a message consumer help? The matcher is the matcher

lewis.foreman
2023-12-18 21:45
has joined #pact-js

matt.fellows
2023-12-18 22:51
ah, sorry I don?t know much about jest-pact

matt.fellows
2023-12-18 22:52
I think it?s largely irrelevant now with the latest version of Pact JS



eran.bergman560
2023-12-19 18:43
has joined #pact-js

matt.fellows
2023-12-20 00:44
OK I?m with you and you?re right - that?s an issue

matt.fellows
2023-12-20 01:34
I?m hoping https://github.com/pact-foundation/pact-js/pull/1143 will address this problem. Would you mind please casting your eyes over it?

tom.dracz
2023-12-20 09:53
has joined #pact-js

ivan.gutowski-smith
2023-12-20 10:40
has joined #pact-js

nicolas.vaquero
2023-12-20 11:31
has joined #pact-js

nicolas.vaquero
2023-12-20 11:35
Hi everyone! I am a new at provider side contract testing. I faced some issues using AWSv4 to authenticate GraphQL requests but I sorted it out with some help of an issue and an extra header, so if anyone needs it --> https://github.com/pact-foundation/pact-js/issues/304#issuecomment-1860716105

nicolas.vaquero
2023-12-20 11:36
```import { Request, sign } from "aws4"; // ... const getCredentials = async ( roleArn?: string ): Promise => roleArn ? getRoleCredentials(roleArn) : fromEnv()(); export const aws4SignAuth = async ( apiEndpoint: string, requestOptions: Omit, roleArn?: string ): Promise => { const parsedUrl = new URL(apiEndpoint); const credentials = await getCredentials(roleArn); return (req, res, next) => { const options: Request = { host: parsedUrl.host, path: parsedUrl.pathname + req.path, headers: {}, ...requestOptions, ...(req.method === "POST" ? { body: String(req.body), headers: { "Content-Type": "application/json" }, } : {}), }; const signed = sign(options, credentials); Object.assign(req.headers, signed.headers); next(); }; };```

nicolas.vaquero
2023-12-20 11:42
Hi, I am having an issue trying to use `failIfNoPactsFound` flag on the provider side When it is set to true I get ```Failures: 1) Failed to load pact - No pacts found matching the given consumer version selectors in pact broker ' // {"name":"Error","message":"Verfication failed","stack":"Error: Verfication failed\n at /....``` and when it is set to false I get ```Failures: 1) Failed to load pact - No pacts found matching the given consumer version selectors in pact broker ' // {"name":"Error","message":"Verfication failed","stack":"Error: Verfication failed\n at /....``` It doesn't seem to for for me as soon as I start using `consumerVersionSelectors.deployedOrReleased`. If I do not set `deployedOrReleased` at all, `failIfNoPactsFound` works fine. Same happens when using `mainBranch` flag

matt.fellows
2023-12-20 11:59
Mind sharing the logs? at DEBUG level? It could be a bug _somewhere_

nicolas.vaquero
2023-12-20 12:06
```2023-12-20T12:00:30.711417Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to https://<REDACTED>/pacts/provider/<PROVIDER_NAME>/for-verification using POST: {"includePendingStatus":false,"consumerVersionSelectors":[{"latest":true,"mainBranch":true,"branch":"mainx"}],"providerVersionBranch":"nico-test"} 2023-12-20T12:00:30.711451Z DEBUG ThreadId(02) hyper::client::pool: reuse idle connection for ("https", <REDACTED>) // ... 2023-12-20T12:00:31.050167Z INFO ThreadId(02) pact_verifier::pact_broker: error response for pacts for verification: failed validation - ["consumerVersionSelectors: cannot specify mainBranch=true with any other criteria apart from consumer (at index 0)"] 2023-12-20T12:00:31.050498Z ERROR ThreadId(02) pact_verifier: No pacts found matching the given consumer version selectors in pact broker 'https://<REDACTED>': failed validation - ["consumerVersionSelectors: cannot specify mainBranch=true with any other criteria apart from consumer (at index 0)"]```

nicolas.vaquero
2023-12-20 12:09
```2023-12-20T12:07:47.808284Z DEBUG ThreadId(02) pact_verifier::pact_broker: Sending JSON to <REDACTED>/pacts/provider/<PROVIDER_NAME>/for-verification using POST: {"includePendingStatus":false,"consumerVersionSelectors":[{"deployedOrReleased":true,"branch":"mainx"}],"providerVersionBranch":"nico-test"} ["consumerVersionSelectors: cannot specify the field branch with the field deployedOrReleased (at index 0)"]```

nicolas.vaquero
2023-12-20 12:09
@matt.fellows it is basically telling me that I cannot mix certain props

nicolas.vaquero
2023-12-20 12:10

nicolas.vaquero
2023-12-20 12:19
Now I am looking at it better, the info was right there with logLvel "info ```2023-12-20T12:17:32.559427Z INFO ThreadId(11) pact_verifier::pact_broker: error response for pacts for verification: failed validation - ["consumerVersionSelectors: cannot specify the fields branch/latest with the field deployedOrReleased (at index 0)"] 2023-12-20T12:17:32.561122Z ERROR ThreadId(11) pact_verifier: No pacts found matching the given consumer version selectors in pact broker 'https://skyai.pactflow.io': failed validation - ["consumerVersionSelectors: cannot specify the fields branch/latest with the field deployedOrReleased (at index 0)"] 2023-12-20T12:17:32.562776Z ERROR ThreadId(11) pact_verifier: Failed to load pact - No pacts found matching the given consumer version selectors in pact broker '<REDACTED>' 2023-12-20T12:17:32.563719Z WARN ThreadId(11) pact_matching::metrics: ``` ```2023-12-20T12:19:00.414088Z INFO ThreadId(11) pact_verifier::pact_broker: error response for pacts for verification: failed validation - ["consumerVersionSelectors: cannot specify the field branch with the field deployedOrReleased (at index 0)"] 2023-12-20T12:19:00.414601Z ERROR ThreadId(11) pact_verifier: No pacts found matching the given consumer version selectors in pact broker '<REDACTED>': failed validation - ["consumerVersionSelectors: cannot specify the field branch with the field deployedOrReleased (at index 0)"]```

matt.fellows
2023-12-20 12:22
can you please show me how you?re sending them in TS? I think you just need to separate them into different selectors (they are all in the same object / position 0 in the array of selectors)

nicolas.vaquero
2023-12-20 12:26
Yes, they were altogether

matt.fellows
2023-12-20 12:29
yep, separate them into two (or more): `[{deployedOrReleased: true}, {mainBranch: true}, ...]`

matt.fellows
2023-12-20 12:30
There is a bug though, that error should probably propagate to the user better. Mind raising a bug on Pact JS for me please? We can get it sorted (it?s upstream, but I can move it)

nicolas.vaquero
2023-12-20 12:31
Is it in pact-js or pact-js-core?

matt.fellows
2023-12-20 12:32
It?s actually in the rust core (https://github.com/pact-foundation/pact-reference). You can raise it there also if you like, and I can embellish it as needed

matt.fellows
2023-12-20 12:32
thanks


nicolas.vaquero
2023-12-20 12:53
I have just shape it a little more, but it still needs to be polished

emailmvj
2023-12-20 16:18
has joined #pact-js

matt.fellows
2023-12-21 01:16
Thanks for that!

matt.fellows
2023-12-21 05:05
I assume the :+1: = approve. I?ll cut a new release now!

noelmccrory
2023-12-21 12:31
has joined #pact-js

fajfer.pawel
2023-12-21 13:39
has joined #pact-js

praful.poudel
2023-12-21 13:44
has joined #pact-js

pratyush.jaiswal88
2023-12-23 16:45
has joined #pact-js

grzegorz.v.bobrowski
2023-12-24 02:37
has joined #pact-js

dimundo
2023-12-27 12:21
hi! any ETAs on next pact-js release ? https://github.com/pact-foundation/pact-js/compare/v12.1.1...master some December changes are nice to have/touch :)

elias.coelho
2023-12-27 17:52
has joined #pact-js

matt.fellows
2023-12-27 23:14
Sorry mate, there was a problem with the last release and I didn't get a chance to look at it prior to heading on leave. I'm back on 8th Jan but will hopefully get a moment to look at it before then

tomer
2023-12-28 21:52
has joined #pact-js

2024-01-02 14:46
This message was deleted.

nicolas.vaquero
2024-01-02 14:47
Thanks @adam.cox for the exhaustive test cases at Sky ^^


adam.cox
2024-01-02 14:59
if the TS code is correct and the output is wrong - is is possible changing something in tsconfig will fix it?

christopher316
2024-01-02 20:10
has joined #pact-js

matt.pichette
2024-01-02 20:26
has joined #pact-js

ocean.razafiarison
2024-01-03 08:57
has joined #pact-js

salmaan60
2024-01-03 20:14
has joined #pact-js

sam.huang1
2024-01-04 03:20
has joined #pact-js

ratnajenisha
2024-01-04 04:04
has joined #pact-js

markkellett
2024-01-04 18:27
has joined #pact-js

varghesevarampi
2024-01-05 02:10
has joined #pact-js

lbrndmrcr
2024-01-05 11:52
has joined #pact-js

mcarballido17
2024-01-05 20:12
has joined #pact-js

f.barril
2024-01-07 02:43
Hi everyone, I am having some troubles implementing contract testing using docker on a mac. I am getting the following error running the consumer test: ```[02:37:53.258] ERROR (196): pact-core@14.0.5: Failed to find native module for linux-arm64: TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')``` I am running inside a container with node 16. I can provide the full stack and more info. Thank you in advance

f.barril
2024-01-07 03:15
this is the command I am running ``` "test:pact:consumer": "VERBOSE=true mocha test/contract/*.test.js --exit"```

f.barril
2024-01-07 03:15
it breaks trying to create the MessageConsumerPact ``` const messagePact = new MessageConsumerPact({ consumer: 'patient.created-service-integrations', provider: 'patient.created-provider', // dir: path.resolve(process.cwd(), 'pacts'), pactfileWriteMode: 'update', // @todo logLevel: 'trace', // @todo })```


yonahlipman
2024-01-07 04:00
has joined #pact-js

x1destory
2024-01-07 19:21
has joined #pact-js

joshua.ellis
2024-01-07 21:15
It would appear that the Pact FFI (a rust binary library providing the core functions) is not found/available. It might be related to the way you installed Pact? Would you mind sharing? Can you see whether manually downloading the https://github.com/pact-foundation/pact-reference/releases/tag/libpact_ffi-v0.4.11 helps? (You'll have to extract the library to somewhere that can be found, or update the `LD_LIBRARY_PATH` environment variable if using a non-standard location).

f.barril
2024-01-07 21:45
I have used `npm install @pact-foundation/pact`

matt.fellows
2024-01-07 23:44
Sorry for the delay in responding Francisco, I?ve been on leave

matt.fellows
2024-01-07 23:44
I noticed your (two) bug reports, thanks. I?ll see if I can reproduce it

f.barril
2024-01-08 02:28
Thank you :) any additional info you need let me know

glenn
2024-01-08 08:39
@glenn has left the channel

christopher.tonog
2024-01-08 18:53
has joined #pact-js

harshad.rayunipet
2024-01-09 08:06
has joined #pact-js

yousafn
2024-01-09 08:12
what docker image and docker client ( docker desktop for mac or other ) is the mac intel or apple silicon based?

yousafn
2024-01-09 08:14
nice one @nicolas.vaquero appreciate the input, solution and you sharing it with others

yousafn
2024-01-09 08:16
jest pact needs to expose the v4 pact instance, it doesn?t currently. its also arguable as to whether the wrapper is needed anymore as we don?t have the same lifecycle concerns introduced by the ruby core using subprocesses. tl;dr - use pact js or fork jest pact and add v4 interface

f.barril
2024-01-09 09:48
mac m1 Docker desktop 4.24.2 (124339) docker image node:16

kumar.vas85
2024-01-09 09:50
has joined #pact-js

ndomingues10
2024-01-09 12:14
hello everyone, So i have an application using karma for unit testing. and i want to make contract testing using the pact and jest. Does anyone know some repo from where can i base my implementation. Thanks

nicolas.vaquero
2024-01-09 13:51
By the way, it says only POST because I use it for Appsync, but anything with a body should be having headers updated one ```const getCredentials = async ( roleArn?: string ): Promise<AwsCredentialIdentity> => roleArn ? getRoleCredentials(roleArn) : fromEnv()(); export const aws4SignAuth = async ( apiEndpoint: string, requestOptions: Omit<Request, "host" | "path" | "headers">, roleArn?: string ): Promise<express.RequestHandler> => { const parsedUrl = new URL(apiEndpoint); const credentials = await getCredentials(roleArn); return (req, res, next) => { const body = req.body instanceof Object ? JSON.stringify(req.body) : String(req.body); const options: Request = { host: parsedUrl.host, path: parsedUrl.pathname + req.path, headers: {}, ...requestOptions, ...(req.method === "POST" ? { body: Buffer.from(body), headers: { ...req.headers, host: parsedUrl.host, }, } : {}), }; const signed = sign(options, credentials); Object.assign(req.headers, signed.headers); next(); }; };```

matt.fellows
2024-01-09 20:40
I think I've gotten to the bottom of it, see issue

matt.fellows
2024-01-09 21:03
I don?t believe Karma and Jest can be used together, because they are both test runners. Pact is not compatible with Karma

matt.fellows
2024-01-09 21:04
If you use Karma today, you?re best just running the Pact test suite separately with Jest

shuo.diao
2024-01-09 23:54
has joined #pact-js

chris.speck
2024-01-10 02:52
has joined #pact-js

f.barril
2024-01-10 11:52
Problem gone using node 20, thank you for your help! But I am having another problem now, I'll write in a separated message

f.barril
2024-01-10 11:55
```pact-broker publish ./pacts --consumer-app-version="1.0.0" --auto-detect-version-properties --broker-base-url=http://localhost:9292 /home/node/app/node_modules/@pact-foundation/pact-core/standalone/linux-arm64-2.0.3/pact/lib/ruby/lib/ruby/3.2.0/net/http.rb:1271:in `initialize': Failed to open TCP connection to localhost:9292 (Cannot assign requested address - connect(2) for "localhost" port 9292) (Errno::EADDRNOTAVAIL)``` I am getting this error trying to publish the pact. My pact-broker is running in a docker container and my app is in another docker container. They are both in the same network. I am using a mac m1, my app is using node 20 image. Should I open an issue for this?

f.barril
2024-01-10 11:56
pact-broker docker compose :arrow_down: ``` pact-broker: container_name: local-environment-pact-broker image: "pactfoundation/pact-broker:latest-multi" ports: - "9292:9292" depends_on: - postgres environment: PACT_BROKER_PORT: '9292' PACT_BROKER_DATABASE_URL: "" PACT_BROKER_LOG_LEVEL: INFO PACT_BROKER_SQL_LOG_LEVEL: DEBUG # PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES is only needed for docker-compose # because the database takes longer to start up than the puma process # Should not be needed in production. PACT_BROKER_DATABASE_CONNECT_MAX_RETRIES: "5" # The list of allowed base URLs (not setting this makes the app vulnerable to cache poisoning) # This list allows the app to be addressed from the host and from within another docker container correctly # Ngnix config below makes the app accessible on ports 443 and 80, while the Ruby application itself runs on port 9292 PACT_BROKER_BASE_URL: 'https://localhost http://localhost http://localhost:9292 http://pact-broker:9292 https://host.docker.internal http://host.docker.internal http://host.docker.internal:9292'```

ulises.cervino
2024-01-10 14:19
hello all, what?s the JS equivalent of `queryParameterFromProviderState` from java-land?

trevor.cook
2024-01-10 18:33
has joined #pact-js

matt.fellows
2024-01-10 21:44
I think it?s just `fromProviderState`, which can be used where matchers are used, in this case on the `query` property

matt.fellows
2024-01-10 21:44
Are you sure that both containers are on the same network?

matt.fellows
2024-01-10 21:44
i.e. from the node image, attempting to hit `localhost:9292` would only work if both containers are running the same network (usually not the case). So that could explain that problem

chris.speck
2024-01-10 23:59
Hi, I am looking at integrating pact / contract testing into a new project. Where are the examples/documentation on how to integrate provider tests with jest + https://github.com/ladjs/supertest, or if that's not possible https://koajs.com/? I need to see the whole flow - i.e. 1. `beforeEach` creating the supertest instance or standing up the test server on a random ephemeral port 2. the actual provider test in a describe/it block 3. `afterEach` tearing down the supertest instance or standing down the test server

matt.fellows
2024-01-11 00:07
You don?t use supertest with Pact, because that?s a separate testing tool

matt.fellows
2024-01-11 00:08
howtoexamples


matt.fellows
2024-01-11 00:08
howtolearn

2024-01-11 00:08
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops

matt.fellows
2024-01-11 00:08
see the learning tutorials and examples above

chris.speck
2024-01-11 00:14
I've looked briefly through through that material. It leads to this: https://github.com/pactflow/example-provider/tree/master/src/product It uses a static port and won't work when we have concurrent tests. Also, I need to see/show that it works with Koa, not Express. I'm really just after an example I can poke, tear apart, follow to build a spike with.

matt.fellows
2024-01-11 00:17
I think you?re misunderstanding how pact works. There is a consumer side of the test, and a provider side. The consumer side doesn?t have Koa (or shouldn?t) and can be run in parallel. The tests are analogous to supertest, but you use the Pact consumer DSL instead (pointing at the pact mock server, not a real thing). This generates a pact file, which is essentially a set of tests for the provider. On the provider side, you start the API (Express, Koa etc.) and then you tell Pact to _verify_ it. Pact uses the contract generated by the consumer, to replay against the (locally) running API

matt.fellows
2024-01-11 00:18
I think you should be able to extrapolate the above provider example to koa quite easily

chris.speck
2024-01-11 00:21
I get the distinction between consumer side, the provider side and the role of a broker. I am specifically asking for a provider side example against Koa, but it appears one doesn't exist and the example you have with express uses a fixed test server port (which would preclude, e.g. running multiple tests concurrently against the provider).

matt.fellows
2024-01-11 00:26
gotcha

matt.fellows
2024-01-11 00:26
I don?t think that concurrency concern is a problem, because the Pact verifier doesn?t run those tests concurrently

matt.fellows
2024-01-11 00:27
Surely your koa server can expose a fixed port for the test?

matt.fellows
2024-01-11 00:28
> I don?t think that concurrency concern is a problem, because the Pact verifier doesn?t run those tests concurrently to elaborate, consider a scenario that is in conflict with another scenario. State 1: There are products State 2: There are no products Running those two examples concurrently is likely to break a scenario attached to one of them

chris.speck
2024-01-11 00:35
Is it assumed and a constraint on the provider side that you only ever have a single verifier running all contracts from all consumers against it sequentially?

chris.speck
2024-01-11 01:08
I know that lack of concurrency (anything that slows down unit tests) will be a reason for push-back, even if the new suite replaces brittle and even slower integration tests.

matt.fellows
2024-01-11 03:12
That?s a little presumptuous, without actually seeing how fast/slow they are

matt.fellows
2024-01-11 03:12
They usually aren?t very slow

matt.fellows
2024-01-11 03:13
> Is it assumed and a constraint on the provider side that you only ever have a single verifier running all contracts from all consumers against it sequentially? you could run the verification process multiple times (and in parallel), by having each verification only verify a subset of consumers or branches (or whatever https://docs.pact.io/selectors you choose)

ulises.cervino
2024-01-11 06:56
right! That?s what I thought. Any examples I can take a look at by any chance? We can?t get it to work :disappointed:

f.barril
2024-01-11 09:43
they are both on same network

ndomingues10
2024-01-11 11:10
Hi. Yes I'm using Jest for contract testing

ndomingues10
2024-01-11 11:10
thanks

ndomingues10
2024-01-11 11:13
@matt.fellows now the next step is to use TestBed or something to use a class with dependency injection to make the requests to the mock provided by pact

meetbogireddyhere
2024-01-11 16:20
has joined #pact-js

matt.fellows
2024-01-11 22:39
Forgive my persistence, but can you please show how you know they are on the same network?

matt.fellows
2024-01-11 22:41
It?s not enough for the containers to be running on the same underlying instance (e.g. your macbook). Docker logically separates the container networks. i.e. `localhost` from the docker container running the publish is not likely to be able to access `9292` of the pact-broker docker container, unless you link them or explicitly set the network for them (which from the setup of docker compose doesn?t look to be the case)

matt.fellows
2024-01-11 23:48
Let me see


ulises.cervino
2024-01-12 06:41
right, that?s what we?re doing. And this is what I quite don?t understand: ``` "query": { "$.entityVersion[0]": { "expression": "${v2Version}", "type": "ProviderState" } }```

ulises.cervino
2024-01-12 06:42
that?s what ends up in the contract. Will that result in a `POST /path/to/entity?entityVersion=${v2Version}` or `entityVersion=[${v2Version}]`?

ulises.cervino
2024-01-12 06:43
context: we?re trying to debug why these contracts are failing and the first thing we noticed is that versions were either not passed or hardcoded to the unit test?s UUID, now verifications are failing with a 500 (still haven?t tried turning logging levels higher on the provider side because java+logging is a mess and I actively try to avoid that)

david.garratt
2024-01-12 10:36
has joined #pact-js

roger.vanburgh
2024-01-12 16:54
has joined #pact-js

matt.fellows
2024-01-14 23:08
hmm good question. It depends on the query ?array? syntax used by the core - I actually don?t remember which style it uses (repeated fields or `entityVersion[]=` style). I believe it will store the parameters as an array though in the contract

matt.fellows
2024-01-14 23:08
Probably if you enable verbose/debug level logging in the verification, you?ll see the request the verifier fires at your service

ulises.cervino
2024-01-15 05:32
I?ll give it a go. Thanks!

matt.fellows
2024-01-15 05:40
@uglyog is the above ^^ related to https://github.com/pact-foundation/pact-reference/issues/355 at all? The related issue mentions headers, but the serialised query looks similar

adwait.damle
2024-01-15 07:43
@adwait.damle has left the channel

ulises.cervino
2024-01-15 08:10
interesting; the contract in principle is fine if what happened then while sending the request didn?t look like this: ```{ "version": [ "741ffe00-8c59-4275-bdd5-385b8249b992" ] }``` and more like ```{ "version": "741ffe00-8c59-4275-bdd5-385b8249b992" }``` instead

ulises.cervino
2024-01-15 08:11
because when you have query parameters, one way to send an array is to repeat `param=value&param=value?` right?

sarah.omalley
2024-01-15 10:03
has joined #pact-js

matt.fellows
2024-01-15 10:53
Yes exactly. There are many ways to encode arrays (or indeed, objects) in query strings. Unfortunately there is no standard. We might need to have a way to tell the contract the serialisation mechanism (see e.g. https://swagger.io/docs/specification/describing-parameters/). The https://github.com/pact-foundation/pact-compatibility-suite/tree/main looks ambiguous at the moment. @uglyog do we have any definitive statement on handling query strings anywhere?

lauren.flanagan
2024-01-15 13:51
has joined #pact-js

tunga
2024-01-15 23:16
has joined #pact-js

tunga
2024-01-15 23:26
Hi everyone, I am having some troubles running a provider verification test on a mac. I am getting the following error ```RUNS src/lambda/on-example-kafka-message/test/fake-provider-test.spec.ts [12:31:20.662] DEBUG (37860): pact-core@14.0.4: We detected your platform as: RUNS src/lambda/on-example-kafka-message/test/fake-provider-test.spec.ts [12:31:22.324] INFO (37860): pact@12.1.1: Verifying message [12:31:22.343] INFO (37860): pact-core@14.0.4: Verifying Pacts. [12:31:22.344] INFO (37860): pact-core@14.0.4: Verifying Pact Files [12:31:22.345] DEBUG (37860): pact-core@14.0.4: Initalising native core at log level 'debug' [12:31:22.346] DEBUG (37860): pact-core@14.0.4: binding path #0: : attempting to load native module from: /Users/tmangombe/dev/repeat-lambda-template/node_modules/@pact-foundation/pact-core/prebuilds/darwin-arm64 source: pact-js-core binding lookup You can override via PACT_PREBUILD_LOCATION [12:31:22.351] INFO (37860): 0.4.7: pact native library successfully found, and the correct version 2023-11-28T02:31:22.351682Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_new_for_application FFI function invoked 2023-11-28T02:31:22.351862Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_provider_info FFI function invoked [12:31:22.351] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetFilterInfo' was not executed as it had non-fatal validation errors: None of PACT_DESCRIPTION, PACT_PROVIDER_STATE or PACT_PROVIDER_NO_STATE were set in the environment [12:31:22.352] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetProviderState' was not executed as it had non-fatal validation errors: No failIfNoPactsFound option provided 2023-11-28T02:31:22.352189Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_set_verification_options FFI function invoked [12:31:22.352] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetPublishOptions' was not executed as it had non-fatal validation errors: No publishVerificationResult option / PACT_BROKER_PUBLISH_VERIFICATION_RESULTS set, or no providerVersion option [12:31:22.352] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetConsumerFilters' was not executed as it had non-fatal validation errors: Either no consumerFilters option provided, or the array was empty [12:31:22.352] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierSetFailIfNoPactsFound' was not executed as it had non-fatal validation errors: No failIfNoPactsFound option provided [12:31:22.353] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierAddCustomHeader' was not executed as it had non-fatal validation errors: No customProviderHeaders option provided [12:31:22.353] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierAddDirectorySource' was not executed as it had non-fatal validation errors: No pactUrls option provided 2023-11-28T02:31:22.353474Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_broker_source_with_selectors FFI function invoked [12:31:22.353] DEBUG (37860): pact-core@14.0.4: the optional ffi function 'pactffiVerifierAddProviderTransport' was not executed as it had non-fatal validation errors: No additional provider transports provided 2023-11-28T02:31:22.353927Z DEBUG ThreadId(02) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_execute FFI function invoked 2023-11-28T02:31:22.353938Z DEBUG ThreadId(02) pact_ffi::verifier::handle: Pact source to verify = PactBrokerWithDynamicConfiguration(https://.http://pactflow.io, provider_name='fake-provider', enable_pending=true, include_wip_since=None, provider_tags=[], provider_branch=Some("add-working-pact-tests"), consumer_version_selectors='[ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: Some(true), branch: None, matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: Some(true) }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: Some(true), deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: None }], auth=Token(O3Zq*************)') 2023-11-28T02:31:22.354299Z DEBUG ThreadId(02) 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-11-28T02:31:22.354323Z DEBUG ThreadId(02) 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 thread '' panicked at 'called Result::unwrap() on an Err value: reqwest::Error { kind: Builder, source: Os { code: 2, kind: NotFound, message: "No such file or directory" } }', pact_verifier/src/pact_broker.rs:530:10 stack backtrace: 0: 0x11c5c6c90 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3fbf720fbb1cb41b 1: 0x11c5e6e64 - core::fmt::write::h8ab6230d6f2a4204 2: 0x11c5c35a4 - std::io::Write::write_fmt::h15ecdca1916a179e 3: 0x11c5c6ae4 - std::sys_common::backtrace::print::hb6e94bab886a9ccf 4: 0x11c5c810c - std::panicking::default_hook::{{closure}}::h4a0e30e90cb1c7bb 5: 0x11c5c7f14 - std::panicking::default_hook::h0bb5bbf65ac7c64d 6: 0x11c5c857c - std::panicking::rust_panic_with_hook::h17facd9c53870157 7: 0x11c5c8488 - std::panicking::begin_panic_handler::{{closure}}::h9eab8195c369d860 8: 0x11c5c7070 - std::sys_common::backtrace::__rust_end_short_backtrace::hce5f67454da3493d 9: 0x11c5c81fc - _rust_begin_unwind 10: 0x11c63c674 - core::panicking::panic_fmt::hc7e96873bfc1c7ba 11: 0x11c63c9a8 - core::result::unwrap_failed::h364bae7050cb2efa 12: 0x11bc62efc - <pact_verifier::pact_broker::HALClient as core::default::Default>::default::hd325d92901bf551e 13: 0x11bc605ec - pact_verifier::pact_broker::HALClient::with_url::h2e2b1ff65b7db6ca 14: 0x11bbd1efc - pact_verifier::pact_broker::fetch_pacts_dynamically_from_broker::{{closure}}::h0efe5f6c3753a2d1 15: 0x11bbcd0f0 - pact_verifier::fetch_pact::{{closure}}::{{closure}}::ha4ba41399f5862cb 16: 0x11bbd9808 - <futures_util::stream::stream::flatten::Flatten<St,::Item> as futures_core::stream::Stream>::poll_next::h8eb667b07e0372c3 17: 0x11bb308c4 - <futures_util::stream::stream::collect::Collect<St,C> as core::future::future::Future>::poll::h1fcaf43d7bc897e6 18: 0x11baaa9cc - pact_verifier::fetch_pacts::{{closure}}::{{closure}}::h23bda17ee0ec6717 19: 0x11baba164 - pact_verifier::verify_provider_async::{{closure}}::{{closure}}::h814461e2ffa4a20e 20: 0x11bb03d98 - <tracing::instrument::Instrumented as core::future::future::Future>::poll::h7c429118268f87cb 21: 0x11b9fad40 - <tokio::task::task_local::TaskLocalFuture<T,F> as core::future::future::Future>::poll::h7ec1ad83ec0849c3 22: 0x11b9bcfb8 - pact_verifier::verify_provider_async::{{closure}}::hf44501821f704b81 23: 0x11b9e60e8 - tokio::runtime::park::CachedParkThread::block_on::hfce2416cec7139be 24: 0x11bb928a0 - tokio::runtime::context::runtime::enter_runtime::hc621080d259a112c 25: 0x11bc03ccc - tokio::runtime::runtime::Runtime::block_on::h2989b66e42e6cbc9 26: 0x11b9ef714 - pact_ffi::verifier::handle::VerifierHandle::execute::h3b8325364b9592ba 27: 0x11ba647f8 - pact_ffi::error::panic::catch_panic::hb11aa34866f5e36d 28: 0x11bb2d7e0 - _pactffi_verifier_execute 29: 0x109f8b098 - __ZN18VerificationWorker7ExecuteEv 30: 0x109f8ada8 - __ZN4Napi11AsyncWorker9OnExecuteENS_3EnvE Caught panic with error: called Result::unwrap() on an Err value: reqwest::Error { kind: Builder, source: Os { code: 2, kind: NotFound, message: "No such file or directory" } } [12:31:22.360] DEBUG (37860): pact-core@14.0.4: shutting down verifier with handle 0 2023-11-28T02:31:22.360806Z DEBUG ThreadId(01) pact_ffi::verifier: pact_ffi::verifier::pactffi_verifier_shutdown FFI function invoked FAIL src/lambda/on-example-kafka-message/test/fake-provider-test.spec.ts1 ? Fake Provider Tests ? should verify the contract with the consumer Verfication failed at node_modules/@pact-foundation/pact-core/src/verifier/nativeVerifier.ts:52:20 RUNS src/lambda/on-example-kafka-message/test/onExampleKafkaMessageHandlerContract.spec.ts [12:31:30.792] DEBUG (37860): pact-core@14.0.4: We detected your platform as: darwin-arm64 [12:31:31.634] DEBUG (37860): pact-core@14.0.4: Initalising native core at log level 'debug' [12:31:31.634] DEBUG (37860): pact-core@14.0.4: binding path #0: : attempting to load native module from: /Users/*****/dev/lambda-template/node_modules/@pact-foundation/pact-core/prebuilds/darwin-arm64 source: pact-js-core binding lookup You can override via PACT_PREBUILD_LOCATION``` more details here -> https://github.com/pact-foundation/pact-js/issues/1139

matt.fellows
2024-01-16 01:23
Any chance you could please DM me a version of the above logs at TRACE level? That might reveal a few other bits and bobs

rholshausen
2024-01-16 03:28
has joined #pact-js

rholshausen
2024-01-16 03:30
The fix for #355 is for both headers and query parameters

matt.fellows
2024-01-16 03:39
Thanks Ron. On query strings, do we have any statements on what format they take during verification?

rholshausen
2024-01-16 04:17
I don't recall any statements, but there may be some in the specs

matt.fellows
2024-01-16 04:37
It only mentions serialisation, and not how the request is sent by the verifier

rholshausen
2024-01-16 05:51
The verifier uses the reqwest HTTP client. That will be responsible for serialising the query parameters


ulises.cervino
2024-01-16 07:53
?Calling `.query(&[("foo", "a"), ("foo", "b")])` gives `"foo=a&foo=b"` ? seems to imply that ```"query": { "$.entityVersion[0]": { "expression": "${v2Version}", "type": "ProviderState" } }``` should result in requests which end with `?entityVersion=UUID_HERE`, or am I misreading?

matt.fellows
2024-01-16 10:41
That's how I read it also

sayan.adak
2024-01-16 12:21
has joined #pact-js

shobhit.agarwal
2024-01-16 12:22
has joined #pact-js

carmen.rietdijk
2024-01-16 12:53
has joined #pact-js

carmen.rietdijk
2024-01-16 13:45
Dear community, I am writing my first Pact test, for the consumer side. I am using the experimental V4 version. It seems everything is working untill the response is sent back from the server. It might be caused by thread has not entered Tokio, and therefore the server is shut down. I have no experience with Rust or Tokio, so I am not sure how this error is caused by my setup or my test. @matt.fellows I've found a post by you dated 2022-09-06 that shows a similar error. So I am hoping you know what might be wrong. And more importantly, how to fix it? Thanks for your time, Carmen

marek19922209
2024-01-16 14:34
Hello, i have a problem while running two tests in the same file using jest, for some reasons pact file is being overriden by last test only, how to disable pact file override ? Imjust PactV3 spec

marek19922209
2024-01-16 14:50
my test structure in jest is like : `describe(some endpoint) {` `it(successfull scenario) {` `}` `it(negative scenario) {` `}` `}` and it will only save negative scenario in pact file

yousafn
2024-01-16 16:36
Are the descriptions and states unique between the tests? I imagine one is clobbering the other. You probably need to ensure these are unique per test

yousafn
2024-01-16 16:38
Can you potentially produce a reproducible example and provide a bit more detail on your setup (os/node version etc) as there probably isn?t enough in there to help with at the moment. Thanks for reaching out though!

matt.fellows
2024-01-16 21:02
Perhaps you could share the test so we can help?

matt.fellows
2024-01-17 03:23
FYI a fix for the query and header generators in the pact file went out today. You might need to re-install the latest Pact or do an update on the `@pact-foundation/pact-core` dependency

ulises.cervino
2024-01-17 06:52
ah, cool, thanks for the heads up, we?ll give it a go :+1:

nick116
2024-01-17 09:57
has joined #pact-js

carmen.rietdijk
2024-01-17 11:04
I would love to offer a reproducible example. But since I have no idea what is going on, I have no clue how to reproduce it. I did manage to write functional contract tests for the different workshops offered on the Pact website, in case that is useful to know. OS: Windows 11, version 22H2 for x64 Node: 20.9.0 Axios: 1.6.2 Typescript 4.9.5 What else would you like to know?

matt.fellows
2024-01-17 11:19
Does your test that produces that error above reliably reproduce the problem? If so, pare back the test (by removing all of your code/IP until the problem goes away - that will either reveal the problem, or give us a repro we can use to debug)

carmen.rietdijk
2024-01-17 11:56
Yes the issue is reproduced by my test reliably. I will follow your approach, thanks for the suggestion! :slightly_smiling_face:

marek19922209
2024-01-17 14:40
states are the same

marek19922209
2024-01-17 14:53
Ok seems like reviewing my test naming helped

marek19922209
2024-01-17 14:53
it seems that uponReceiving: "a request to update a dashboard", was not unique

ndomingues10
2024-01-17 16:01
@matt.fellows is it possible to use karma-pact in conjuntion with pactjs

matt.fellows
2024-01-17 21:24
Yes, but only with older versions of pact. Karma pact is dead

miguel.heitor
2024-01-18 09:03
has joined #pact-js

miguel.heitor
2024-01-18 09:19
hey! following up on this, someone knows when will pact-js library update its pact-core dependency to have that last fix? we mostly use pact-js to generate our tests


matt.fellows
2024-01-18 10:35
Can you please run this command: ```npm list @pact-foundation/pact-core``` in the project that?s not working?

miguel.heitor
2024-01-18 10:35
sure

miguel.heitor
2024-01-18 10:44
oh, we still have a previous pact-js version which was fixed on core 13, thats why it didn't change when we upgraded the core one. changing this one first , hopefully not many changes will be needed

matt.fellows
2024-01-18 10:44
ohh right. Which version of Pact JS are you on?

miguel.heitor
2024-01-18 10:45
10.4.1

matt.fellows
2024-01-18 10:46
oh, yes, that?s a few major versions behind.

miguel.heitor
2024-01-18 10:46
we dont have many tests though. the js side has started recently. so ill try the update

matt.fellows
2024-01-18 10:46
Actually, the major change was 9 -> 10

matt.fellows
2024-01-18 10:46
I think probably it won?t be anything major

matt.fellows
2024-01-18 10:47
Oh yeah, see: https://github.com/pact-foundation/pact-js/blob/master/CHANGELOG.md One was making the node version minimum 16 and another was a minor change to `MessageStateHandlers`

miguel.heitor
2024-01-18 10:47
great :slightly_smiling_face:

miguel.heitor
2024-01-18 10:48
yeah, just made a small edit and now its working. trying now our pipeline after the change :slightly_smiling_face:

anshita.tripathi
2024-01-18 11:07
has joined #pact-js

miguel.heitor
2024-01-18 11:15
seems like its still working as before. the variable injected in the query is still the example value and not the one that should come from the provider :confused:

matt.fellows
2024-01-18 11:23
Ah, this thread is so long I think we?re talking across purposes. The problem (or potential problem) we were discussing was the serialisation in the pact file, but there was a ?problem? that wasn?t articulated. So the problem is clearer (ish) now. Are you using JS on both sides? Is the verification JS or Java? Can you please also share the contract (or relevant bits)?

miguel.heitor
2024-01-18 11:25
No, we have Js on the consumer and Java on the Provider The publish and can-i-deploy are done with JS

matt.fellows
2024-01-18 11:26
So just for reference, the fix was actually for a different issue, but it _looked_ like it might also be affecting the query string serialisation. So we have a few things we?ll need to check off to confirm where the problem may lie

miguel.heitor
2024-01-18 11:26
regarding the contract its what Ulisses shared above. We're trying to add a variable in the query path that is being added with the array.. but using the default value insstead of one that should come from the provider state

matt.fellows
2024-01-18 11:27
thanks, has the serialisation changed since Ulisses first shared it or is it exactly the same?

miguel.heitor
2024-01-18 11:28
which in the code is coming from: `query: {basketVersion: fromProviderState('${basketV2Version}', v2Version)},` inside the provider.withRequest

matt.fellows
2024-01-18 11:30
thx, can you please show the matching rules/generators section?

miguel.heitor
2024-01-18 11:36
```"query": { "$.basketVersion[0]": { "expression": "${basketV2Version}", "type": "ProviderState" } }``` this part?

matt.fellows
2024-01-18 11:41
thanks. It looks the same as the above to me. That may or may not be correct. What does the provider verification setup look like for this?

miguel.heitor
2024-01-18 11:42
so when they set the state from the provider state?

ulises.cervino
2024-01-18 11:42
that?s us, it?s a java app, and in the state method we have something like ``` state.put("basketV2Version", internalBasketV2.getBasketVersionUUID());```

ulises.cervino
2024-01-18 11:42
for another consumer (using pact-jvm) this works just fine, which is why we?re trying to figure if this is 1) a pact-js bug 2) pact-js misuse 3) both

matt.fellows
2024-01-18 11:48
do you happen to have a contract for a working one?

ulises.cervino
2024-01-18 11:59
I can probably get it, 1sec

matt.fellows
2024-01-18 12:01
thx. No hurries, I?ll be heading to bed any moment

matt.fellows
2024-01-18 12:01
Rest assured this thread will occupy my nightmares :wink:

ulises.cervino
2024-01-18 12:02
``` "query": { "basketVersion": { "dataType": "STRING", "expression": "basketVersion", "type": "ProviderState" } }```

ulises.cervino
2024-01-18 12:02
managed ? right before your bedtime!

matt.fellows
2024-01-18 12:03
what spec version is that? (and is it different to the JS one?)

ulises.cervino
2024-01-18 12:03
it?s V3 according to the test itself: ``` @PactTestFor(pactMethod = "updateBasketPutAsyncV2", pactVersion = PactSpecVersion.V3)```

miguel.heitor
2024-01-18 12:05
in js we have this `const mockProvider = new PactV3({` so think it should be the same. (btw, im new here, seeing all of this for the first time)

matt.fellows
2024-01-18 12:06
I might need somebody with a higher pay grade to look at this tomorrow. But thanks, I think we might have enough to at least get to the next stage.

miguel.heitor
2024-01-18 12:06
thank you very much for the help till now :slightly_smiling_face:

matt.fellows
2024-01-18 12:07
You?re welcome folks

hiroshi.fujii
2024-01-18 14:50
has joined #pact-js

carmen.rietdijk
2024-01-18 19:04
Thank you for your suggestion @matt.fellows :slightly_smiling_face: I started making changes to my code, as you suggested, and somehow the issue disappeared. I do not know how it happened, but I am glad that it did :slightly_smiling_face:

matt.fellows
2024-01-18 22:39
haha well, good to hear!

matt.fellows
2024-01-18 22:43
@rholshausen I could do with your eyes on this. It?s is quite a long thread so I will try to summarise: The JS DSL is producing this generator for a query string (they?re on the latest version): ```"query": { "$.basketVersion[0]": { "expression": "${basketV2Version}", "type": "ProviderState" } }``` It comes via this call in the JS client: ```query: {basketVersion: fromProviderState('${basketV2Version}', v2Version)}, inside the provider.withRequest (edited) ``` On the provider side, when verifying, they use this to inject the parameter: ```state.put("basketV2Version", internalBasketV2.getBasketVersionUUID());``` However, the value in the contract is still used. When looking at another test that _does_ work (generated by Java), the generator in the contract looks different: ``` "query": { "basketVersion": { "dataType": "STRING", "expression": "basketVersion", "type": "ProviderState" } }``` It?s curious that both the expression is different (no `$` business) and there is also no path to `basketVersion` in this contract. Both are version 3 contracts, apparently.

rholshausen
2024-01-18 22:49
Firstly, this is wrong: `$.basketVersion[0]`, that is what the fix I released addressed. I.e., with this expression, the generator won't match the proper query string value, it will try create a query string like `?%24.basketVersion%5B0%5D=VALUE` and not `?basketVersion=VALUE`

rholshausen
2024-01-18 22:50
Secondly, you can use either an expression or just the key name. So, `"expression": "basketVersion"` and `"expression": "${basketVersion}"` are equivalent

matt.fellows
2024-01-18 22:53
ok cool, thanks

rholshausen
2024-01-18 22:53
I don't think this ```"query": { "$.basketVersion[0]": { "expression": "${basketV2Version}", "type": "ProviderState" } }``` will do anything. I'm pretty sure the process works by going through the query parameters and looks for a matching query parameter

matt.fellows
2024-01-18 22:53
Thanks. I?ll try a repro on the latest version.

rholshausen
2024-01-18 22:53
So unless the actual query parameter is `$.basketVersion[0]` it will never get applied

matt.fellows
2024-01-18 22:54
Yeah, pretty sure it?s not

matt.fellows
2024-01-18 23:04
@miguel.heitor I think maybe you?re not on the latest `pact-core` version. After an `npm update @pact-foundation/pact-core` in a test project and then creating a version, I get the fixed generator: ``` "generators": { "query": { "basketVersion": { "expression": "${basketV2Version}", "type": "ProviderState" } }```

matt.fellows
2024-01-18 23:04
Thanks for confirming Ron.

ebernardino
2024-01-19 04:08
has joined #pact-js

ulises.cervino
2024-01-19 06:10
just to add/confirm: it?s the wrong matcher that?s tripping us up, not the value, etc. because for pact-jvm it all works as expected

matt.fellows
2024-01-19 06:12
You could probably test it locally, by downloading/acquiring the (currently broken) contract, modifying the `generators` section with the correct one and running the Java test with it. If that passes, we know it?s an issue with the contract serialisation

matt.fellows
2024-01-19 06:14
> just to add/confirm: it?s the wrong matcher that?s tripping us up, not the value, etc. because for pact-jvm it all works as expected you use the word ?matcher? here, and not generator. Just want to make sure we?re on the same page too! I haven?t looked at the matcher for this either, but the generator was definitely wrong. The generator is what?s used during provider verification, where a value is _generated_ dynamically. In this case, the generator gets the dynamic value from `state.put(..)` expression. my understanding is that this expression is having no effect, so the default value in the contract is being used. Is that correct?

matt.fellows
2024-01-19 06:15
I?ve just checked, and not surprisingly both the matcher and generator definition were incorrect: ``` "generators": { "query": { "$.basketVersion[0]": { "expression": "${basketV2Version}", "type": "ProviderState" } } }, "matchingRules": { "query": { "$.basketVersion[0]": { "combine": "AND", "matchers": [ { "match": "type" } ] } } },``` but are fixed in the latest: ``` "generators": { "query": { "basketVersion": { "expression": "${basketV2Version}", "type": "ProviderState" } } }, "matchingRules": { "query": { "basketVersion": { "combine": "AND", "matchers": [ { "match": "type" } ] } } }```

ulises.cervino
2024-01-19 06:49
> you use the word ?matcher? here, and not generator. Just want to make sure we?re on the same page too! sorry, still learning the terminology :slightly_smiling_face:

ulises.cervino
2024-01-19 06:49
good to see that it should be fixed in the latest version too (thanks for confirming) :heart:

matt.fellows
2024-01-19 06:49
No worries!

matt.fellows
2024-01-19 06:50
If you/Miguel can confirm the version of `@pact-foundation/pact`/ (+ `pact-core`) is in the project that would help

ulises.cervino
2024-01-19 07:01
that?s @miguel.heitor, we?ll confirm the versions (and upgrades) as the day progresses (still early morning here)

matt.fellows
2024-01-19 07:04
Yep I thought you were up early (in fact, you seem to be an early bird given our overlap :wink: )

miguel.heitor
2024-01-19 07:58
hey hey! :slightly_smiling_face: checking the versions here in the project: ```? bash git:(antripathi/CT-basketversion2) npm list @pact-foundation/pact-core nodejs@0.0.1 /Users/mheitor/git_tree/nodejs ??? @pact-foundation/pact-core@14.0.6 ??? @pact-foundation/pact@12.1.2 ??? @pact-foundation/pact-core@14.0.6 deduped ? bash git:(antripathi/CT-basketversion2) npm list @pact-foundation/pact nodejs@0.0.1 /Users/mheitor/git_tree/nodejs ??? @pact-foundation/pact@12.1.2```

miguel.heitor
2024-01-19 08:09
seems like there is a new core version from 15hrs ago, going to update to that one first and then recreate the pact files

miguel.heitor
2024-01-19 08:18
pact-core: ?? @pact-foundation/pact-core@14.1.0 ?? @pact-foundation/pact@12.1.2 ?? @pact-foundation/pact-core@14.0.6 pact-js: ?? @pact-foundation/pact@12.1.2

miguel.heitor
2024-01-19 08:19
ive just generated the pacts file and the generators are the same as before :confused:

hegge.m
2024-01-19 09:40
has joined #pact-js

visser.r
2024-01-19 09:40
has joined #pact-js

miguel.heitor
2024-01-19 09:42
well, last update.. i removed the node_modules, updated to last version from both dependencies and made sure that pact-js was with the correct pact-core last version. now this seems to be finally working :slightly_smiling_face:

miguel.heitor
2024-01-19 09:42
```"generators": { "path": { "expression": "/v2/${basketV2Id}/item/${insuranceItemId}", "type": "ProviderState" }, "query": { "basketVersion": { "expression": "${basketV2Version}", "type": "ProviderState" } } },```

miguel.heitor
2024-01-19 09:42
no more [0] in there

miguel.heitor
2024-01-19 09:54
trying to fix now the issues after the upgrade and will come back later when i see that the value is being correctly injected

matt.fellows
2024-01-19 10:12
Awesome - looks much better!

miguel.heitor
2024-01-19 13:09
If the pact file is correct now, this value that shows up here in the UI, should still be the one that i give as example?

miguel.heitor
2024-01-19 13:10
i would expect it to be a different one, coming from the set state on the provider. the test keeps failing and im wondering about that value

ulises.cervino
2024-01-19 14:53
that?s a red-herring, this is from a contract that works/is verified today (all jvm based)

miguel.heitor
2024-01-19 14:55
and that one is the one added by the consumer?

ulises.cervino
2024-01-19 14:55
yes

ulises.cervino
2024-01-19 14:55
this is the important bit

miguel.heitor
2024-01-19 14:55
oh..thats not helpful :confused: would be better if it had the injected value

ulises.cervino
2024-01-19 14:57
I wonder why `dataType` is missing :thinking2:

miguel.heitor
2024-01-19 14:58
indeed..was thinking of trying to fill it in myself and push just to see if something changes in the result

matt.fellows
2024-01-19 23:21
The injected value is dynamic, so the contract doesn't show it. But it would be cool if we showed what the provider did inject So I assume it's still not working?

ulises.cervino
2024-01-21 19:26
we?ve gone past the hurdle of query-params thanks to the latest patch, now we need to iron out actual issues with the contract, thanks for checking in

matt.fellows
2024-01-21 21:24
Great! No worries

dcrivella
2024-01-21 23:51
has joined #pact-js

dmondejar
2024-01-22 03:39
has joined #pact-js

grzegorzstanek
2024-01-22 10:46
has joined #pact-js

miguel.heitor
2024-01-23 10:41
hello, morning! Im creating some pact tests against a Java provider and im trying to check a response that comes with a key value result. something like: ```{ items: { 123: { id: 123, -> i want to check this type: 'type' -> i want to check this }, 456: { id: 456, type: 'another_type' } } }``` im trying on the consumer side to add a similar response on the `willRespondWith` , but im not being able to make the key part as those are being set in the provider state and im not able to add a function

miguel.heitor
2024-01-23 10:43
this is the response im trying to create on the consumer side

miguel.heitor
2024-01-23 11:42
well, i found the `eachKeyMatches` and seems to work for what I was trying to do :slightly_smiling_face: thanks anyway!

matt.fellows
2024-01-23 12:12
nice work :slightly_smiling_face:

2024-01-23 14:07
This message was deleted.

mcruzdrake
2024-01-23 14:26
Hey @marek19922209! The README here is quite detailed with examples on how to use the CLI tool https://github.com/pact-foundation/pact_broker-client. Hope this helps!

francois.larouche1
2024-01-23 14:31
has joined #pact-js

sarah.souza
2024-01-23 15:24
has joined #pact-js

marek19922209
2024-01-23 15:56
docker run --rm \ -w $(Build.SourcesDirectory)/$(bffFolder)/src/pacts \ -v $(Build.SourcesDirectory)/$(bffFolder)/src/pacts:$(Build.SourcesDirectory)/$(bffFolder)/src/pacts \ -e PACT_BROKER_BASE_URL="https://orbus.pactflow.iorl" \ -e PACT_BROKER_TOKEN="token" \ pactfoundation/pact-cli:latest \ publish \ $(Build.SourcesDirectory)/$(bffFolder)/src/pacts/pact.json --consumer-app-version=$(version.packageSemVer)

marek19922209
2024-01-23 15:57
trying with this command not working at all

marek19922209
2024-01-23 15:57
always some problem

marek19922209
2024-01-23 15:57
No value provided for required option --consumer-app-version :open_mouth:

marek19922209
2024-01-23 19:21
Im trying to run following script in order to publish contract to pactflow.. IT is being run in azure pipeline. When im doing ls -la with my path PACT FILE is there. ( on host) , but when im running command in pipeline, still receving error message that: ```Specified pact file '/pacts/somePact.json' does not exist. This sometimes indicates one of the arguments has been specified with the wrong name and has been incorrectly identified as a file path. If you are using Docker, check that you have mounted the pact file or directory into the container correctly using `-v`, and have specified the location of the pact file or directory in the *Docker container*, not the *host*.``` `chmod 755 $(Build.SourcesDirectory)/someFolder/src/pacts/somePact.json` `docker run --rm -v $(Build.SourcesDirectory)/someFolder/src/pacts/somePact.json:/pacts pactfoundation/pact-cli:latest pact-broker publish /pacts/somePact.json --broker-base-url=https://somecompany.pactflow.io --broker-token=token--consumer-app-version=$(version.packageSemVer)`

matt.fellows
2024-01-23 23:22
Are you on windows? I recall the directory mapping being a bit different on that

marek19922209
2024-01-24 07:44
yes and when i tryin to print this path $(Build.SourcesDirectory)/someFolder/src/pacts/ pact file is there

marek19922209
2024-01-24 08:18
sorry my bad, agent os is Linux

zachary.romano
2024-01-24 19:16
has joined #pact-js

ken.overgard
2024-01-24 19:32
has joined #pact-js

rama.ganapa
2024-01-24 21:13
has joined #pact-js

justin.gilroy
2024-01-24 21:46
has joined #pact-js

naveenkarkra
2024-01-24 23:36
has joined #pact-js

matt.fellows
2024-01-25 05:27
It looks like you're mapping a file (on the host) to a dir on the container. Either map the file to a file, or just map the directories

marek19922209
2024-01-25 09:06
i just went to simpler solution without docker. $(pwd)/bff/node_modules/.bin/pact-broker publish $(pwd)/bff/src/pacts\pactFile.json --consumer-app-version=version --broker-token=token--broker-base-url=https://orbus.pactflow.iorl

yangtao.ge
2024-01-25 11:07
has joined #pact-js

salman.bilalshah
2024-01-25 11:34
has joined #pact-js

matt.fellows
2024-01-25 11:36
That also works ;)

sridhar.munendramani
2024-01-25 14:32
has joined #pact-js

scott.anderson
2024-01-25 15:05
has joined #pact-js

bala.kurakula
2024-01-25 17:21
has joined #pact-js

sarah.hand
2024-01-25 17:28
has joined #pact-js

corey.jewett
2024-01-25 18:48
has joined #pact-js

eddjlsh94
2024-01-26 09:41
has joined #pact-js

falkowski.b
2024-01-26 10:59
has joined #pact-js

gawaine.ogilvie
2024-01-26 17:00
I?m a bit confused with the PactJS documentation. I understand starting up the service locally, but how much dependencies am I suppose to stub out? Let?s say my service has 5 external services that are dependencies, do I stub out all 5? Versus just running the service and stubbing out the specific route that?s being called by the contract. Any suggestions would be helpful, thanks.

yash.khade
2024-01-26 18:50
has joined #pact-js

joe.allen
2024-01-26 18:50
has joined #pact-js

andrew.voronin
2024-01-26 18:50
has joined #pact-js

richie.schramm
2024-01-26 18:55
has joined #pact-js

dsteinbach77
2024-01-26 23:23
has joined #pact-js

matt.fellows
2024-01-27 21:19
You just need to stub out what's required for the test to pass

matt.fellows
2024-01-27 21:20
In a consumer test that's usually a lot less because this should only testa single outbound call

matt.fellows
2024-01-27 21:20
The provider side usually all external dependencies

gawaine.ogilvie
2024-01-27 21:21
ah I see. I am referring to the `provider` side

rachida_laghmami
2024-01-28 15:53
has joined #pact-js

hrushikesh.agrawal
2024-01-29 07:13
has joined #pact-js

santos.danallanbray
2024-01-29 10:50
has joined #pact-js

katie.andriacchi
2024-01-29 15:05
has joined #pact-js

darren.grove
2024-01-29 15:11
has joined #pact-js

markkellett
2024-01-29 16:26
I am currently implementing bi-directional testing, however I think it would be good to be able to run the tests locally during development for a quick verification check. Is this possible for bi-directional testing? I know for consumer led, you can download the pact files locally and use the testing tools to verify there. I could do this for the provider, but it would involve a different test flow?

markkellett
2024-01-29 16:29
What I mean is traditionally for bi-directional, the provider verifies their own tests and simple uploads an openapi doc (there are no pact tests locally to verify they match??) To get the feedback you need to ? Upload the openapi doc ? use `can-i-use` ? record the deployments into the environments but if you wanted to close that loop, you would need to ? Download the latest consumer pacts ? Run a provider test against those pacts?

michael.brandeis
2024-01-29 16:37
has joined #pact-js

niki.mahurin
2024-01-29 17:51
has joined #pact-js

yousafn
2024-01-29 18:24
latest from main branch or deployed/released from any consumers. run pacts against https://github.com/pactflow/swagger-mock-validator you could just use the Pact Verifier and use consumer version selectors to retrieve the correct pacts, and perform the requests against the actual application, rather than statically against the openapi. it might depend on how you leverage OAS. design first or autogenned, combo of both, and where you want the feedback.

arina
2024-01-29 21:48
has joined #pact-js

matt.fellows
2024-01-29 21:59
We have a roadmap item for a `can-i-deploy` _local_ variant, which allows you to pass in either a work-in-progress pact or OAS

matt.fellows
2024-01-29 22:00
but for now, Yousaf?s suggestion might get you going

tomasz.perek
2024-01-30 12:19
has joined #pact-js

kp1289
2024-01-30 12:37
Hi all, I'm looking to learn contract testing and wondered if anyone could recommend a good tutorial for learning/understanding contract testing. i've been reading the docs https://docs.pact.io/implementation_guides/javascript/docs/consumer and I find that they require already a level of assumed knowledge. I'm looking for something that really starts from the ground up and build up.

yousafn
2024-01-30 12:55
Hey Kyle, We have a range of tutorials/workshops/examples over on our docs site https://docs.pact.io/implementation_guides/workshops as well as a 5 minute getting started guide https://docs.pact.io/5-minute-getting-started-guide Once you?ve done that, working through, say for example the pact-js workshop, should help ground you in the basics https://github.com/pact-foundation/pact-workshop-js

kp1289
2024-01-30 14:15
Thanks @yousafn, I'll have another visit and give those examples a go.

arina
2024-01-30 17:04
hey! I'm going through the documentation and can't find info about mockService for pact-js. Could you please point me out to where I could go to read more about it? thanks in advance!

sofia
2024-01-30 17:12
has joined #pact-js

wesley.williams
2024-01-30 18:02
has joined #pact-js

matt.fellows
2024-01-30 20:38
What are you trying to achieve?

matt.fellows
2024-01-30 20:38
The mock service is implementation detail mostly

j.sauret
2024-01-31 14:03
has joined #pact-js

michelle.ryals
2024-01-31 22:17
has joined #pact-js

jyothi.kaspa
2024-01-31 23:34
has joined #pact-js

prasadsolanki
2024-02-01 12:35
Hello All, I am trying to use provider state to generate a random parameter. I am facing two issues 1. Parameter passed to provider test is undefined 2. Value returned is NaN I tried quite a few things which I could find but no luck. Can anyone take a look at below code screenshots and see what I am doing wrong? I am using specification V3 Pact Test - Passing prefix value to state

kp1289
2024-02-01 15:11
Hi all, I'm looking to start learning Pact/Contract testing and I have a question to see if contract testing is suitable for my use case. My company develops an API that is used by an external company, they can use our API to POST/GET data into our system. I'd like to know if I can use contract testing as part of our QA process to test as the third party, to ensure that the JSON objects being returned to the 3rd party are the correct shape and have the correct data types.

yousafn
2024-02-01 16:39
its not recommend with third party teams as they are usually out of your control but you can allow them to publish pacts to a broker, and use them to guide your development rather than block it. You can also generate example use cases as though you are a client, and use that as documentation for end users/integrators. You could then detect where contracts supplied by integrators differ from your own examples, and maybe initiate a conversation that way.


patrika.patil
2024-02-01 16:41
has joined #pact-js

kp1289
2024-02-01 16:43
In my scenario, we wouldn't be working with the 3rd party at all, we just want to make sure that the contract we are offering them, as a provider doesn't break?

yousafn
2024-02-01 16:44
well if its a api you offer, and its considered public, you have to assume everything is being used. if the third party isn't going to be working with you, you won't get visibility into their usage and Pact won't be the right tool for the job

tim.willis
2024-02-01 16:44
has joined #pact-js

kp1289
2024-02-01 16:45
Perfect, that's exactly what I thought, thank you very much.

kp1289
2024-02-01 16:45
The API, does connect to an internal API we offer, would it best to place the contract testing there?

kp1289
2024-02-01 16:46
between the two APIS that are under our dev teams control.

yousafn
2024-02-01 16:47
Providing SDK's and a good onboarding experience, and having a mechanism to commuicate changes to an api (sandbox envs) are great. Just think about what you love when you use another API and things that give you gripes, and solve the former, quash the latter. within organisations where teams communicate is perfectly suited and all of our docs/examples support those cases, and suggest where failures occur, teams communicate in order to ascertain the way forward, contract testing is that early communicator to a change in intent of a service, be it intended (which promotes discussion) or unintended (which leads to remediation)

kp1289
2024-02-01 16:51
Thanks again!

yogi.patel
2024-02-01 18:38
has joined #pact-js

sebbmoreno
2024-02-01 21:23
has joined #pact-js

matt.fellows
2024-02-02 00:33
can you please share the pact file? It looks like params isn?t in the pact

cverma28
2024-02-02 10:30
has joined #pact-js

cverma28
2024-02-02 10:31
Hi All, Does any one have pact java framework with BDD implementation

cverma28
2024-02-02 10:32
any help to write normal pact test in BDD style

a.g.s.maxwell
2024-02-02 12:54
has joined #pact-js

t.mazelin
2024-02-02 23:33
has joined #pact-js

maeleeuxs
2024-02-03 10:20
has joined #pact-js

swaroopsonline
2024-02-04 02:44
has joined #pact-js

jose.silva
2024-02-04 14:45
has joined #pact-js

joshua.ellis
2024-02-04 21:38
That's probably best answered in the #pact-jvm channel :slightly_smiling_face: EDIT: Which I now see you have asked as well.

sonal3062000
2024-02-05 09:52
has joined #pact-js

lorenz.ammon082
2024-02-05 14:44
has joined #pact-js

patrick.barnes
2024-02-05 19:44
has joined #pact-js

andrew.kostka
2024-02-05 20:24
has joined #pact-js

allie
2024-02-05 20:25
has joined #pact-js

bryan.anderson
2024-02-05 21:18
has joined #pact-js

alec.abdul-rahim
2024-02-05 23:34
has joined #pact-js

filip.olszewski
2024-02-06 12:00
has joined #pact-js

prasadsolanki
2024-02-06 14:50
Thanks @matt.fellows for looking into this. Here is the pact file generated

amol.jose
2024-02-06 18:03
has joined #pact-js

matt.fellows
2024-02-06 20:59
Yep no Params on there. Can you please create a repro for us? I could be how you setup your test case but screenshots of your IDE aren't very helpful in determining that

ryoshida
2024-02-07 01:47
has joined #pact-js

pallam.sudhasrinivas1
2024-02-07 13:21
has joined #pact-js

michal
2024-02-07 16:36
has joined #pact-js

miguel.heitor
2024-02-08 09:46
hey! :slightly_smiling_face: any recommendation about the generated pact files being kept in version control or not? currently my team has that folder on .gitignore and i dont really understand it .. so wanted to check if there are some recommendations on this for best practices. to me, seeing it as a contract, it seems that the generated file should be kept, but would like to check some opinions :slightly_smiling_face:

matt.fellows
2024-02-08 09:57
It's generally expected to not check-in the files if you use a pact broker

miguel.heitor
2024-02-08 09:58
ok, but why?

miguel.heitor
2024-02-08 10:00
at least im seeing this as a contract that should be kept between different executions (if nothing changed). bit like a snapshot or something similar

yousafn
2024-02-08 10:03
It can lead to stale interactions and issues merging contents. If you remove a pact test from your codebase, the interaction would remain in your pact contract, that is no bueno

yousafn
2024-02-08 10:04
You can check them in if you want, but I would just ensure the pacts folder is cleared prior to any new test execution.

miguel.heitor
2024-02-08 10:07
> and issues merging contents. because when pact runs, it merges the new test execution to the previous?

yousafn
2024-02-08 10:09
kinda, you have a named file with consumer/provider name. if you have 3 tests, all with the same c/p name, you will get one pact file, with three interactions.

yousafn
2024-02-08 10:10
if you remove one of those tests, you will still have three interactions in your pact file, if you haven?t deleted it prior to the 2nd test run

miguel.heitor
2024-02-08 10:11
yup yup, that makes sense and i agree with the removal between tests executions while in local. even my local command does something like `rm -rf pacts && run_pact_tests`

miguel.heitor
2024-02-08 10:13
but as im seeing this a bit like a snapshot (from jest) not really getting the part of not pushing them and having to generate again in the pipeline to be able to publish. at least im not expecting that a different behaviour would be outputted i might be seeing this the wrong way though

yousafn
2024-02-08 10:16
> not really getting the part of not pushing them and having to generate again in the pipeline to be able to publish. If you don?t generate them in the pipeline, then the results could be erroneous. you should never pregenerate pact contracts, and publish them from CI from a build that hasn?t ran the tests. the code could have changed from the content in the contract

yousafn
2024-02-08 10:16
I get the snapshot bit, you can see it in a diff, you can also see diffs in the pact broker, diffs between distinct versions

miguel.heitor
2024-02-08 10:17
yeah, that second comment is my mindset

miguel.heitor
2024-02-08 10:18
i dont understand how generated contracts would be different in the pipeline though. (as long as I had run them in my local before pushing of course)

yousafn
2024-02-08 10:19
> as long as I had run them in my local before pushing of course That is manual effort on your part, that you or others might forget. You might not check in the updated files

yousafn
2024-02-08 10:19
if you have to caveat it ?

miguel.heitor
2024-02-08 10:21
okok. thank you for the explanation :slightly_smiling_face:

yousafn
2024-02-08 10:24
maybe you can solve that problem with pre-commit hooks, but just worth being aware. I think the TL;DR is local machines are thought to be _dirty_ in terms on the contents, and we trust CI more, and can associate a version with the contract, so we have high confidence on which commit the contract was associated with. and no worries, always happy to chat

miguel.heitor
2024-02-08 10:27
> and we trust CI more, and can associate a version with the contract, so we have high confidence on which commit the contract was associated with. actually this makes some more sense to me, thank you for the TL;DR

niels.schuette
2024-02-08 14:18
has joined #pact-js

jeremy.buchmann
2024-02-09 00:11
has joined #pact-js

rachel.green
2024-02-09 00:15
has joined #pact-js

jj.guo
2024-02-09 00:33
has joined #pact-js

dipali.gulhane
2024-02-09 07:01
has joined #pact-js

manoj.chaudhari
2024-02-09 09:13
has joined #pact-js

martha.chambers
2024-02-09 16:15
has joined #pact-js

adonay.berhe
2024-02-09 16:52
has joined #pact-js

camilo.morales
2024-02-09 16:52
has joined #pact-js

jonathan.barker
2024-02-12 08:56
has joined #pact-js

tobiasroland
2024-02-12 10:48
has joined #pact-js

samantha.lam
2024-02-12 12:32
has joined #pact-js

logi.ragnarsson
2024-02-12 15:22
has joined #pact-js

michal.patron
2024-02-13 10:41
has joined #pact-js

tomasz.fiechowski
2024-02-13 11:14
has joined #pact-js

coletaylor017
2024-02-13 19:50
has joined #pact-js

lachlan.austin
2024-02-13 22:44
has joined #pact-js

rejeesh.gangadharan
2024-02-14 00:55
has joined #pact-js

utku.kilincci01
2024-02-14 08:00
has joined #pact-js

ahmadlotfygamersfield
2024-02-14 14:38
has joined #pact-js

evan.hafers
2024-02-14 15:11
has joined #pact-js

wiktor2.karpinski
2024-02-15 09:31
has joined #pact-js

cae.vieira
2024-02-15 11:37
has joined #pact-js

m.barbosa
2024-02-15 13:54
has joined #pact-js

r_connolly
2024-02-15 20:22
has joined #pact-js

wally.yuen
2024-02-16 00:42
has joined #pact-js

david.montero
2024-02-16 10:29
has joined #pact-js

hristian.iliev
2024-02-16 10:37
has joined #pact-js

v-rybam-gri
2024-02-16 13:49
has joined #pact-js

msarayu1111
2024-02-16 13:49
has joined #pact-js

shivanirajebhosale16
2024-02-17 10:50
has joined #pact-js

maciej.harapinski
2024-02-19 09:42
has joined #pact-js

d.madureira
2024-02-19 14:17
has joined #pact-js

dpunna
2024-02-19 18:35
has joined #pact-js

michael.schmidt
2024-02-20 11:01
has joined #pact-js