-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: favor deepStrictEqual over deepEqual #12883
Conversation
@@ -79,8 +79,7 @@ const s = http.createServer(common.mustCall((req, res) => { | |||
'set-cookie': cookies, | |||
'x-test-array-header': arrayValues | |||
}); | |||
// eslint-disable-next-line no-restricted-properties | |||
assert.deepEqual(headersCopy['set-cookie'], cookies); | |||
assert.deepStrictEqual(headersCopy['set-cookie'], cookies); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to suggest
const headersCopy = res.getHeaders();
// eslint-disable-next-line no-restricted-properties
const expected = {
'x-test-header': 'testing',
'x-test-header2': 'testing',
'set-cookie': cookies,
'x-test-array-header': arrayValues
};
Object.setPrototypeOf(expected, null)
assert.deepStrictEqual(headersCopy, expected);
And a question, why is headersCopy.__proto__ === undifined
?
Also headersCopy.hasOwnPropert === undifined
so the API is wrong it says the return value is an Object
https://nodejs.org/api/http.html#http_response_getheaders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And a question, why is
headersCopy.__proto__ === undifined
?
Because, as you noted, headersCopy
has a null
prototype, and therefore the __proto__
getter inherited from Object.prototype is missing.
Also
headersCopy.hasOwnPropert === undifined
so the API is wrong it says the return value is anObject
https://nodejs.org/api/http.html#http_response_getheaders
It’s still an object, it just doesn’t inherit from Object.prototype; if you have suggestions on how to improve the docs for this, sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my books it's not an Object if headersCopy instanceof Object === false
🤷♂️
Ref: #12885
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (but if you want, feel free to go with @refack’s suggestion for changing the test code)
* also correct language for the same note for querystring.parse * add assertions for said note PR-URL: nodejs#12887 Fixes: nodejs#12885 Refs: nodejs#12883 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
test-http-mutable-headers uses assert.deepEqual() in three places but appears to only needs it in two of them. Replace one with assert.deepStrictEqual() and remove linting exception.
Went with @refack's suggestion. New CI: https://ci.nodejs.org/job/node-test-pull-request/7999/ |
test-http-mutable-headers uses assert.deepEqual() in three places but appears to only needs it in two of them. Replace one with assert.deepStrictEqual() and remove linting exception. PR-URL: nodejs#12883 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Landed in 631cb42. |
* also correct language for the same note for querystring.parse * add assertions for said note PR-URL: nodejs#12887 Fixes: nodejs#12885 Refs: nodejs#12883 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
test-http-mutable-headers uses assert.deepEqual() in three places but appears to only needs it in two of them. Replace one with assert.deepStrictEqual() and remove linting exception. PR-URL: nodejs#12883 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This does not land cleanly in LTS. Please feel free to manually backport. Please also feel free to replace the backport request label with do-not-land if it shouldn't land |
@MylesBorins If #10805 gets backported, I can backport this after that lands. |
test-http-mutable-headers uses assert.deepEqual() in three places but
appears to only needs it in two of them. Replace one with
assert.deepStrictEqual() and remove linting exception.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test http