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

test: add case to test-http-methods.js #14773

Closed
wants to merge 3 commits into from
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
47 changes: 40 additions & 7 deletions test/parallel/test-http-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,46 @@
require('../common');
const assert = require('assert');
const http = require('http');
const util = require('util');

// This test ensures all http methods from HTTP parser are exposed
// to http library

var methods = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: use const

'DELETE',
'GET',
'HEAD',
'POST',
'PUT',
'CONNECT',
'OPTIONS',
'TRACE',
'COPY',
'LOCK',
'MKCOL',
'MOVE',
'PROPFIND',
'PROPPATCH',
'SEARCH',
'UNLOCK',
'BIND',
'REBIND',
'UNBIND',
'ACL',
'REPORT',
'MKACTIVITY',
'CHECKOUT',
'MERGE',
'M-SEARCH',
'NOTIFY',
'SUBSCRIBE',
'UNSUBSCRIBE',
'PATCH',
'PURGE',
'MKCALENDAR',
'LINK',
'UNLINK'
];
assert(Array.isArray(http.METHODS));
assert(http.METHODS.length > 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is now redundant, you may safely remove it.

assert(http.METHODS.includes('DELETE'));
assert(http.METHODS.includes('GET'));
assert(http.METHODS.includes('HEAD'));
assert(http.METHODS.includes('POST'));
assert(http.METHODS.includes('PUT'));
assert.deepStrictEqual(util._extend([], http.METHODS), http.METHODS.sort());
assert.equal(methods.length, http.METHODS.length);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is covered by the next assert statement, so I'd say this is redundant. By the way, please use strictEqual() instead of equal() in such cases :)

assert.deepStrictEqual(methods.sort(), http.METHODS.sort());
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously this test asserted that the http.METHODS array is alphabetically sorted. So as not to change the test expectations, you should either drop .sort() from http.METHODS, or drop both .sort()s and make the array in this test sorted beforehand. I'd prefer the latter way, but one might find the former one conveying the intention more clearly, so I'm fine with both.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aside from that, can you please swap the order of arguments here? According to the function's signature, first argument should be an actual value and second one an expected value.