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