stubborn-ws
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -15,4 +15,4 @@ ## Classes | ||
<dd></dd> | ||
<dt><a href="#HeadersDefinition">HeadersDefinition</a> : <code>object.<string, (string|Regexp|function()|null)></code></dt> | ||
<dd><p>key/value object. Key is the header name, value is the header definition | ||
<dt><a href="#HeadersDefinition">HeadersDefinition</a> : <code>string</code> | <code>Regexp</code> | <code>function</code> | <code>null</code></dt> | ||
<dd><p>Definition | ||
The header definition can be a <code>string</code>, a <code>Regexp</code>, a <code>function</code> or <code>null</code></p> | ||
@@ -26,3 +26,3 @@ <ul> | ||
</dd> | ||
<dt><a href="#QueryParametersDefinition">QueryParametersDefinition</a> : <code>Object.<string, (string|Regexp|function()|null)></code></dt> | ||
<dt><a href="#QueryParametersDefinition">QueryParametersDefinition</a> : <code>Object.<string, Definition></code></dt> | ||
<dd><p>key/value object. Key is the query parameter name, value is the parameter definition | ||
@@ -37,3 +37,3 @@ The parameter definition can be a <code>string</code>, a <code>Regexp</code>, a <code>function</code> or <code>null</code></p> | ||
</dd> | ||
<dt><a href="#BodyDefinition">BodyDefinition</a> : <code>string</code> | <code>Array</code> | <code>Object.<string, (string|Regexp|Body|function()|null)></code></dt> | ||
<dt><a href="#BodyDefinition">BodyDefinition</a> : <code>string</code> | <code>Array</code> | <code>Object.<string, (Definition|Body)></code></dt> | ||
<dd><p>Body can be a string, an array or a key/mixed object where values can be a <code>string</code>, a <code>Regexp</code>, a <code>function</code>, object, Array or <code>null</code></p> | ||
@@ -59,7 +59,10 @@ <ul> | ||
* [.setHeaders(headers)](#Route+setHeaders) ⇒ <code>this</code> | ||
* [.setHeader(header, definition)](#Route+setHeader) ⇒ <code>this</code> | ||
* [.setQueryParameters(query)](#Route+setQueryParameters) ⇒ <code>this</code> | ||
* [.setQueryParameter(queryParameter, definition)](#Route+setQueryParameter) ⇒ <code>this</code> | ||
* [.setBody(body)](#Route+setBody) ⇒ <code>this</code> | ||
* [.setResponseStatusCode(statusCode)](#Route+setResponseStatusCode) ⇒ <code>this</code> | ||
* [.setResponseBody(body)](#Route+setResponseBody) ⇒ <code>this</code> | ||
* [.setResponseHeaders(body)](#Route+setResponseHeaders) ⇒ <code>this</code> | ||
* [.setResponseHeaders(headers)](#Route+setResponseHeaders) ⇒ <code>this</code> | ||
* [.setResponseHeader(header, value)](#Route+setResponseHeader) ⇒ <code>this</code> | ||
@@ -101,2 +104,21 @@ <a name="Route+getDefinition"></a> | ||
``` | ||
<a name="Route+setHeader"></a> | ||
### route.setHeader(header, definition) ⇒ <code>this</code> | ||
Set a specific header definition. | ||
**Kind**: instance method of [<code>Route</code>](#Route) | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| header | <code>String</code> | Header name | | ||
| definition | <code>Definition</code> | Header definition | | ||
**Example** | ||
```js | ||
stubborn | ||
.get('/match') | ||
.setHeader('Authorization', 'BEARER'); | ||
``` | ||
<a name="Route+setQueryParameters"></a> | ||
@@ -131,2 +153,20 @@ | ||
``` | ||
<a name="Route+setQueryParameter"></a> | ||
### route.setQueryParameter(queryParameter, definition) ⇒ <code>this</code> | ||
Set a specific query parameter | ||
**Kind**: instance method of [<code>Route</code>](#Route) | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| queryParameter | <code>String</code> | Query parameters name | | ||
| definition | <code>Definition</code> | Query parameter definition | | ||
**Example** | ||
```js | ||
stubborn | ||
.get('/match') | ||
.setQueryParameter('page', '100'); | ||
``` | ||
<a name="Route+setBody"></a> | ||
@@ -201,4 +241,4 @@ | ||
### route.setResponseHeaders(body) ⇒ <code>this</code> | ||
Set the response header | ||
### route.setResponseHeaders(headers) ⇒ <code>this</code> | ||
Set the response headers | ||
key/value object. If value is a function it will receive the request as parameter | ||
@@ -217,4 +257,21 @@ ```js | ||
| --- | --- | | ||
| body | <code>Object.<mixed></code> | | ||
| headers | <code>Object.<mixed></code> | | ||
<a name="Route+setResponseHeader"></a> | ||
### route.setResponseHeader(header, value) ⇒ <code>this</code> | ||
Set a response header | ||
```js | ||
ws.get('/resource') | ||
.setResponseHeader('Content-type', 'application/json'); | ||
``` | ||
**Kind**: instance method of [<code>Route</code>](#Route) | ||
| Param | Type | | ||
| --- | --- | | ||
| header | <code>String</code> | | ||
| value | <code>String</code> \| <code>function</code> | | ||
<a name="Stubborn"></a> | ||
@@ -347,4 +404,4 @@ | ||
## HeadersDefinition : <code>object.<string, (string\|Regexp\|function()\|null)></code> | ||
key/value object. Key is the header name, value is the header definition | ||
## HeadersDefinition : <code>string</code> \| <code>Regexp</code> \| <code>function</code> \| <code>null</code> | ||
Definition | ||
The header definition can be a `string`, a `Regexp`, a `function` or `null` | ||
@@ -359,3 +416,3 @@ - `string`: Match using string equality against the request header value | ||
## QueryParametersDefinition : <code>Object.<string, (string\|Regexp\|function()\|null)></code> | ||
## QueryParametersDefinition : <code>Object.<string, Definition></code> | ||
key/value object. Key is the query parameter name, value is the parameter definition | ||
@@ -371,3 +428,3 @@ The parameter definition can be a `string`, a `Regexp`, a `function` or `null` | ||
## BodyDefinition : <code>string</code> \| <code>Array</code> \| <code>Object.<string, (string\|Regexp\|Body\|function()\|null)></code> | ||
## BodyDefinition : <code>string</code> \| <code>Array</code> \| <code>Object.<string, (Definition\|Body)></code> | ||
Body can be a string, an array or a key/mixed object where values can be a `string`, a `Regexp`, a `function`, object, Array or `null` | ||
@@ -374,0 +431,0 @@ - `string`: Match using string equality against the request parameter value |
{ | ||
"name": "stubborn-ws", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "", | ||
@@ -10,2 +10,3 @@ "homepage": "https://github.com/ybonnefond/stubborn#stubborn", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test-ci": "mkdir -p coverage && yarn lint && jest --coverage --coverageReporters=lcov && cat ./coverage/lcov.info | coveralls", | ||
@@ -12,0 +13,0 @@ "lint": "eslint src", |
@@ -46,3 +46,3 @@ # Stubborn | ||
const sb = new Stubborn({ port: 8080 }); | ||
const sb = new Stubborn(); | ||
@@ -49,0 +49,0 @@ beforeAll(async() => await sb.start()); |
@@ -238,2 +238,10 @@ 'use strict'; | ||
}); | ||
it('should return SUCCESS when setting a specific header', async() => { | ||
sb | ||
.get('/') | ||
.setHeader('Authorization', 'Bearer 9'); | ||
await expect(request('/', { headers: { Authorization: 'Bearer 9' } })).toReplyWith(STATUS_CODES.SUCCESS); | ||
}); | ||
}); | ||
@@ -343,2 +351,10 @@ | ||
}); | ||
it('should return SUCCESS when setting a specific query parameter', async() => { | ||
sb | ||
.get('/') | ||
.setQueryParameter('page', '100'); | ||
await expect(request('/?page=100')).toReplyWith(STATUS_CODES.SUCCESS); | ||
}); | ||
}); | ||
@@ -491,2 +507,10 @@ | ||
it('should respond with provided header', async() => { | ||
sb | ||
.get('/') | ||
.setResponseHeader('custom', 'header'); | ||
await expect(request('/')).toReplyWith(STATUS_CODES.SUCCESS, '', expect.objectContaining({ custom: 'header' })); | ||
}); | ||
it('should respond with provided string body', async() => { | ||
@@ -493,0 +517,0 @@ sb |
@@ -82,2 +82,22 @@ 'use strict'; | ||
/** | ||
* Set a specific header definition. | ||
* | ||
* @example | ||
* ```js | ||
* | ||
* stubborn | ||
* .get('/match') | ||
* .setHeader('Authorization', 'BEARER'); | ||
* ``` | ||
* @param {String} header Header name | ||
* @param {Definition} definition Header definition | ||
* @returns {this} | ||
*/ | ||
setHeader(header, definition) { | ||
this.headers[header] = definition; | ||
return this; | ||
} | ||
/** | ||
* Set the headers definition. | ||
@@ -113,2 +133,21 @@ * | ||
/** | ||
* Set a specific query parameter | ||
* | ||
* @example | ||
* ```js | ||
* stubborn | ||
* .get('/match') | ||
* .setQueryParameter('page', '100'); | ||
* ``` | ||
* @param {String} queryParameter Query parameters name | ||
* @param {Definition} definition Query parameter definition | ||
* @returns {this} | ||
*/ | ||
setQueryParameter(queryParameter, definition) { | ||
this.query[queryParameter] = definition; | ||
return this; | ||
} | ||
/** | ||
* Set the body definition. Body can be a string or a complex object mixing | ||
@@ -183,3 +222,3 @@ * | ||
/** | ||
* Set the response header | ||
* Set the response headers | ||
* key/value object. If value is a function it will receive the request as parameter | ||
@@ -193,3 +232,3 @@ * ```js | ||
* ``` | ||
* @param {Object.<mixed>} body | ||
* @param {Object.<mixed>} headers | ||
* @returns {this} | ||
@@ -202,2 +241,19 @@ */ | ||
} | ||
/** | ||
* Set a response header | ||
* | ||
* ```js | ||
* ws.get('/resource') | ||
* .setResponseHeader('Content-type', 'application/json'); | ||
* ``` | ||
* @param {String} header | ||
* @param {String|function} value | ||
* @returns {this} | ||
*/ | ||
setResponseHeader(header, value) { | ||
this.response.headers[header] = value; | ||
return this; | ||
} | ||
} | ||
@@ -217,2 +273,11 @@ | ||
/** | ||
* Definition | ||
* The header definition can be a `string`, a `Regexp`, a `function` or `null` | ||
* - `string`: Match using string equality against the request header value | ||
* - `Regexp`: Match using Regexp.test against the request header value | ||
* - `function`: Request header value will be passed to the function. The function Should return a boolean | ||
* - `null`: act as a wildcard, header will not be processed | ||
* @typedef {string|Regexp|function|null} Definition | ||
/** | ||
* key/value object. Key is the header name, value is the header definition | ||
@@ -224,3 +289,3 @@ * The header definition can be a `string`, a `Regexp`, a `function` or `null` | ||
* - `null`: act as a wildcard, header will not be processed | ||
* @typedef {object.<string, string|Regexp|function|null>} HeadersDefinition | ||
* @typedef {object.<string, HeaderValue>} HeadersDefinition | ||
*/ | ||
@@ -236,3 +301,3 @@ | ||
* | ||
* @typedef {Object.<string, string|Regexp|function|null>} QueryParametersDefinition | ||
* @typedef {Object.<string, Definition>} QueryParametersDefinition | ||
*/ | ||
@@ -249,3 +314,3 @@ | ||
* | ||
* @typedef {string|Array|Object.<string, string|Regexp|Body|function|null>} BodyDefinition | ||
* @typedef {string|Array|Object.<string, Definition|Body>} BodyDefinition | ||
*/ |
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
76470
1573