Skip to content

Commit

Permalink
Copy edit pass on /docs
Browse files Browse the repository at this point in the history
  • Loading branch information
griffinmyers committed Feb 27, 2023
1 parent 5c53b05 commit fff3436
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ A handle on the HTTP mock server.

#### `mock(options): Mock`

Declares a mock with the server.
Declares a mock with the server. Will match at most one request.

All functions under `req` are passed the value at their position in `options`
and are expected to return a Boolean. For example, a function at
Expand All @@ -95,7 +95,7 @@ undefined.
* **`method`**: (`Comparable`) Request method.
* **`pathname`**: (`Comparable`) Request pathname with leading `/` and no
querystring.
* **`query`**: (`Comparable`) Request querystring including leading `?`
* **`query`**: (`Comparable`) Request querystring including leading `?`.
* **`headers`**: (`Object` | `Function`) Request headers.
* **`$key`**: (`Comparable` | `Array<Comparable>`) An individual header,
case sensitive. If multiple headers with the same name are expected,
Expand All @@ -115,7 +115,7 @@ undefined.
to inject before sending the response body.
* **`destroySocket`**: (`Boolean` | `Function`) Whether or not to suddenly
hang up the socket in the middle of serving a request. Helpful when
testing error handling logic in an application
testing error handling logic in an application.

###### Returns

Expand Down Expand Up @@ -276,7 +276,7 @@ dep.mock({
method: 'POST',
pathname: Buffer.from('/bloop', 'utf8'),
body: /^blo+p$/,
headers: { 'content-type': c.endsWith('json'), 'content-length': /d+/ }
headers: { 'content-type': c => c.endsWith('json'), 'content-length': /d+/ }
}
});
```
Expand Down
23 changes: 12 additions & 11 deletions docs/tcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ like a `for` loop.

When a new connection with wirepig is established, it will start buffering all
writes it receives internally. With each write, it will evaluate all mocks
registered with the server to see if there is a match against all the data its
received so far.
registered with the server to see if there is a match against all the data it's
received on that connection so far.

When a match is found, wirepig will write the response back over the socket and
clear its internal write buffer. Subsequent writes, and thus mock matching
Expand Down Expand Up @@ -88,12 +88,12 @@ A handle on the TCP mock server.

#### `mock(options): Mock`

Declares a mock with the server.
Declares a mock with the server. Will match at most one request.

All functions under `res` are passed the current data written to the socket and
expected to return the expected value in its position. For example, a function at `options.res.body` will be passed the
request and request body and should return either a String, Buffer, or
undefined.
expected to return the expected value in its position. For example, a function
at `options.res.body` will be passed current socket data and should return
either a String, Buffer, or undefined.

###### Arguments

Expand Down Expand Up @@ -162,7 +162,7 @@ first data written over a socket.

#### Basic Request/Response Pair

This example shows the expected request response pair from issuing a `GET`
This example shows the expected request/response pair from issuing a `GET`
request to a redis server.

```js
Expand Down Expand Up @@ -222,7 +222,7 @@ Some protocols expect the server to be the first to write to a connection (mysql
is a good example).

To handle this, we can declare a mock with the `init` key. When a wirepig
receives a new connection, it'll find any available "init" mock and write it
receives a new connection, it'll find the first pending "init" mock and write it
to the socket.

```js
Expand All @@ -236,7 +236,8 @@ The previous example showed two mocks we expected to occur over the same
connection. However, the way we've written it, the first could have been
satisfied by one connection, and the second by another.

To "pin" mocks to a given connection, we can use the `Mock.mock()` function:
To "pin" mocks to a given connection, we can use the
[`Mock.mock()`](#mockoptions-mock-1) function:

```js
const handshake = dep.mock({
Expand All @@ -249,7 +250,7 @@ const query = handshake.mock({
```

Here, `query` will only match a write of `SELECT 1 + 1;` if it occurred on the
same connection that handshake used.
same connection that `handshake used.

#### Many Mocks and Many Writes

Expand All @@ -261,7 +262,7 @@ dep.mock({ req: 'abcd', res: 'bloop' });
dep.mock({ req: '1234', res: 'bleep' });
````

Assume we establish a single connection with wirepig, the do the following:
Assume we establish a single connection with wirepig, then do the following:

1. We write `ab` to the socket. Wirepig will buffer `ab` and check all its mocks
for a match. Since `ab` doesn't match `abcd` or `1234`, it does nothing.
Expand Down

0 comments on commit fff3436

Please sign in to comment.