New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.2.0 to 2.0.0

.prettierrc

101

package.json
{
"name": "stubborn-ws",
"version": "1.2.0",
"description": "",
"homepage": "https://github.com/ybonnefond/stubborn#stubborn",
"main": "src/index.js",
"keywords": "stubborn, test, test api, testing, testing web server, nock, dyson, jest, jasmine, mocha",
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test-ci": "mkdir -p coverage && yarn lint && jest --coverage --coverageReporters=lcov && cat ./coverage/lcov.info | coveralls",
"lint": "eslint src",
"doc": "jsdoc2md -f src/*.js > doc/API.md",
"release": "yarn doc && yarn publish"
},
"author": "",
"license": "ISC",
"devDependencies": {
"coveralls": "^3.0.2",
"eslint": "^5.3.0",
"got": "^9.0.0",
"jest": "^23.3.0",
"jest-diff": "^23.2.0",
"jsdoc-to-markdown": "^4.0.1"
},
"jest": {
"testEnvironment": "node",
"collectCoverage": true,
"coverageReporters": [
"html"
],
"coverageDirectory": "coverage",
"collectCoverageFrom": [
"src/**/*.js"
]
},
"dependencies": {
"accept": "^3.1.3",
"body-parser": "^1.18.3",
"content-type": "^1.0.4",
"lodash": "^4.17.10"
}
"name": "stubborn-ws",
"version": "2.0.0",
"description": "Web server to mock external HTTP APIs in tests",
"types": "dist/index.d.ts",
"homepage": "https://github.com/ybonnefond/stubborn#stubborn",
"main": "dist/index.js",
"engines": {
"node": ">=8"
},
"keywords": [
"stubborn",
"test",
"test api",
"testing",
"testing web server",
"nock",
"dyson",
"jest",
"jasmine",
"mocha"
],
"scripts": {
"build": "tsc",
"prepublish": "tsc",
"test": "jest --config jest.json",
"test:watch": "yarn test --watch",
"lint:prettier": "yarn prettier -l '{src,test}/**/*.{ts,js,md,json}'",
"lint:prettier:fix": "yarn prettier --write '{src,test}/**/*.{ts,js,md,json}'",
"test-ci": "mkdir -p coverage && yarn lint && yarn test --coverage --coverageReporters=lcov && cat ./coverage/lcov.info | coveralls",
"lint": "tslint --project tsconfig.json -c tslint.json 'src/**/*.ts' 'test/**/*.ts' -t stylish",
"doc": "compodoc -p tsconfig.json -d docs --disableInternal --hideGenerator",
"release": "yarn doc && yarn publish"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@compodoc/compodoc": "^1.1.9",
"@types/accept": "^3.1.1",
"@types/body-parser": "^1.17.0",
"@types/content-type": "^1.1.3",
"@types/got": "^9.6.0",
"@types/jest": "^24.0.15",
"@types/lodash": "^4.14.135",
"coveralls": "^3.0.4",
"got": "^9.6.0",
"jest": "^24.8.0",
"jest-diff": "^24.8.0",
"jsdoc-to-markdown": "^5.0.0",
"prettier": "^1.18.2",
"ts-jest": "^24.0.2",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.5.2"
},
"dependencies": {
"accept": "^3.1.3",
"body-parser": "^1.19.0",
"content-type": "^1.0.4",
"lodash": "^4.17.11"
}
}

@@ -1,4 +0,7 @@

