create-test-server
Advanced tools
Comparing version 1.1.0 to 1.1.1
{ | ||
"name": "create-test-server", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Creates a minimal express server for testing", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -23,2 +23,21 @@ # create-test-server | ||
```js | ||
const createTestServer = require('create-test-server'); | ||
createTestServer().then(server => { | ||
console.log(server.url); | ||
// http://localhost:5486 | ||
console.log(server.sslUrl); | ||
// https://localhost:5487 | ||
// This is just an express route | ||
// You could use any express middleware too | ||
server.get('/foo', (req, res) => { | ||
res.send('bar'); | ||
}); | ||
// server.url + '/foo' and server.sslUrl + '/foo' will respond with 'bar' | ||
}); | ||
``` | ||
`createTestServer()` has a Promise based API that pairs well with a modern asynchronous test runner such as [AVA](https://github.com/avajs/ava). | ||
@@ -35,13 +54,5 @@ | ||
const server = await createTestServer(); | ||
console.log(server.url); | ||
// http://localhost:5486 | ||
console.log(server.sslUrl); | ||
// https://localhost:5487 | ||
// This is just an express route | ||
// You could use any express middleware too | ||
server.get('/foo', (req, res) => res.send('bar')); | ||
const response = await got(server.url + '/foo'); | ||
const response = await got(`${server.url}/foo`); | ||
t.is(response.body, 'bar'); | ||
@@ -62,3 +73,3 @@ }); | ||
test(async t => { | ||
const response = await got(server.url + '/foo'); | ||
const response = await got(`${server.url}/foo`); | ||
t.is(response.body, 'bar'); | ||
@@ -68,3 +79,3 @@ }); | ||
test(async t => { | ||
const response = await got(server.url + '/foo'); | ||
const response = await got(`${server.url}/foo`); | ||
t.is(response.statusCode, 200); | ||
@@ -81,3 +92,3 @@ }); | ||
const response = await got(server.sslUrl + '/foo', { | ||
const response = await got(`${server.sslUrl}/foo`, { | ||
ca: server.caCert, | ||
@@ -97,3 +108,3 @@ headers: { host: 'foobar.com' } | ||
const response = await got(server.sslUrl + '/foo', { | ||
const response = await got(`${server.sslUrl}/foo`, { | ||
rejectUnauthorized: false | ||
@@ -100,0 +111,0 @@ }); |
@@ -59,2 +59,11 @@ import test from 'ava'; | ||
test('server uses a new port on each listen', async t => { | ||
const server = await createTestServer(); | ||
const origurl = server.url; | ||
await server.close(); | ||
await server.listen(); | ||
t.not(origurl, server.url); | ||
}); | ||
test('server listens for SSL traffic', async t => { | ||
@@ -61,0 +70,0 @@ const server = await createTestServer(); |
11836
100
200