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
add test case for no argument
  • Loading branch information
XadillaX committed Jun 10, 2017
commit c798af825c6f8d731b91926f1c65ae6842a2e16e
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,28 @@ 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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit: instead of using server1, server2, and server3 we can use block scope.

{
  // test for immutable `opts`
}

{
  // validate that `createServer` can work with the only argument requestListener
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a style we now use more often (helps frame every test case), but IMHO it's up to you...


assert.deepStrictEqual(opts, { foo: 'bar', NPNProtocols: [ 'http/1.1' ] });
assert.strictEqual(server1.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
Copy link
Copy Markdown
Contributor

@mscdex mscdex Jun 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should suffice to just compare the NPNProtocols references. That way we know for sure that our options weren't overridden:

assert.strictEqual(server1.NPNProtocols, dftProtocol.NPNProtocols);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mscdex I think we can't, because NPNProtocols hasn't been cached yet. 2 calls to tls.convertNPNProtocols won't return the same reference.

Copy link
Copy Markdown
Contributor

@mscdex mscdex Jun 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I see it now. Perhaps we should at least choose a different set of protocols then, so as to differentiate from the default NPN protocols (perhaps just use one protocol?).



// validate that `createServer` can work with the only argument requestListener
const mustNotCall = common.mustNotCall();
const server2 = https.createServer(mustNotCall);
Copy link
Copy Markdown
Contributor

@mscdex mscdex Jun 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment below doesn't match the behavior of this line. If we're testing no arguments, it should just be https.createServer().

Otherwise we could add a separate test below for no arguments.


// validate that `createServer` can work with no arguments
tls.convertNPNProtocols([ 'http/1.1', 'http/1.0' ], dftProtocol);
assert.ok(server2);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It doesn't harm but I think this is redundant. An error would be thrown below if server2 is falsy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@refack, Shall I?

Copy link
Copy Markdown
Contributor

@refack refack Jun 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a style we now use more often (helps frame every test case), but IMHO it's up to you... that was for the other comment
I'm 👍 for keeping it, but maybe put if just below the const server2 =

assert.strictEqual(server2.NPNProtocols.compare(dftProtocol.NPNProtocols), 0);
assert.strictEqual(server2.listeners('request').length, 1);
assert.strictEqual(server2.listeners('request')[0], mustNotCall);


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

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