diff --git a/README.md b/README.md index 7fe9b2c0d..5630160de 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ how to get going. - [Asynchronous API Testing](#asynchronous-api-testing) - [Consumer](#consumer) - [Provider (Producer)](#provider-producer) + - [Pact Broker Integration](#pact-broker-integration) - [Matching](#matching) - [Match common formats](#match-common-formats) - [Match based on type](#match-based-on-type) @@ -53,6 +54,8 @@ how to get going. - [Match by regular expression](#match-by-regular-expression) - [Tutorial (60 minutes)](#tutorial-60-minutes) - [Examples](#examples) + - [HTTP APIs](#http-apis) + - [Asynchronous APIs](#asynchronous-apis) - [Using Pact in non-Node environments](#using-pact-in-non-node-environments) - [Using Pact with Karma](#using-pact-with-karma) - [Using Pact with RequireJS](#using-pact-with-requirejs) @@ -437,7 +440,7 @@ The following test creates a contract for a Dog API handler: 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](/Users/mfellows/development/public/pact-js/src/dsl/message.ts) object along with other context, so the body must be retrieved via `content` attribute. + * The actual request body that Pact will send, will be contained within a [Message](https://github.com/pact-foundation/pact-js/tree/feat/message-pact/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` - 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. * In this case, we wrap the actual dogApiHandler with a convenience function `synchronousBodyHandler` provided by Pact, which Promisifies the handler and extracts the contents. @@ -492,6 +495,10 @@ describe("Message provider tests", () => { * 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. 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. +### Pact Broker Integration + +As per HTTP APIs, you can [publish contracts and verification results to a Broker](#publishing-pacts-to-a-broker). + ## Matching Matching makes your tests more expressive making your tests less brittle. @@ -654,6 +661,8 @@ Learn everything in Pact JS in 60 minutes: https://github.com/DiUS/pact-workshop ## Examples +### HTTP APIs + * [Complete Example (Node env)](https://github.com/pact-foundation/pact-js/tree/master/examples/e2e) * [Pact with AVA (Node env)](https://github.com/pact-foundation/pact-js/tree/master/examples/ava) * [Pact with Jest (Node env)](https://github.com/pact-foundation/pact-js/tree/master/examples/jest) @@ -661,7 +670,11 @@ Learn everything in Pact JS in 60 minutes: https://github.com/DiUS/pact-workshop * [Pact with Mocha](https://github.com/pact-foundation/pact-js/tree/master/examples/mocha) * [Pact with Karma + Jasmine](https://github.com/pact-foundation/pact-js/tree/master/karma/jasmine) * [Pact with Karma + Mocha](https://github.com/pact-foundation/pact-js/tree/master/karma/mocha) -* [Asynchronous messages](https://github.com/pact-foundation/pact-js/tree/master/examples/messages) + +### Asynchronous APIs + +* [Asynchronous messages](https://github.com/pact-foundation/pact-js/tree/feat/message-pact/examples/messages) +* [Serverless](https://github.com/pact-foundation/pact-js/tree/feat/message-pact/examples/serverless) [![asciicast](https://asciinema.org/a/105793.png)](https://asciinema.org/a/105793) diff --git a/examples/serverless/README.md b/examples/serverless/README.md index 091eba604..4cc29b054 100644 --- a/examples/serverless/README.md +++ b/examples/serverless/README.md @@ -2,7 +2,7 @@ ![serverless-logo](https://user-images.githubusercontent.com/53900/38163394-57ec9176-353f-11e8-80d1-b9f6d5f1773f.png) -Fictional application running using the [Serverless](https://github.com/serverless/serverless) framework. +Sample contract testing application running using the [Serverless](https://github.com/serverless/serverless) framework. The very basic architecture is as follows: @@ -49,6 +49,7 @@ Or individually: ``` npm run test:consumer +npm run test:publish # publish contracts to the broker npm run test:provider ``` @@ -56,21 +57,32 @@ npm run test:provider You can run this stack in AWS. It uses services within the [free tier](https://aws.amazon.com/free/?awsf.default=categories%23alwaysfree) to reduce potential costs. -To use any of the commandsn belowe, ensure you have valid [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) for your environment. - -Serverless +To use any of the commands below, ensure you have valid [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) for your environment. ### Pact Broker integration -Using the test broker at https://test.pact.dius.com.au (user/pass: `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` / `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`), we integrate the `can-i-deploy` facility, that ensure it is safe to deploy the consumer or provider before a change. +Using the test broker at https://test.pact.dius.com.au (user/pass: `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` / `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`), we make use of the [`can-i-deploy` tool](https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-results#querying) (available from the [Pact CLI suite](https://github.com/pact-foundation/pact-ruby-standalone/releases) but also bundled as part of `pact`), that ensures it is safe to deploy the consumer or provider before a releasing a change. -Whenever we verify a contract with Pact, the results are shared with the broker, which is able to determine compatibility between components. +Whenever we create, change or verify a contract with Pact, the results are shared with the broker, which is then able to determine compatibility between components at any point in time. -You can see the current state of verification by running one of: +You can see this in action by running one of the following: +```sh +npm run can-i-deploy # For both +npm run can-i-deploy:consumer # Just consumer +npm run can-i-deploy:provider # Yep, just the provider ``` -npm run can-i-deploy:consumer -npm run can-i-deploy:provider + +You will see something like: + +```sh +Computer says yes \o/ + +CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS? +---------------------|-----------|----------------------|-----------|--------- +SNSPactEventConsumer | 1.0.1 | SNSPactEventProvider | 1.0.0 | true + +All verification results are published and successful ``` ### Running deployment @@ -81,7 +93,7 @@ npm run deploy This will first check with `can-i-deploy`. If you want to skip this process, you can simply run: -``` +```sh serverless deploy -f provider serverless deploy -f consumer ``` diff --git a/examples/serverless/serverless-logo.png b/examples/serverless/serverless-logo.png deleted file mode 100644 index 906ca6cff..000000000 Binary files a/examples/serverless/serverless-logo.png and /dev/null differ diff --git a/package.json b/package.json index c8f1f45e7..59391f334 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pact-foundation/pact", - "version": "6.0.0-alpha.2", + "version": "6.0.0-alpha.3", "description": "Pact for all things Javascript", "main": "./pact.js", "types": "./pact.d.ts",