# Stubborn
[![Build Status](https://travis-ci.org/ybonnefond/stubborn.svg?branch=master)](https://travis-ci.org/ybonnefond/stubborn) [![Coverage Status](https://coveralls.io/repos/github/ybonnefond/stubborn/badge.svg?branch=master)](https://coveralls.io/github/ybonnefond/stubborn?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/ybonnefond/stubborn.svg)](https://greenkeeper.io/)
# Stubborn
[![Build Status](https://travis-ci.org/ybonnefond/stubborn.svg?branch=master)](https://travis-ci.org/ybonnefond/stubborn) [![Coverage Status](https://coveralls.io/repos/github/ybonnefond/stubborn/badge.svg?branch=master)](https://coveralls.io/github/ybonnefond/stubborn?branch=master)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
![node](https://img.shields.io/node/v/stubborn-ws.svg)
**Stubborn** web server to mock external api responses. It is basically [nock](https://github.com/nock/nock) meets [Dyson](https://github.com/webpro/dyson). **Stubborn** will **strictly** match the requests based on the definition like [nock](https://github.com/nock/nock) but in a separate web server like [Dyson](https://github.com/webpro/dyson).

@@ -12,3 +15,3 @@

- [Contributing](#contributing)
* [Release](#release)
- [Release](#release)

@@ -22,2 +25,3 @@ <hr />

Npm:
```bash

@@ -28,2 +32,3 @@ npm install --save-dev stubborn-ws

Yarn:
```bash

@@ -35,3 +40,3 @@ yarn add -D stubborn-ws

Stubborn is a testing tool that let you **hot** load and unload routes into a webserver.
Stubborn is a testing tool that let you **hot** load and unload routes into a webserver.
Requests are **strictly** matched against routes definitions based on Method, Path, Query parameters, Headers and Body.

@@ -42,30 +47,29 @@ If the request does not exactly match one route definition (ex: extra parameter, missing parameter, value does not match, etc), Stubborn will respond with a 501.

Stubborn response headers and body can be hardcoded or defined using a template.
Stubborn response headers and body can be hardcoded or defined using a template.
```javascript
describe('Test', () => {
const got = require('got');
const { Stubborn } = require('stubborn-ws');
const got = require('got');
const { Stubborn } = require('stubborn-ws');
const sb = new Stubborn();
const sb = new Stubborn();
beforeAll(async() => await sb.start());
afterAll(async() => await sb.stop());
beforeAll(async () => await sb.start());
afterAll(async () => await sb.stop());
// Clean up all routes after a test if needed
afterEach(() => sb.clear());
// Clean up all routes after a test if needed
afterEach(() => sb.clear());
it('should respond to query', async () => {
const body = { some: 'body' };
sb.get('/').setResponseBody({ some: 'body' });
it('should respond to query', async () => {
const body = { some: 'body' };
sb.get('/').setResponseBody({ some: 'body' });
const res = await got(`${sb.getOrigin()}`, { json: true });
const res = await got(`${sb.getOrigin()}`, { json: true });
expect(res.body).toEqual(body);
});
expect(res.body).toEqual(body);
});
});
```
Stubborn **strictly** matches the request against the route definition.
Stubborn **strictly** matches the request against the route definition.

@@ -75,9 +79,9 @@ If a query parameter or a header is missing, stubborn will return a 501 (not implemented)

```javascript
it('should respond 501 if a parameter is missing', async () => {
sb.get('/').setQueryParameters({ page: '1' });
it('should respond 501 if a parameter is missing', async () => {
sb.get('/').setQueryParameters({ page: '1' });
const res = await got(`${sb.getOrigin()}`, { throwHttpErrors: false });
const res = await got(`${sb.getOrigin()}`, { throwHttpErrors: false });
expect(res.statusCode).toEqual(501);
});
expect(res.statusCode).toEqual(501);
});
```

@@ -88,9 +92,11 @@

```javascript
it('should respond 501 if a parameter is added', async () => {
sb.get('/').setQueryParameters({ page: '1' });
it('should respond 501 if a parameter is added', async () => {
sb.get('/').setQueryParameters({ page: '1' });
const res = await got(`${sb.getOrigin()}?page=1&limit=10`, { throwHttpErrors: false });
const res = await got(`${sb.getOrigin()}?page=1&limit=10`, {
throwHttpErrors: false,
});
expect(res.statusCode).toEqual(501);
});
expect(res.statusCode).toEqual(501);
});
```

@@ -101,9 +107,9 @@

```javascript
it('should respond 501 if a parameter does not match the definition', async () => {
sb.get('/').setQueryParameters({ page: '1' });
it('should respond 501 if a parameter does not match the definition', async () => {
sb.get('/').setQueryParameters({ page: '1' });
const res = await got(`${sb.getOrigin()}?page=2`, { throwHttpErrors: false });
const res = await got(`${sb.getOrigin()}?page=2`, { throwHttpErrors: false });
expect(res.statusCode).toEqual(501);
});
expect(res.statusCode).toEqual(501);
});
```

@@ -114,18 +120,14 @@

```javascript
it('should respond using wildcard', async () => {
sb.get('/')
.setQueryParameters({ page: null })
.setHeaders(null);
it('should respond using wildcard', async () => {
sb.get('/')
.setQueryParameters({ page: null })
.setHeaders(null);
const res = await got(`${sb.getOrigin()}?page=2`, {
headers: { 'x-api-key': 'api key', 'any-other-header': 'stuff' },
throwHttpErrors: false,
});
const res = await got(
`${sb.getOrigin()}?page=2`,
{
headers: { 'x-api-key': 'api key', 'any-other-header': 'stuff' },
throwHttpErrors: false
}
);
expect(res.statusCode).toEqual(200);
});
expect(res.statusCode).toEqual(200);
});
```

@@ -151,2 +153,2 @@

Then go to github to [draft a new release](https://github.com/ybonnefond/stubborn/releases/new)
Then go to github to [draft a new release](https://github.com/ybonnefond/stubborn/releases/new)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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