Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https: make opts optional & immutable when create #13599

Closed
Prev Previous commit
Next Next commit
use blocks to instead of server1, server2, ...
  • Loading branch information
XadillaX committed Jun 10, 2017
commit 5de8cf2eb33072fc24bea4a6417e40540e704667
36 changes: 20 additions & 16 deletions test/parallel/test-https-argument-of-creating.js
Original file line number Diff line number Diff line change
@@ -7,30 +7,34 @@ const https = require('https');
const tls = require('tls');

const dftProtocol = {};
tls.convertNPNProtocols([ 'http/1.1' ], dftProtocol);

// test for immutable `opts`
const opts = { foo: 'bar', NPNProtocols: [ 'http/1.1' ] };
const server1 = https.createServer(opts);
{
const opts = { foo: 'bar', NPNProtocols: [ 'http/1.1' ] };
const server = https.createServer(opts);

assert.deepStrictEqual(opts, { foo: 'bar', NPNProtocols: [ 'http/1.1' ] });
assert.strictEqual(server1.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
tls.convertNPNProtocols([ 'http/1.1' ], dftProtocol);
assert.deepStrictEqual(opts, { foo: 'bar', NPNProtocols: [ 'http/1.1' ] });
assert.strictEqual(server.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
}


// validate that `createServer` can work with the only argument requestListener
const mustNotCall = common.mustNotCall();
const server2 = https.createServer(mustNotCall);
{
const mustNotCall = common.mustNotCall();
const server = https.createServer(mustNotCall);

tls.convertNPNProtocols([ 'http/1.1', 'http/1.0' ], dftProtocol);
assert.ok(server2);
assert.strictEqual(server2.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
assert.strictEqual(server2.listeners('request').length, 1);
assert.strictEqual(server2.listeners('request')[0], mustNotCall);
tls.convertNPNProtocols([ 'http/1.1', 'http/1.0' ], dftProtocol);
assert.strictEqual(server.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
assert.strictEqual(server.listeners('request').length, 1);
assert.strictEqual(server.listeners('request')[0], mustNotCall);
}


// validate that `createServer` can work with no arguments
const server3 = https.createServer();
{
const server = https.createServer();

assert.ok(server3);
assert.strictEqual(server3.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
assert.strictEqual(server3.listeners('request').length, 0);
assert.strictEqual(server.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
assert.strictEqual(server.listeners('request').length, 0);
}