Browse Source

Cleanup tests

pull/2/head
Luke Childs 8 years ago
parent
commit
ecee111bce
  1. 26
      test/create-test-server.js

26
test/create-test-server.js

@ -30,18 +30,21 @@ test('express endpoint', async t => {
res.send('bar'); res.send('bar');
}); });
const response = await got(server.url + '/foo'); const { body } = await got(server.url + '/foo');
t.is(response.body, 'bar'); t.is(body, 'bar');
}); });
test('server can be stopped and restarted', async t => { test('server can be stopped and restarted', async t => {
const server = await createTestServer(); const server = await createTestServer();
server.get('/foo', (req, res) => {
res.send('bar');
});
t.plan(3); t.plan(3);
await got(server.url + '/foo').catch(err => { const { body } = await got(server.url + '/foo');
t.is(err.statusCode, 404); t.is(body, 'bar');
});
await server.close(); await server.close();
@ -51,9 +54,8 @@ test('server can be stopped and restarted', async t => {
await server.listen(); await server.listen();
await got(server.url + '/foo').catch(err => { const { body: bodyRestarted } = await got(server.url + '/foo');
t.is(err.statusCode, 404); t.is(bodyRestarted, 'bar');
});
}); });
test('server listens for SSL traffic', async t => { test('server listens for SSL traffic', async t => {
@ -63,8 +65,8 @@ test('server listens for SSL traffic', async t => {
res.send('bar'); res.send('bar');
}); });
const response = await got(server.sslUrl + '/foo', { rejectUnauthorized: false }); const { body } = await got(server.sslUrl + '/foo', { rejectUnauthorized: false });
t.is(response.body, 'bar'); t.is(body, 'bar');
}); });
test('opts.certificate is passed through to createCert()', async t => { test('opts.certificate is passed through to createCert()', async t => {
@ -74,10 +76,10 @@ test('opts.certificate is passed through to createCert()', async t => {
res.send('bar'); res.send('bar');
}); });
const response = await got(server.sslUrl + '/foo', { const { body } = await got(server.sslUrl + '/foo', {
strictSSL: true, strictSSL: true,
ca: server.sslCert.caKeys.cert, ca: server.sslCert.caKeys.cert,
headers: { host: 'foo.bar' } headers: { host: 'foo.bar' }
}); });
t.is(response.body, 'bar'); t.is(body, 'bar');
}); });

Loading…
Cancel
Save