Hi, before I raise an issue I wanted to ask here. ...
# pact-js
r
Hi, before I raise an issue I wanted to ask here. In our API we have fields with "@id" or "@type". The are 2 problems with that. • We get this warning
pact-node@10.17.6: WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body']['someData']['pData']['items'][*]@['type']
• Weirdly pact is adding and removing the matching rule during every test run. So the pact is also changed every time
Copy code
"$.body.someData.pData.items[*].@id": {
            "match": "type"
          },
          "$.body.someData.pData.items[*].@type": {
            "match": "type"
          },
I also saw there is a similar issue with the pact-php. https://github.com/pact-foundation/pact-php/issues/162 , but there is no progress since 3 years. So my question is should I raise an issue in pact-js or try to push the pact-php issue?
t
I would push the one that you need fixed. This definitely seems like a bug
Weirdly pact is adding and removing the matching rule during every test run. So the pact is also changed every time
This is odd. Are you deleting the pact file before each run?
m
Just for clarification, the consumer test is in PHP and the verification is in JS - that right?
It’s possible that a later version of Pact JS will support that matching rule, but I’m not 100% sure on it (for clarity - it should be supported full stop, I just don’t know for sure that it is, and more improtantly, if the PHP library is serialising the correct format)
t
I bet the problem is that
@
has special meaning in jsonpath
r
This is odd. Are you deleting the pact file before each run?
No the pact is not deleted. Pact is updating it
t
You shouldn’t update it every time - I think there’s a note in the docs, you have to delete it
r
Just for clarification, the consumer test is in PHP and the verification is in JS - that right?
In my case the consumer is in JS and the provider is JAVA
t
before each test run
otherwise when you remove interactions, they stay around
@Matt (pactflow.io / pact-js / pact-go) I just played around with a jsonpath thing here - I believe Pact is supposed to write the query as
Copy code
$.body.someData.pData.items[*].`@type
(note the backtick before the
@
)
Also, I can’t find the note that you need to clear out the pacts in the documentation any more. I know it used to be there.
r
You shouldn’t update it every time - I think there’s a note in the docs, you have to delete it
Could I also use
pactfile_write_mode
with
override
or is deleting it a better way?
t
You need to delete it I think - I’m personally not familiar with the new write modes, so I don’t know what override does
(For context, I haven’t maintained pact since 10.x)
I think the right place to open an issue about matching properties starting with @ is pact-reference. I’m on mobile, but let me get you a link
I would include: • pact-js version(s) • Pact rust version (you can get this from the metadata field in your broken pact file) • The working json path expression I posted above • Also mention that the interaction wasn’t overwriting correctly (this is probably also some kind of bug, but I don’t know if it’s related)
thankyou 1
You should be clearing out the pacts each time, but if you don’t, then re-running the same test shouldn’t produce a different output
I don’t think the rust pact core which backs pact-js knows when you start and finish the test run, so I think if you can get it to overwrite the file, you’ll only have one interaction. A current maintainer will be able to tell you
m
Looking at the output, it looks like Robert is still using the 9.x.x line of Pact (they are Ruby warnings we are seeing there)
Also, I can’t find the note that you need to clear out the pacts in the documentation any more. I know it used to be there.
Thanks. It’s in the migration guide, but new users won’t read that
👍 1
I don’t think the rust pact core which backs pact-js knows when you start and finish the test run, so I think if you can get it to overwrite the file, you’ll only have one interaction. A current maintainer will be able to tell you
the rust core only has one mode - update the existing pact (analogous to
merge
). The reason is that you can run tests in parallel and so Pact doesn’t know about when the tests start/stop. It just knows about a test, and where to write the interaction
t
Ah, I got confused, because it says pact-node@10, and I forgot that pact-node didn’t exist after pact-js@10
(Which was something I changed, I believe 😅 )
😆 1
m
hahah all good. I often forget which
pact-node
version is which, but I definitely remember those Ruby warnings (they can be quite unreliable)
I’m also not sure they are JSON path exactly, but JSON path-like. That’s outside of my direct knowledge though, so I could be spewing additional rubbish there
🤔 1
t
You’re right! You could say it’s a limitation of the spec: From V2:
Pact does not support the full JSON path expressions, only ones that match the following rules:
• All paths start with a dollar ($), representing the root.
• All path elements are either separated by periods (.) or use the JSON path bracket notation (square brackets and single quotes around the values: e.g. [‘x.y’]), except array indices which use square brackets ([]). For elements where the value contains white space or non-alphanumeric characters, the JSON path bracket notation ([‘’]) should be used.
• The second element of the path is the http type that the matcher is applied to (e.g., $.body or $.header).
• Path elements represent keys.
• A star (*) can be used to match all keys of a map or all items of an array (one level only).
This is probably the most relevant bit:
For elements where the value contains white space or non-alphanumeric characters, the JSON path bracket notation ([‘’]) should be used.
I reckon whether not supporting properties starting with
@
is a bug or would need a spec change is an @uglyog question.
🤔 1
For those playing at home, I checked later versions too - V3 introduces no change to the paths in a body - here’s the quote:
Jsonpath will still be used internally for matching body elements.
V4 doesn’t mention jsonpath at all.
👍 1
r
Some update from side 🙂. It seems now to work with the current version of pact-js or with deleting the old pact file.
🙌 2
Now I have just the problem that the new pact-js version needs python and I don't have python on the docker image but that's another problem 😅
👍 1