Skip to content

Commit

Permalink
chore: synced pact-js docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Github Action committed Oct 6, 2023
1 parent b06df2d commit b4a393b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions website/docs/implementation_guides/javascript/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ custom_edit_url: https://github.com/pact-foundation/pact-js/edit/master/CONTRIBU
---
<!-- This file has been synced from the pact-foundation/pact-js repository. Please do not edit it directly. The URL of the source file can be found in the custom_edit_url value above -->

We love contributors! Pact-js is maintained and contrbuted to by developers just like you.
We love contributors! Pact-js is maintained and contributed to by developers just like you.

We have a development channel in the pact-foundation [slack] (`#pact-js-development`).

Expand All @@ -21,9 +21,9 @@ Please provide the following information with your issue to enable us to respond

## Key Branches

* `master` - this is the current main version supporting the 11.x.x release line. Most investment will be here, including major new features, enhancements, bug fixes, security patches etc.
* `master` - this is the current main version supporting the 11.x.x release line. Most investment will be here, including major new features, enhancements, bug fixes, security patches, etc.
* `9.x.x` - this is the previous major version supporting the 9.x.x release line. Critical security patches and bug fixes will be provided as a priority.
* There is no tracking or release branch for 10.x.x at this stage. Most users can be encouraged to jump straight to 11.x.x noting the single breaking change (see the migration guide)
* There is no tracking or release branch for 10.x.x at this stage. Most users can be encouraged to jump straight to 11.x.x noting the single breaking change (see the migration guide).

## I want to contribute code but don't know where to start

Expand Down Expand Up @@ -83,10 +83,10 @@ The recommended approach is to configure Prettier to format on save in your edit

## Pull requests

- Please write tests for any changes
- Please follow existing code style and conventions
- Please separate unrelated changes into multiple pull requests
- For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change
- Please write tests for any changes.
- Please follow existing code style and conventions.
- Please separate unrelated changes into multiple pull requests.
- For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change.

[stackoverflow]: https://stackoverflow.com/questions/tagged/pact
[examples]: https://github.com/pact-foundation/pact-js/tree/master/examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pact is a consumer-driven contract testing tool, which is a fancy way of saying

The process looks like this:

![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/summary.png?raw=true)
![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/summary.png)

1. The consumer writes a unit test of its behaviour using a Mock provided by Pact
1. Pact writes the interactions into a contract file (as a JSON document)
Expand Down
24 changes: 12 additions & 12 deletions website/docs/implementation_guides/javascript/docs/messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ Pact is a consumer-driven contract testing tool, which is a fancy way of saying

The process looks like this on the consumer side:

![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/message-consumer.png?raw=true)
![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/message-consumer.png)

The process looks like this on the provider (producer) side:

![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/message-provider.png?raw=true)
![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/message-provider.png)

1. The consumer writes a unit test of its behaviour using a Mock provided by Pact
1. Pact writes the interactions into a contract file (as a JSON document)
1. The consumer publishes the contract to a broker (or shares the file in some other way)
1. Pact retrieves the contracts and replays the requests against a locally running provider
1. The consumer writes a unit test of its behaviour using a Mock provided by Pact.
1. Pact writes the interactions into a contract file (as a JSON document).
1. The consumer publishes the contract to a broker (or shares the file in some other way).
1. Pact retrieves the contracts and replays the requests against a locally running provider.
1. The provider should stub out its dependencies during a Pact test, to ensure tests are fast and more deterministic.

In this document, we will cover steps 1-3.
In this document, we will cover steps 1 and 2.

### Consumer

Expand Down Expand Up @@ -97,8 +97,8 @@ describe("receive dog event", () => {
1. The Dog API - a contrived API handler example. Expects a dog object and throws an `Error` if it can't handle it.
- In most applications, some form of transactionality exists and communication with a MQ/broker happens.
- It's important we separate out the protocol bits from the message handling bits, so that we can test that in isolation.
1. Creates the MessageConsumer class
1. Setup the expectations for the consumer - here we expect a `dog` object with three fields
1. Creates the MessageConsumer class.
1. Setup the expectations for the consumer - here we expect a `dog` object with three fields.
1. Pact will send the message to your message handler. If the handler returns a successful promise, the message is saved, otherwise the test fails. There are a few key things to consider:
- The actual request body that Pact will send, will be contained within a [Message](https://github.com/pact-foundation/pact-js/tree/master/src/dsl/message.ts) object along with other context, so the body must be retrieved via `content` attribute.
- All handlers to be tested must be of the shape `(m: Message) => Promise<any>` - that is, they must accept a `Message` and return a `Promise`. This is how we get around all of the various protocols, and will often require a lightweight adapter function to convert it.
Expand Down Expand Up @@ -157,7 +157,7 @@ describe("Message provider tests", () => {

**Explanation**:

1. Our API producer contains a single function `createDog` which is responsible for generating the message that will be sent to the consumer via some message queue
1. We configure Pact to stand-in for the queue. The most important bit here is the `messageProviders` block
- Similar to the Consumer tests, we map the various interactions that are going to be verified as denoted by their `description` field. In this case, `a request for a dog`, maps to the `createDog` handler. Notice how this matches the original Consumer test. We are using the `providerWithMetadata` function because we are also going to validate message metadata (in this case, the queue the message will be sent on)
1. Our API producer contains a single function `createDog` which is responsible for generating the message that will be sent to the consumer via some message queue.
1. We configure Pact to stand-in for the queue. The most important bit here is the `messageProviders` block.
- Similar to the Consumer tests, we map the various interactions that are going to be verified as denoted by their `description` field. In this case, `a request for a dog`, maps to the `createDog` handler. Notice how this matches the original Consumer test. We are using the `providerWithMetadata` function because we are also going to validate message metadata (in this case, the queue the message will be sent on).
1. We can now run the verification process. Pact will read all of the interactions specified by its consumer, and invoke each function that is responsible for generating that message.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pact is a consumer-driven contract testing tool, which is a fancy way of saying

The process looks like this:

![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/summary.png?raw=true)
![diagram](https://github.com/pact-foundation/pact-js/blob/master/docs/diagrams/summary.png)

1. The consumer writes a unit test of its behaviour using a Mock provided by Pact
1. Pact writes the interactions into a contract file (as a JSON document)
Expand Down

0 comments on commit b4a393b

Please sign in to comment.