pact-js | Pact is a contract testing framework | Testing library
kandi X-RAY | pact-js Summary
kandi X-RAY | pact-js Summary
Implementation of the consumer driven contract library Pact for Javascript.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pact-js
pact-js Key Features
pact-js Examples and Code Snippets
Community Discussions
Trending Discussions on pact-js
QUESTION
I'm using Pact to mock our server side with graphql(Apollo) client. After trying some examples manually I did notice that majority of our current code performs exports like this:
...ANSWER
Answered 2022-Mar-23 at 09:34Use print
from the graphql
package (which you should probably already have installed).
QUESTION
I'm working on a system that calls external APIs, some are owned by my company and others are not.
My system is composed of an HTTP interface that takes orders and publishes them into a message queue in order to run an operation chain. My system is composed of 3 NodeJS processes (1 for HTTP, 2 message queue consumers), 2 databases and a message queue.
As I develop my application it becomes hard to test all the scenarios covered by my system (even tho I have unit tests). To ensure that all the components are working together, I am writing specifications using the Gherkin language and cucumber js.
To test the system, I want to be as close as the deployment environment, so I start all my system including the databases, the NodeJS processes and the message queue with docker-compose. All of the components of the system are communicating through a docker network defined in the docker-compose configuration.
The issue is that I can't make sure that all of the external APIs are in the right state ready to accept my request and that they will respond in a way that's interesting for my test steps.
So, I thought about using a Mock server for each of my dependencies and discovered pact.io. As I understand, Pact allows me to write contracts and start a mock server so my system can then run HTTP requests against the mock server. Pact also allows me to give the contract to the service provider so it can also run the contract against the real app to see if it really works.
I saw the examples, in javascript, and I am able to start a mock service, provide it an interaction, verify the interaction and close the mock service. (JS with mocha example)
My issue is that I want my system to be as close as the production so I want it to access the Pact mock service through my docker network. I saw a Pact CLI docker image to run the pact mock service (Pact CLI docker image) but once my mock server is dockerized, I lose the control that I had with the JS wrapper to add new interactions.
Also, I don't want to write pact files, I want to add interactions at the time my tests are running otherwise I will declare the test data twice (once in the cucumber tests scenarios and once in the pact files).
My questions are:
Is there a way to bind the JS wrapper to an existing mock service, a dockerize one? When using the docker pact image, is there a way to add interaction at run time? Is pact the right tool to use since I just need a mock service?
EditI just create a sandbox env to see what could be done with the NodeJS wrapper. It seems that you can create a mock service using docker and them control it via the NodeJS wrapper.
...ANSWER
Answered 2022-Feb-21 at 23:37So, I thought about using a Mock server for each of my dependencies and discovered pact.io. As I understand, Pact allows me to write contracts and start a mock server so my system can then run HTTP requests against the mock server. Pact also allows me to give the contract to the service provider so it can also run the contract against the real app to see if it really works.
Yes, that's correct. Pact can probably be considered as a unit testing tool for your API client, that uses contract testing to ensure the mocks are valid.
If you're using Pact just for mocking, you're missing out on all of the key benefits though.
Using Pact at such a high level test is considered bad practice, and as you can see, is difficult to do (you're working against the way it is intended to be used).
I would worry less about overlapping tests (end-to-end tests will always double up with other layers testing by design), and concern yourself more about ensuring each of the API contracts are covered by Pact. These tests will run much faster, are more precise in what the test and are less flakey.
This way, you can reduce the scope of your end-to-end BDD scenarios to the key ones and that should reduce the maintenance cost.
QUESTION
We have 2 services where one is the consumer of the other. The consumer is written in Java and the provider is written in JavaScript.
On the consumer side we've defined a consumer-contract-test using pact-jvm and we're able to generate a contract. In this contract the response is defined like:
...ANSWER
Answered 2020-Sep-01 at 23:58MessageProviderPact
is for message queue type interactions, not HTTP interactions. I think you need the standard Verifier
class (https://github.com/pact-foundation/pact-js/#provider-api-testing):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pact-js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page