Comparing version 0.15.4 to 0.15.5
{ | ||
"name": "mockyeah", | ||
"version": "0.15.4", | ||
"description": "An invaluable service mocking platform built on Express.", | ||
"version": "0.15.5", | ||
"description": "A simple but powerful web service mocking utility.", | ||
"main": "index.js", | ||
@@ -19,11 +19,28 @@ "scripts": { | ||
"keywords": [ | ||
"assert", | ||
"assertion", | ||
"bdd", | ||
"cli", | ||
"express", | ||
"expect", | ||
"expectation", | ||
"fixture", | ||
"http", | ||
"integration", | ||
"jest", | ||
"mocha", | ||
"mock", | ||
"mocks", | ||
"mock services", | ||
"mock integration", | ||
"mock server", | ||
"mock service", | ||
"mock http", | ||
"mockserver", | ||
"mocking", | ||
"record", | ||
"request", | ||
"server", | ||
"service", | ||
"sinon", | ||
"snapshot", | ||
"stub", | ||
"supertest", | ||
@@ -33,5 +50,7 @@ "superagent", | ||
"test", | ||
"test double", | ||
"test framework", | ||
"testing", | ||
"web services" | ||
"utility", | ||
"web service" | ||
], | ||
@@ -38,0 +57,0 @@ "devDependencies": { |
210
README.md
@@ -5,5 +5,5 @@ # mockyeah [![Build Status](https://travis-ci.org/ryanricard/mockyeah.svg)](https://travis-ci.org/ryanricard/mockyeah) | ||
Testing is difficult when you don't have control of your data. This project puts you in complete control, enabling you to implement __real mock web services__ with ease. Real mock services means you have control of response payloads, HTTP Status Codes, response latency, and more. | ||
Testing is difficult when you don't have control of your data. mockyeah puts you in complete control, enabling you to implement __real mock web services__ with ease. Real mock services means you have control of response payloads, HTTP Status Codes, response latency, and more. | ||
Have a requirement to implement specific behavior when a service is slow to respond or a server returns an unexpected status code? No problem! This platform makes developing for such requirements easy. | ||
Have a requirement to implement specific behavior when a service is slow to respond or a server returns an unexpected status code? No problem! mockyeah makes developing for such requirements easy. | ||
@@ -18,184 +18,13 @@ ## Install | ||
- [Introductory tutorial](#introductory-tutorial) | ||
- [Testing example](#testing-example) | ||
- [Testing with mockyeah](#testing-with-mockyeah) | ||
- [Configuration](https://github.com/ryanricard/mockyeah/wiki/Configuration) | ||
## API | ||
### Mock service creation API | ||
__mockyeah.get(path, options)__<br/> | ||
__mockyeah.put(path, options)__<br/> | ||
__mockyeah.post(path, options)__<br/> | ||
__mockyeah.delete(path, options)__<br/> | ||
__mockyeah.all(path, options)__<br/> | ||
- [Mock Services](https://github.com/ryanricard/mockyeah/wiki/Mock-Services) | ||
- [Server Management](https://github.com/ryanricard/mockyeah/wiki/Server-Management) | ||
- [Mock Expectations](https://github.com/ryanricard/mockyeah/wiki/Mock-Expectations) | ||
- [Service Snapshots](https://github.com/ryanricard/mockyeah/wiki/Service-Snapshots) | ||
Each of the methods creates a mock service with a HTTP verb matching its respective method name. | ||
#### Parameters | ||
##### Path `String` | ||
Path to which to mount service. Fully supports all Express path matching options. | ||
##### Options `Object` | ||
Response options informing mockyeah how to respond to matching requests. Supported options: | ||
__One of the following options may be used per service:__ | ||
- `filePath` (`String`; optional) - File with contents to include in response body. Assumes response Content-Type of file type. | ||
- `fixture` (`String`; optional) - Fixture file with contents to include in response body. Assumes response Content-Type of file type. Default fixture file location is `./fixtures` in your project. | ||
- `html` (`String`; optional) - HTML to include in response body. Assumes response Content-Type of `text/html`. | ||
- `json` (`Object`; optional) - JSON to include in response body. Assumes response Content-Type of `application/json`. | ||
- `raw` (`String`; optional) - Text to include in response body. Content-Type is the default Express type if not specified in header. | ||
- `text` (`String`; optional) - Text to include in response body. Assumes response Content-Type of `text/plain`. | ||
__Additional options:__ | ||
- `headers` (`Object`; optional) - Header key value pairs to include in response. | ||
- `latency` (`Number` in Milliseconds; optional) - Used to control the response timing of a response. | ||
- `type` (`String`; optional) - Content-Type HTTP header to return with response. Proxies option to Express response method `res.type(type)`; more info here: http://expressjs.com/en/4x/api.html#res.type | ||
- `status` (`String`; optional; default: `200`) - HTTP response status code. | ||
### Service capture recording and playback | ||
__mockyeah.record(name)__ | ||
`name` (`String`; required) Directory name to save service responses recordings | ||
(i.e. `./mockyeah/[recording name]`). | ||
Configures mockyeah to proxy and record service requests. Recorded responses | ||
are written to `./mockyeah`. To use this feature, you must update | ||
the service addresses in your application to proxy through mockyeah. Here is an | ||
example of an address configured for recording: | ||
``` | ||
http://localhost:[mockyeah port]/http://example.com/your/service/url | ||
``` | ||
__mockyeah.play(name)__ | ||
`name` (`String`; required) Directory name from which to mount contained | ||
service responses recordings (i.e. `./mockyeah/[recording name]`). | ||
Mounts each service response captured during a recording. Each service response | ||
will be mounted with exact same payload, headers, status, and latency as | ||
experienced during recording. This behavior may be changed by altering the values | ||
in the captured service response file. | ||
Here is an example of a service response file: | ||
```json | ||
{ | ||
"method": "GET", | ||
"url": "http://example.com/some/service", | ||
"path": "/some/service", | ||
"options": { | ||
"headers": { | ||
"x-powered-by": "Express", | ||
"content-type": "text/plain; charset=utf-8", | ||
"content-length": "12", | ||
"etag": "W/\"5-iwTV43ddKY54RV78XKQE1Q\"", | ||
"date": "Sun, 21 Feb 2016 06:17:49 GMT", | ||
"connection": "close" | ||
}, | ||
"status": 200, | ||
"raw": "Hello world!", | ||
"latency": 57 | ||
} | ||
} | ||
``` | ||
Pseudo recordings may be created manually to ease repetitive setup of multiple | ||
services. Here are the steps to creating a pseudo recording: | ||
1. Create a recording directory (e.g. `./mockyeah/pseudo-example`) | ||
2. Add one or more JSON files containing the following properties, at minimum: | ||
```json | ||
{ | ||
"method": "GET", | ||
"path": "/some/service", | ||
"options": { | ||
"text": "Hello world!" | ||
} | ||
} | ||
``` | ||
See [Mock service creation API](#Mock-service-creation-API) for details on supported `options`. | ||
3. Play your pseudo recording. | ||
```js | ||
require('mockyeah').play('pseudo-example'); | ||
``` | ||
4. That's it! | ||
### Mock service and server management | ||
__mockyeah.reset()__ | ||
Removes all mounted mock services. Best practice is to execute `.reset()` in an after test hook. Example usage with Mocha: | ||
```js | ||
// unmounts all mounted services after each test | ||
afterEach(() => mockyeah.reset()); | ||
``` | ||
You may remove specific services by passing paths matching services to unmount. Example: | ||
```js | ||
mockyeah.get('/foo-1', { text: 'bar' }); | ||
mockyeah.get('/foo-2', { text: 'bar' }); | ||
mockyeah.get('/foo-3', { text: 'bar' }); | ||
// unmounts only /foo-1 and /foo-2 | ||
mockyeah.reset('/foo-1', '/bar-2'); | ||
``` | ||
__mockyeah.close()__ | ||
Stops mockyeah Express server. Useful when running mockyeah with a file watcher. | ||
mockyeah will attempt to start a new instance of Express with each iteration of | ||
test execution. After all tests run, `mockyeah.close()` should be called to | ||
shutdown mockyeah's Express server. Failing to do so will likely result in | ||
`EADDRINUSE` exceptions. This is due to mockyeah attempting to start a server on | ||
an occupied port. | ||
### mockyeah configuration | ||
__Default `.mockyeah` configuration:__ | ||
```json | ||
{ | ||
"name": "mockyeah", | ||
"host": "localhost", | ||
"port": 4001, | ||
"fixturesDir": "./fixtures", | ||
"capturesDir": "./mockyeah", | ||
"output": true, | ||
"journal": false, | ||
"verbose": false | ||
} | ||
``` | ||
__Configuration options:__ | ||
- `name`: Used to identify the origin of logged output. | ||
- `host`: Host on which mockyeah will run. | ||
- `port`: Port on which mockyeah will run. | ||
- `fixturesDir`: Relative path to the fixtures directory. | ||
- `capturesDir`: Relative path to the captures directory. | ||
- `output`: Boolean to toggle mockyeah generated output written to stdout. | ||
- `journal`: Boolean to toggle request journaling. Example: | ||
``` | ||
[mockyeah][14:54:21][REQUEST][JOURNAL] { | ||
"callCount": 1, | ||
"url": "/foo?bar=baa", | ||
"fullUrl": "http://localhost:4001/foo?bar=baa", | ||
"clientIp": "127.0.0.1", | ||
"method": "GET", | ||
"headers": { | ||
"host": "localhost:4001", | ||
"user-agent": "curl/7.43.0", | ||
"accept": "*/*" | ||
}, | ||
"query": { | ||
"bar": "baa" | ||
}, | ||
"body": {} | ||
} | ||
``` | ||
- `verbose`: Boolean to toggle verbosity of mockyeah generated output. | ||
Overriding any of these configurations can be done by placing a `.mockyeah` | ||
file in root of the project and adding the key value pair that needs to be updated. | ||
This file should be written using standard `JSON`. | ||
### Introductory tutorial | ||
## Introductory tutorial | ||
1. Create an example project and initialized with NPM | ||
@@ -231,3 +60,3 @@ ```shell | ||
### Testing example | ||
## Testing with mockyeah | ||
```js | ||
@@ -266,21 +95,2 @@ const request = require('supertest')('http://localhost:4001'); | ||
## Package dependencies | ||
- mockyeah was built and tested with Node v4.2.3 | ||
- [Mocha](https://mochajs.org/) | ||
## Contributing | ||
### Getting started | ||
Installing project and dependencies | ||
```shell | ||
# download project | ||
$ git clone git@github.com:ryanricard/mockyeah.git | ||
$ cd mockyeah | ||
# install proper Node version | ||
$ nvm install v4.2.3 | ||
$ nvm use | ||
# if tests pass, you're good to go | ||
$ npm test | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65
1696
322428
93