Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -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);
}