Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stubborn-ws

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stubborn-ws - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

33

doc/API.md

@@ -64,2 +64,4 @@ ## Classes

* [.setResponseHeader(header, value)](#Route+setResponseHeader) ⇒ <code>this</code>
* [.countCalls()](#Route+countCalls) ⇒ <code>number</code>
* [.getCall(index)](#Route+getCall) ⇒ <code>number</code>

@@ -270,2 +272,33 @@ <a name="Route+getDefinition"></a>

<a name="Route+countCalls"></a>
### route.countCalls() ⇒ <code>number</code>
Return the number of times the route has been called
```js
const route = ws.get('/resource');
expect(route.countCalls()).toBe(0);
await got(`${ws.getOrigin()}/resource`);
expect(route.countCalls()).toBe(1);
```
**Kind**: instance method of [<code>Route</code>](#Route)
<a name="Route+getCall"></a>
### route.getCall(index) ⇒ <code>number</code>
Return the number of times the route has been called
```js
const route = ws.get('/resource');
expect(route.countCalls()).toBe(0);
await got(`${ws.getOrigin()}/resource`);
expect(route.getCall(0)).toBe(1);
```
**Kind**: instance method of [<code>Route</code>](#Route)
| Param | Type |
| --- | --- |
| index | <code>number</code> |
<a name="Stubborn"></a>

@@ -272,0 +305,0 @@

2

package.json
{
"name": "stubborn-ws",
"version": "1.1.1",
"version": "1.2.0",
"description": "",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/ybonnefond/stubborn#stubborn",

@@ -615,2 +615,46 @@ 'use strict';

describe('Retain Calls', () => {
it('should have no calls when initialize the route', () => {
const route = sb.get('/');
expect(route.countCalls()).toBe(0);
});
it('should retain every calls made to the route', async() => {
const route = sb.get('/');
const TOTAL_CALLS = 3;
for (let i = 1; i <= TOTAL_CALLS; i++) {
await request();
expect(route.countCalls()).toBe(i);
}
});
it('should retain a striped version of the request', async() => {
const route = sb.post('/', null)
.setHeaders(null)
.setQueryParameters(null);
await request('/?page=100', { method: 'POST', body: { some: 'body' } });
expect(route.countCalls()).toBe(1);
expect(route.getCall(0)).toEqual({
method: 'POST',
query: { page: '100' },
body: { some: 'body' },
path: '/',
hash: '',
headers: {
accept: 'application/json',
'accept-encoding': expect.any(String),
connection: expect.any(String),
'content-length': expect.any(String),
'content-type': expect.any(String),
host: expect.any(String),
'user-agent': expect.any(String)
}
});
});
});
function request(path = '/', options = {}) {

@@ -617,0 +661,0 @@ return got(`${sb.getOrigin()}${path}`, Object.assign({

@@ -15,2 +15,3 @@ 'use strict';

this.body = '';
this.calls = [];

@@ -253,2 +254,35 @@ this.setHeaders({

}
/**
* Return the number of times the route has been called
*
* ```js
* const route = ws.get('/resource');
* expect(route.countCalls()).toBe(0);
* await got(`${ws.getOrigin()}/resource`);
* expect(route.countCalls()).toBe(1);
* ```
*
* @returns {number}
*/
countCalls() {
return this.calls.length;
}
/**
* Return the number of times the route has been called
*
* ```js
* const route = ws.get('/resource');
* expect(route.countCalls()).toBe(0);
* await got(`${ws.getOrigin()}/resource`);
* expect(route.getCall(0)).toBe(1);
* ```
*
* @param {number} index
* @returns {number}
*/
getCall(index) {
return this.calls[index];
}
}

@@ -255,0 +289,0 @@

@@ -121,2 +121,4 @@ 'use strict';

function reply(route, res, req) {
route.calls.push(stripReq(req));
const headers = applyTemplate(route.response.headers, req);

@@ -143,2 +145,14 @@ const body = applyTemplate(route.response.body, req);

function stripReq(incMessage) {
const { headers, body, path, query, hash, method } = incMessage;
return {
headers,
body,
path,
query,
hash,
method
};
}
function findAcceptTypes(headers) {

@@ -145,0 +159,0 @@ const headerKey = Object.keys(headers).find((name) => new RegExp('^accept$', 'i').test(name));

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc