Hey, I was wondering if you think it's a good idea...
# general
c
Hey, I was wondering if you think it's a good idea to write e2e with e.g. cucumber-js and use pact in the background to 'mock' the services I'm communicating with. So basically I have my e2e, use the
.feature
files to control the 'given' behaviour of pact with the 'given' of cucumber - and in the end I call 'writePact' to get my output The cucumber would execute selenium/puppeteer UI actions šŸ™‚
m
You could do it, the concern would be the granularity you are testing. Unit tests have the ability to go more granular to test all of the scenarios you need. If you’re doing this at the e2e level, you may not be able to get that level of specificity, and therefore only cover some of the cases. Or, you end up writing too many e2es
t
Yeah, my gut is this would be a pain to maintain. But, I’d be interested to hear how it goes if you try it
c
I think due to the 'advertisement' pact is doing with 'cut e2e in smaller pieces' this would be exactly the use case, but I remember the docs also used to contain a warning exactly against hat. From a testing strategy I usually try to only do unit tests for edge-cases that are hard to test from an e2e perspective. Too many unit tests make the code rigid and therefore refactoring hard
Right now I'm only building this for an application that's in the supporting domain, which currently only covers 2 interactions with one endpoint - but depending on my learnings I'd roll it out to different parts of our product
šŸ‘ 1
m
I think due to the ā€˜advertisement’ pact is doing with ā€˜cut e2e in smaller pieces’ this would be exactly the use case, but I remember the docs also used to contain a warning exactly against hat.
the main way we do that is to improve the ā€œbaseā€ of the pyramid - more tests, reliability etc. lower down gives you more specificity, speed etc. Most orgs have unwieldy e2e tests, because they try to do too much with them. By adding contract testing at the base, you can usually reduce your e2e at the top. Often to the point you don’t need them at all
This YT video is a good way of describing our objective:

https://www.youtube.com/watch?v=QFCHSEHgqFEā–¾

ā¤ļø 1
t
You might also be interested in this answer I wrote a while back that talks about end-to-end tests and pact
šŸ™Œ 1
c
OK so I got it running and it's actually very nice. Basically I'm doing black-box texting in BDD style where Cucumber + Puppeteer do some click testing, and in the end it spawn some pact files which I upload to our broker. But there is something I find inconvinient with the pact-js api. In the past I remember it was possible to start a pact server and add interactions - in the end verify them. Now the api adds a pact and then every verification spawns a new server. Here I neede to hack my way around it and collect the requests with nock and forward them to the pact server. Is there a way to use the old approach?
t
I’m on mobile, so short response- but can you collect the requests you want to mock and send them all at once?
Also - sounds cool! Do you have a link we can check out?
c
sadly I've built this for a company internal thing - If I find the time I can create a public example on my private sheet
t
It sounds like it would be generally useful - maybe your company might want to open source it (I know this isn’t always easy or practical, of course)
A good argument would be future proofing- if you have a custom use of an open source tool, but keep it private, it might not stay compatible
c
I wouldn't consider this one an open source tool - It would be more of a collection of configurations / experient šŸ™‚ - Maybe I find the time on the weekend to recreate it as an pet-shop example
ā¤ļø 1