Skip to content

Commit 2048ec0

Browse files
jpage-godaddyindexzero
authored andcommitted
Return value compatibility (#22)
Do not return `null` values for `createServers` keys
1 parent 09566da commit 2048ec0

File tree

3 files changed

+32
-21
lines changed

3 files changed

+32
-21
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ node_modules
1616

1717
.idea
1818
.vscode
19+
.prettierrc
20+
.prettierignore

index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ module.exports = async function createServers(options, listening) {
5656
createHttps(options.https, options.log)
5757
]);
5858

59-
const servers = { http, https };
59+
const servers = {};
60+
if (http) servers.http = http;
61+
if (https) servers.https = https;
6062

6163
if (httpErr || httpsErr) {
6264
let errorSource = httpsErr || httpErr;

test/create-servers-test.js

+27-20
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ async function download(httpsURL) {
4444
})
4545
.once('aborted', reject)
4646
.once('close', reject)
47-
.once('error', reject)
47+
.once('error', reject);
4848
});
4949
req.once('error', reject);
5050
});
5151
}
5252

5353
test('only http', function (t) {
54-
t.plan(3);
54+
t.plan(5);
5555
createServers({
5656
log: console.log,
5757
http: 9876,
@@ -61,6 +61,8 @@ test('only http', function (t) {
6161
t.error(err);
6262
t.equals(typeof servers, 'object');
6363
t.equals(typeof servers.http, 'object');
64+
t.equals(servers.http instanceof Array, false);
65+
t.equals(servers.https, undefined);
6466
servers.http.close();
6567
});
6668
});
@@ -101,7 +103,7 @@ test('only http, timeout', function (t) {
101103
});
102104

103105
test('only https', function (t) {
104-
t.plan(3);
106+
t.plan(5);
105107
createServers({
106108
log: console.log,
107109
https: {
@@ -115,6 +117,8 @@ test('only https', function (t) {
115117
t.error(err);
116118
t.equals(typeof servers, 'object');
117119
t.equals(typeof servers.https, 'object');
120+
t.equals(servers.https instanceof Array, false);
121+
t.equals(servers.http, undefined);
118122
servers.https.close();
119123
});
120124
});
@@ -149,7 +153,7 @@ test('absolute cert path resolution', function (t) {
149153
port: 3456,
150154
root: '/',
151155
cert: path.resolve(__dirname, 'fixtures', 'example-org-cert.pem'),
152-
key: path.resolve(__dirname, 'fixtures', 'example-org-key.pem')
156+
key: path.resolve(__dirname, 'fixtures', 'example-org-key.pem')
153157
},
154158
handler: fend
155159
}, function (err, servers) {
@@ -182,7 +186,7 @@ test('http && https', function (t) {
182186
});
183187
});
184188

185-
test('provides useful debug information', async function(t) {
189+
test('provides useful debug information', async function (t) {
186190
t.plan(4);
187191

188192
const config = {
@@ -229,7 +233,7 @@ test('http && https with different handlers', function (t) {
229233
root: path.join(__dirname, 'fixtures'),
230234
key: 'example-org-key.pem',
231235
cert: 'example-org-cert.pem'
232-
},
236+
}
233237
}, function (err, servers) {
234238
t.error(err);
235239
t.equals(typeof servers, 'object');
@@ -282,7 +286,7 @@ test('supports cert contents instead of cert paths', function (t) {
282286
port: 3456,
283287
root: root,
284288
cert: fs.readFileSync(path.resolve(root, 'example-org-cert.pem')),
285-
key: fs.readFileSync(path.resolve(root, 'example-org-key.pem'))
289+
key: fs.readFileSync(path.resolve(root, 'example-org-key.pem'))
286290
},
287291
handler: fend
288292
}, function (err, servers) {
@@ -317,15 +321,17 @@ test('supports creating certificate chains', function (t) {
317321
t.plan(2);
318322
var root = path.join(__dirname, 'fixtures');
319323
var agent3Cert = fs.readFileSync(path.resolve(root, 'agent3-cert.pem'));
320-
var intermediate = fs.readFileSync(path.resolve(root, 'intermediate-cert.pem'));
324+
var intermediate = fs.readFileSync(
325+
path.resolve(root, 'intermediate-cert.pem')
326+
);
321327
var spy = sinon.spy(https, 'createServer');
322328
createServers({
323329
log: console.log,
324330
https: {
325331
port: 3456,
326332
root: root,
327333
cert: ['agent3-cert.pem', 'intermediate-cert.pem'],
328-
key: 'agent3-key.pem'
334+
key: 'agent3-key.pem'
329335
},
330336
handler: fend
331337
}, function (err, servers) {
@@ -355,7 +361,11 @@ test('supports requestCert https option', function (t) {
355361
handler: fend
356362
}, function (err, servers) {
357363
t.error(err);
358-
t.equals(spy.lastCall.args[0].requestCert, true, 'should preserve the requestCert option');
364+
t.equals(
365+
spy.lastCall.args[0].requestCert,
366+
true,
367+
'should preserve the requestCert option'
368+
);
359369
servers.https.close();
360370
spy.restore();
361371
});
@@ -364,11 +374,7 @@ test('supports requestCert https option', function (t) {
364374
test('supports SNI', async t => {
365375
t.plan(1);
366376

367-
const hostNames = [
368-
'example.com',
369-
'example.net',
370-
'foo.example.org',
371-
];
377+
const hostNames = ['example.com', 'example.net', 'foo.example.org'];
372378

373379
let httpsServer;
374380
try {
@@ -400,14 +406,15 @@ test('supports SNI', async t => {
400406

401407
hostNames.forEach(host => evilDNS.add(host, '0.0.0.0'));
402408

403-
const responses = await Promise.all(hostNames
404-
.map(hostname => download(`https://${hostname}:3456/`)));
409+
const responses = await Promise.all(
410+
hostNames.map(hostname => download(`https://${hostname}:3456/`))
411+
);
405412

406413
t.equals(
407414
responses.every(str => str === 'Hello'),
408415
true,
409-
'responses are as expected');
410-
416+
'responses are as expected'
417+
);
411418
} catch (err) {
412419
return void t.error(err);
413420
} finally {
@@ -416,7 +423,7 @@ test('supports SNI', async t => {
416423
}
417424
});
418425

419-
test('multiple https servers', async function(t) {
426+
test('multiple https servers', async function (t) {
420427
t.plan(2);
421428

422429
evilDNS.add('foo.example.org', '0.0.0.0');

0 commit comments

Comments
 (0)