http-test-server
v2.0.1
Published
Create a simple http server for tests
Downloads
248
Readme
http-test-server
Create a simple http server for tests
Installation
Download node at nodejs.org and install it, if you haven't already.
npm install http-test-server --save
Usage
/* eslint-disable import/no-extraneous-dependencies */
import test from 'tapava';
import got from 'got';
import httpTestServer from 'http-test-server';
test('simple GET', t =>
httpTestServer((req, res) => {
t.is(req.url, '/foo');
t.is(req.method, 'GET');
res.end('beep boop');
})
.then(({shutdown, baseUrl}) =>
got(`${baseUrl}/foo`)
.then(({body}) => {
t.is(body, 'beep boop');
return shutdown();
})
)
);
test('simple POST', t =>
httpTestServer((req, res) => {
t.is(req.url, '/foo');
t.is(req.method, 'POST');
t.is(req.body.toString(), 'heja');
res.statusCode = 201;
res.end('beep boop');
})
.then(({shutdown, baseUrl}) =>
got(`${baseUrl}/foo`, {
body: 'heja',
method: 'post'
})
.then(({body, statusCode}) => {
t.is(body, 'beep boop');
t.is(statusCode, 201);
return shutdown();
})
)
);
Tests
npm install
npm test
Dependencies
- http-shutdown: Gracefully shutdown a running HTTP server.
- stream-to-promise: Convert streams (readable or writable) to promises
Dev Dependencies
- babel-cli: Babel command line.
- babel-core: Babel compiler core.
- babel-preset-es2015-node4: Babel preset to make node@4 ES2015 compatible.
- babel-tape-runner: Babel + Tape for running your ES Next tests
- got: Simplified HTTP requests
- package-json-to-readme: Generate a README.md from package.json contents
- tapava: the syntax of ava, run through tape
- xo: JavaScript happiness style linter ❤️
License
MIT
Generated by package-json-to-readme