# sinon-server

> A mock server to answer calls to external systems controlled by a sinon stub

Latest version **0.2.0** (published 2017-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install sinon-server
pnpm add sinon-server
yarn add sinon-server
bun add sinon-server
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2017-10-06 |
| First published | 2017-01-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Johan Öbrink |
| Maintainers | johanobrink |
| Keywords | test, testing, sinon, mock, stub, server, external, dependencies, http, soap |

## Links

- npm: https://www.npmjs.com/package/sinon-server
- Repository: https://github.com/JohanObrink/sinon-server
- Homepage: https://github.com/JohanObrink/sinon-server#readme
- Issues: https://github.com/JohanObrink/sinon-server/issues
- npm.io page: https://npm.io/package/sinon-server

## Dependencies (3)

- [sinon](https://npm.io/package/sinon.md) ^1.17.6
- [lodash](https://npm.io/package/lodash.md) ^4.16.6
- [xml2js](https://npm.io/package/xml2js.md) ^0.4.17

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2017-10-06
- 0.1.1 — 2017-01-09
- 0.1.0 — 2017-01-09

## README

# sinon-server
A mock server to answer calls to external systems controlled by a sinon stub

## Install

```npm install sinon-server```

## Use

```javascript
const {request} = require('http')
const {match} = require('sinon')

const {HttpServer} = require('./lib')
const testServer = new HttpServer({port: 1337})
```

### Example 1
```javascript
testServer
  .withArgs('GET', '/', match({'accept': 'application/json'}))
  .resolves({
    status: 200,
    headers: {'Content-Type': 'application/json'},
    body: {
      success: 'great'
    }
  })

const options = {
  host: 'localhost',
  port: '1337',
  headers: {'Accept': 'application/json'}
}

testServer
  .start()
  .then(() => {
    const req1 = request(Object.assign({method: 'GET', path: '/'}, options), res => {
      console.log('status', res.statusCode)
      console.log('headers', res.headers)

      res.setEncoding('utf8')
      res.on('data', data => console.log(data))
    })
    req1.end()
  })
  .then(() => testServer.stop())
```

### Example 2
```javascript
testServer
  .withArgs('POST', '/users', match.object, JSON.stringify({foo: 'bar'}))
  .resolves({
    status: 201,
    headers: {'Content-Type': 'text/html'},
    body: `<!doctype html>
<html>
  <body>
    <h1>User created!</h1>
  </body>
</html>`
  })

const options = {
  host: 'localhost',
  port: '1337',
  headers: {'Accept': 'application/json'}
}

testServer
  .start()
  .then(() => {
    const req2 = request(Object.assign({method: 'POST', path: '/users'}, options), res => {
      console.log('status', res.statusCode)
      console.log('headers', res.headers)

      res.setEncoding('utf8')
      res.on('data', data => console.log(data))
    })
    req2.write(JSON.stringify({foo: 'bar'}))
    req2.end()
  })
.then(() => testServer.stop())
```

---
_Source: https://npm.io/package/sinon-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
